diff --git a/app/models/project.rb b/app/models/project.rb index acc1b8d2..ce429bc3 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 ecd3401f..87653f04 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 de1b1b09..b6353078 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,