diff options
author | Nick Thomas <nick@gitlab.com> | 2019-01-16 17:11:55 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-01-16 17:11:55 +0000 |
commit | dedaec13a57abdbeaded37c1ae9526a4f3d82e8b (patch) | |
tree | 4d66f74afef4c3b4e7501bb4072e94b7444513c0 /spec/models | |
parent | c8e3261729189cc26310a32926e74f97c1401b42 (diff) | |
parent | 2d9a6f2bd3b4ac55d5e59c8e9eb2013fa46798d9 (diff) | |
download | gitlab-ce-dedaec13a57abdbeaded37c1ae9526a4f3d82e8b.tar.gz |
Merge branch 'refactor-checking-personal-project-limits' into 'master'
Refactor checking personal project limits
See merge request gitlab-org/gitlab-ce!24396
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/project_spec.rb | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 08eed9c06de..7a8dc59039e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -209,9 +209,14 @@ describe Project do it 'does not allow new projects beyond user limits' do project2 = build(:project) - allow(project2).to receive(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object) + + allow(project2) + .to receive(:creator) + .and_return( + double(can_create_project?: false, projects_limit: 0).as_null_object + ) + expect(project2).not_to be_valid - expect(project2.errors[:limit_reached].first).to match(/Personal project creation is not allowed/) end describe 'wiki path conflict' do @@ -4431,6 +4436,75 @@ describe Project do end end + describe '#check_personal_projects_limit' do + context 'when creating a project for a group' do + it 'does nothing' do + creator = build(:user) + project = build(:project, namespace: build(:group), creator: creator) + + allow(creator) + .to receive(:can_create_project?) + .and_return(false) + + project.check_personal_projects_limit + + expect(project.errors).to be_empty + end + end + + context 'when the user is not allowed to create a personal project' do + let(:user) { build(:user) } + let(:project) { build(:project, creator: user) } + + before do + allow(user) + .to receive(:can_create_project?) + .and_return(false) + end + + context 'when the project limit is zero' do + it 'adds a validation error' do + allow(user) + .to receive(:projects_limit) + .and_return(0) + + project.check_personal_projects_limit + + expect(project.errors[:limit_reached].first) + .to match(/Personal project creation is not allowed/) + end + end + + context 'when the project limit is greater than zero' do + it 'adds a validation error' do + allow(user) + .to receive(:projects_limit) + .and_return(5) + + project.check_personal_projects_limit + + expect(project.errors[:limit_reached].first) + .to match(/Your project limit is 5 projects/) + end + end + end + + context 'when the user is allowed to create personal projects' do + it 'does nothing' do + user = build(:user) + project = build(:project, creator: user) + + allow(user) + .to receive(:can_create_project?) + .and_return(true) + + project.check_personal_projects_limit + + expect(project.errors).to be_empty + end + end + end + def rugged_config rugged_repo(project.repository).config end |