diff options
Diffstat (limited to 'spec/finders/merge_requests_finder_spec.rb')
-rw-r--r-- | spec/finders/merge_requests_finder_spec.rb | 102 |
1 files changed, 75 insertions, 27 deletions
diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index e3643698012..5b86c891e47 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -85,6 +85,31 @@ RSpec.describe MergeRequestsFinder do expect(merge_requests).to contain_exactly(merge_request5) end + context 'filters by merged_at date' do + before do + merge_request1.metrics.update!(merged_at: 5.days.ago) + merge_request2.metrics.update!(merged_at: 10.days.ago) + end + + describe 'merged_after' do + subject { described_class.new(user, merged_after: 6.days.ago).execute } + + it { is_expected.to eq([merge_request1]) } + end + + describe 'merged_before' do + subject { described_class.new(user, merged_before: 6.days.ago).execute } + + it { is_expected.to eq([merge_request2]) } + end + + describe 'when both merged_after and merged_before is given' do + subject { described_class.new(user, merged_after: 15.days.ago, merged_before: 6.days.ago).execute } + + it { is_expected.to eq([merge_request2]) } + end + end + context 'filtering by group' do it 'includes all merge requests when user has access excluding merge requests from projects the user does not have access to' do private_project = allow_gitaly_n_plus_1 { create(:project, :private, group: group) } @@ -192,43 +217,59 @@ RSpec.describe MergeRequestsFinder do expect(merge_requests).to contain_exactly(merge_request3) end - describe 'WIP state' do + describe 'draft state' do let!(:wip_merge_request1) { create(:merge_request, :simple, author: user, source_project: project5, target_project: project5, title: 'WIP: thing') } let!(:wip_merge_request2) { create(:merge_request, :simple, author: user, source_project: project6, target_project: project6, title: 'wip thing') } let!(:wip_merge_request3) { create(:merge_request, :simple, author: user, source_project: project1, target_project: project1, title: '[wip] thing') } let!(:wip_merge_request4) { create(:merge_request, :simple, author: user, source_project: project1, target_project: project2, title: 'wip: thing') } + let!(:draft_merge_request1) { create(:merge_request, :simple, author: user, source_branch: 'draft1', source_project: project5, target_project: project5, title: 'Draft: thing') } + let!(:draft_merge_request2) { create(:merge_request, :simple, author: user, source_branch: 'draft2', source_project: project6, target_project: project6, title: '[draft] thing') } + let!(:draft_merge_request3) { create(:merge_request, :simple, author: user, source_branch: 'draft3', source_project: project1, target_project: project1, title: '(draft) thing') } + let!(:draft_merge_request4) { create(:merge_request, :simple, author: user, source_branch: 'draft4', source_project: project1, target_project: project2, title: 'Draft - thing') } - it 'filters by wip' do - params = { wip: 'yes' } + [:wip, :draft].each do |draft_param_key| + it "filters by #{draft_param_key}" do + params = { draft_param_key => 'yes' } - merge_requests = described_class.new(user, params).execute + merge_requests = described_class.new(user, params).execute - expect(merge_requests).to contain_exactly(merge_request4, merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, wip_merge_request4) - end + expect(merge_requests).to contain_exactly( + merge_request4, merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, wip_merge_request4, + draft_merge_request1, draft_merge_request2, draft_merge_request3, draft_merge_request4 + ) + end - it 'filters by not wip' do - params = { wip: 'no' } + context 'when merge_request_draft_filter is disabled' do + it 'does not include draft merge requests' do + stub_feature_flags(merge_request_draft_filter: false) - merge_requests = described_class.new(user, params).execute + merge_requests = described_class.new(user, { draft_param_key => 'yes' }).execute - expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request3) - end + expect(merge_requests).to contain_exactly( + merge_request4, merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, wip_merge_request4 + ) + end + end - it 'returns all items if no valid wip param exists' do - params = { wip: '' } + it "filters by not #{draft_param_key}" do + params = { draft_param_key => 'no' } - merge_requests = described_class.new(user, params).execute + merge_requests = described_class.new(user, params).execute - expect(merge_requests).to contain_exactly( - merge_request1, merge_request2, merge_request3, merge_request4, - merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, - wip_merge_request4) - end + expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request3) + end - it 'adds wip to scalar params' do - scalar_params = described_class.scalar_params + it "returns all items if no valid #{draft_param_key} param exists" do + params = { draft_param_key => '' } + + merge_requests = described_class.new(user, params).execute - expect(scalar_params).to include(:wip, :assignee_id) + expect(merge_requests).to contain_exactly( + merge_request1, merge_request2, merge_request3, merge_request4, + merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, wip_merge_request4, + draft_merge_request1, draft_merge_request2, draft_merge_request3, draft_merge_request4 + ) + end end context 'filter by deployment' do @@ -265,6 +306,14 @@ RSpec.describe MergeRequestsFinder do end end + describe '.scalar_params' do + it 'contains scalar params related to merge requests' do + scalar_params = described_class.scalar_params + + expect(scalar_params).to include(:wip, :draft, :assignee_id) + end + end + context 'assignee filtering' do let(:issuables) { described_class.new(user, params).execute } @@ -311,9 +360,8 @@ RSpec.describe MergeRequestsFinder do let(:group_milestone) { create(:milestone, group: group) } before do - project2.update(namespace: group) - merge_request2.update(milestone: group_milestone) - merge_request3.update(milestone: group_milestone) + merge_request1.update!(milestone: group_milestone) + merge_request2.update!(milestone: group_milestone) end it 'returns merge requests assigned to that group milestone' do @@ -321,7 +369,7 @@ RSpec.describe MergeRequestsFinder do merge_requests = described_class.new(user, params).execute - expect(merge_requests).to contain_exactly(merge_request2, merge_request3) + expect(merge_requests).to contain_exactly(merge_request1, merge_request2) end context 'using NOT' do @@ -330,7 +378,7 @@ RSpec.describe MergeRequestsFinder do it 'returns MRs not assigned to that group milestone' do merge_requests = described_class.new(user, params).execute - expect(merge_requests).to contain_exactly(merge_request1, merge_request4, merge_request5) + expect(merge_requests).to contain_exactly(merge_request3, merge_request4, merge_request5) end end end |