diff options
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index aedfc7fca53..46bf80b1e8f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -6438,6 +6438,8 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr let!(:merge_request) do create( :merge_request, + author: author, + state_id: state_id, target_project: target_project, target_branch: 'target-branch', source_project: project, @@ -6446,6 +6448,9 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr ) end + let(:author) { project.creator } + let(:state_id) { MergeRequest.available_states[:opened] } + before do target_project.add_developer(user) end @@ -6455,10 +6460,12 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr expect(project.merge_requests_allowing_push_to_user(user)).to include(merge_request) end - it 'does not include closed merge requests' do - merge_request.close + context 'when the merge requests are closed' do + let(:state_id) { MergeRequest.available_states[:closed] } - expect(project.merge_requests_allowing_push_to_user(user)).to be_empty + it 'does not include closed merge requests' do + expect(project.merge_requests_allowing_push_to_user(user)).to be_empty + end end it 'does not include merge requests for guest users' do @@ -6480,16 +6487,38 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr end describe '#any_branch_allows_collaboration?' do - it 'allows access when there are merge requests open allowing collaboration', :sidekiq_might_not_need_inline do - expect(project.any_branch_allows_collaboration?(user)) - .to be_truthy - end + context 'when there is an open merge request allowing collaboration' do + it 'allows access', :sidekiq_might_not_need_inline do + expect(project.any_branch_allows_collaboration?(user)) + .to be_truthy + end + + context 'when the merge request author is not allowed to push_code' do + let(:author) { create(:user) } - it 'does not allow access when there are no merge requests open allowing collaboration' do - merge_request.close! + it 'returns false' do + expect(project.any_branch_allows_collaboration?(user)) + .to be_falsey + end + end - expect(project.any_branch_allows_collaboration?(user)) - .to be_falsey + context 'when the merge request is closed' do + let(:state_id) { MergeRequest.available_states[:closed] } + + it 'returns false' do + expect(project.any_branch_allows_collaboration?(user)) + .to be_falsey + end + end + + context 'when the merge request is merged' do + let(:state_id) { MergeRequest.available_states[:merged] } + + it 'returns false' do + expect(project.any_branch_allows_collaboration?(user)) + .to be_falsey + end + end end end @@ -6537,6 +6566,15 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr .not_to exceed_query_limit(control).with_threshold(2) end end + + context 'when the merge request author is not allowed to push_code' do + let(:author) { create(:user) } + + it 'returns false' do + expect(project.branch_allows_collaboration?(user, 'awesome-feature-1')) + .to be_falsey + end + end end end |