diff --git a/app/models/project.rb b/app/models/project.rb index 9d61ffc1ac5a1f289afdb49b6f14a894ac27c212..b7d688bf8f569d664eb724824c55d57b499524c1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -146,7 +146,7 @@ class Project < ActiveRecord::Base end def saved? - id && valid? + id && persisted? end def import? diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 4ac1e7cc31cb69e48597a0c2729b184da5de4fc7..586f108ca9e78ce77af56a55ed78945ff10ec44f 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -33,6 +33,20 @@ describe Gitlab::API do end describe "POST /projects" do + context "maximum number of projects reached" do + before do + (1..user2.projects_limit).each do |project| + post api("/projects", user2), name: "foo#{project}" + end + end + + it "should not create new project" do + expect { + post api("/projects", user2), name: 'foo' + }.to change {Project.count}.by(0) + end + end + it "should create new project without path" do expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1) end @@ -41,6 +55,12 @@ describe Gitlab::API do expect { post api("/projects", user) }.to_not change {Project.count} end + it "should create last project before reaching project limit" do + (1..user2.projects_limit-1).each { |p| post api("/projects", user2), name: "foo#{p}" } + post api("/projects", user2), name: "foo" + response.status.should == 201 + end + it "should respond with 201 on success" do post api("/projects", user), name: 'foo' response.status.should == 201