diff --git a/app/models/project.rb b/app/models/project.rb index acc1b8d232870682b4dc24f787a5cd782f733d1d..ce429bc3d75dc042e91371a40169cd5663ae4a10 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -155,7 +155,7 @@ class Project < ActiveRecord::Base def check_limit unless creator.can_create_project? - errors[:base] << ("Your own projects limit is #{creator.projects_limit}! Please contact administrator to increase it") + errors[:limit_reached] << ("Your own projects limit is #{creator.projects_limit}! Please contact administrator to increase it") end rescue errors[:base] << ("Can't check your ability to create project") diff --git a/lib/api/projects.rb b/lib/api/projects.rb index ecd3401fd94707ce73d747216035b0ade6f6f3a1..87653f04450c4e1930eed86c03eef22dce9a4ec9 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -58,6 +58,9 @@ module Gitlab if @project.saved? present @project, with: Entities::Project else + if @project.errors[:limit_reached].present? + error!(@project.errors[:limit_reached], 403) + end not_found! end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index de1b1b09e5f63a41247f5a8f00a25eed9065af0a..b635307884b0dc5afb11ffe8d46d12365b752c01 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -41,6 +41,11 @@ describe Gitlab::API do expect { post api("/projects", user) }.to_not change {Project.count} end + it "should return a 400 error if name not given" do + post api("/projects", user) + response.status.should == 400 + end + it "should respond with 201 on success" do post api("/projects", user), name: 'foo' response.status.should == 201 @@ -51,6 +56,14 @@ describe Gitlab::API do response.status.should == 400 end + it "should return a 403 error if project limit reached" do + (1..user.projects_limit).each do |p| + post api("/projects", user), name: "foo#{p}" + end + post api("/projects", user), name: 'bar' + response.status.should == 403 + end + it "should assign attributes to project" do project = attributes_for(:project, { description: Faker::Lorem.sentence,