diff options
Diffstat (limited to 'spec/finders/issues_finder_spec.rb')
-rw-r--r-- | spec/finders/issues_finder_spec.rb | 219 |
1 files changed, 129 insertions, 90 deletions
diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index fb7d4e808fe..dbf5abe64a5 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe IssuesFinder do + using RSpec::Parameterized::TableSyntax include_context 'IssuesFinder context' describe '#execute' do @@ -330,100 +331,139 @@ RSpec.describe IssuesFinder do end end - context 'filtering by label' do - let(:params) { { label_name: label.title } } + shared_examples ':label_name parameter' do + context 'filtering by label' do + let(:params) { { label_name: label.title } } - it 'returns issues with that label' do - expect(issues).to contain_exactly(issue2) - end + it 'returns issues with that label' do + expect(issues).to contain_exactly(issue2) + end - context 'using NOT' do - let(:params) { { not: { label_name: label.title } } } + context 'using NOT' do + let(:params) { { not: { label_name: label.title } } } - it 'returns issues that do not have that label' do - expect(issues).to contain_exactly(issue1, issue3, issue4) - end + it 'returns issues that do not have that label' do + expect(issues).to contain_exactly(issue1, issue3, issue4) + end - # IssuableFinder first filters using the outer params (the ones not inside the `not` key.) - # Afterwards, it applies the `not` params to that resultset. This means that things inside the `not` param - # do not take precedence over the outer params with the same name. - context 'shadowing the same outside param' do - let(:params) { { label_name: label2.title, not: { label_name: label.title } } } + # IssuableFinder first filters using the outer params (the ones not inside the `not` key.) + # Afterwards, it applies the `not` params to that resultset. This means that things inside the `not` param + # do not take precedence over the outer params with the same name. + context 'shadowing the same outside param' do + let(:params) { { label_name: label2.title, not: { label_name: label.title } } } - it 'does not take precedence over labels outside NOT' do - expect(issues).to contain_exactly(issue3) + it 'does not take precedence over labels outside NOT' do + expect(issues).to contain_exactly(issue3) + end end - end - context 'further filtering outside params' do - let(:params) { { label_name: label2.title, not: { assignee_username: user2.username } } } + context 'further filtering outside params' do + let(:params) { { label_name: label2.title, not: { assignee_username: user2.username } } } - it 'further filters on the returned resultset' do - expect(issues).to be_empty + it 'further filters on the returned resultset' do + expect(issues).to be_empty + end end end end - end - context 'filtering by multiple labels' do - let(:params) { { label_name: [label.title, label2.title].join(',') } } - let(:label2) { create(:label, project: project2) } + context 'filtering by multiple labels' do + let(:params) { { label_name: [label.title, label2.title].join(',') } } + let(:label2) { create(:label, project: project2) } - before do - create(:label_link, label: label2, target: issue2) - end + before do + create(:label_link, label: label2, target: issue2) + end - it 'returns the unique issues with all those labels' do - expect(issues).to contain_exactly(issue2) - end + it 'returns the unique issues with all those labels' do + expect(issues).to contain_exactly(issue2) + end - context 'using NOT' do - let(:params) { { not: { label_name: [label.title, label2.title].join(',') } } } + context 'using NOT' do + let(:params) { { not: { label_name: [label.title, label2.title].join(',') } } } - it 'returns issues that do not have any of the labels provided' do - expect(issues).to contain_exactly(issue1, issue4) + it 'returns issues that do not have any of the labels provided' do + expect(issues).to contain_exactly(issue1, issue4) + end end end - end - context 'filtering by a label that includes any or none in the title' do - let(:params) { { label_name: [label.title, label2.title].join(',') } } - let(:label) { create(:label, title: 'any foo', project: project2) } - let(:label2) { create(:label, title: 'bar none', project: project2) } + context 'filtering by a label that includes any or none in the title' do + let(:params) { { label_name: [label.title, label2.title].join(',') } } + let(:label) { create(:label, title: 'any foo', project: project2) } + let(:label2) { create(:label, title: 'bar none', project: project2) } - before do - create(:label_link, label: label2, target: issue2) - end + before do + create(:label_link, label: label2, target: issue2) + end + + it 'returns the unique issues with all those labels' do + expect(issues).to contain_exactly(issue2) + end - it 'returns the unique issues with all those labels' do - expect(issues).to contain_exactly(issue2) + context 'using NOT' do + let(:params) { { not: { label_name: [label.title, label2.title].join(',') } } } + + it 'returns issues that do not have ANY ONE of the labels provided' do + expect(issues).to contain_exactly(issue1, issue4) + end + end end - context 'using NOT' do - let(:params) { { not: { label_name: [label.title, label2.title].join(',') } } } + context 'filtering by no label' do + let(:params) { { label_name: described_class::Params::FILTER_NONE } } - it 'returns issues that do not have ANY ONE of the labels provided' do + it 'returns issues with no labels' do expect(issues).to contain_exactly(issue1, issue4) end end - end - context 'filtering by no label' do - let(:params) { { label_name: described_class::Params::FILTER_NONE } } + context 'filtering by any label' do + let(:params) { { label_name: described_class::Params::FILTER_ANY } } + + it 'returns issues that have one or more label' do + create_list(:label_link, 2, label: create(:label, project: project2), target: issue3) - it 'returns issues with no labels' do - expect(issues).to contain_exactly(issue1, issue4) + expect(issues).to contain_exactly(issue2, issue3) + end + end + + context 'when the same label exists on project and group levels' do + let(:issue1) { create(:issue, project: project1) } + let(:issue2) { create(:issue, project: project1) } + + # Skipping validation to reproduce a "real-word" scenario. + # We still have legacy labels on PRD that have the same title on the group and project levels, example: `bug` + let(:project_label) { build(:label, title: 'somelabel', project: project1).tap { |r| r.save!(validate: false) } } + let(:group_label) { create(:group_label, title: 'somelabel', group: project1.group) } + + let(:params) { { label_name: 'somelabel' } } + + before do + create(:label_link, label: group_label, target: issue1) + create(:label_link, label: project_label, target: issue2) + end + + it 'finds both issue records' do + expect(issues).to contain_exactly(issue1, issue2) + end end end - context 'filtering by any label' do - let(:params) { { label_name: described_class::Params::FILTER_ANY } } + context 'when `optimized_issuable_label_filter` feature flag is off' do + before do + stub_feature_flags(optimized_issuable_label_filter: false) + end - it 'returns issues that have one or more label' do - create_list(:label_link, 2, label: create(:label, project: project2), target: issue3) + it_behaves_like ':label_name parameter' + end - expect(issues).to contain_exactly(issue2, issue3) + context 'when `optimized_issuable_label_filter` feature flag is on' do + before do + stub_feature_flags(optimized_issuable_label_filter: true) end + + it_behaves_like ':label_name parameter' end context 'filtering by issue term' do @@ -949,10 +989,6 @@ RSpec.describe IssuesFinder do describe '#use_cte_for_search?' do let(:finder) { described_class.new(nil, params) } - before do - stub_feature_flags(attempt_group_search_optimizations: true) - end - context 'when there is no search param' do let(:params) { { attempt_group_search_optimizations: true } } @@ -969,47 +1005,50 @@ RSpec.describe IssuesFinder do end end - context 'when the attempt_group_search_optimizations flag is disabled' do - let(:params) { { search: 'foo', attempt_group_search_optimizations: true } } + context 'when all conditions are met' do + context "uses group search optimization" do + let(:params) { { search: 'foo', attempt_group_search_optimizations: true } } - before do - stub_feature_flags(attempt_group_search_optimizations: false) + it 'returns true' do + expect(finder.use_cte_for_search?).to be_truthy + end end - it 'returns false' do - expect(finder.use_cte_for_search?).to be_falsey + context "uses project search optimization" do + let(:params) { { search: 'foo', attempt_project_search_optimizations: true } } + + it 'returns true' do + expect(finder.use_cte_for_search?).to be_truthy + end end end + end - context 'when attempt_group_search_optimizations is unset and attempt_project_search_optimizations is set' do - let(:params) { { search: 'foo', attempt_project_search_optimizations: true } } + describe '#parent_param=' do + let(:finder) { described_class.new(nil) } - context 'and the corresponding feature flag is disabled' do - before do - stub_feature_flags(attempt_project_search_optimizations: false) - end + subject { finder.parent_param = obj } - it 'returns false' do - expect(finder.use_cte_for_search?).to be_falsey - end - end + where(:klass, :param) do + :Project | :project_id + :Group | :group_id + end - context 'and the corresponding feature flag is enabled' do - before do - stub_feature_flags(attempt_project_search_optimizations: true) - end + with_them do + let(:obj) { Object.const_get(klass, false).new } - it 'returns true' do - expect(finder.use_cte_for_search?).to be_truthy - end + it 'sets the params' do + subject + + expect(finder.params[param]).to eq(obj) end end - context 'when all conditions are met' do - let(:params) { { search: 'foo', attempt_group_search_optimizations: true } } + context 'unexpected parent' do + let(:obj) { MergeRequest.new } - it 'returns true' do - expect(finder.use_cte_for_search?).to be_truthy + it 'raises an error' do + expect { subject }.to raise_error('Unexpected parent: MergeRequest') end end end |