diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-08 09:08:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-08 09:08:49 +0300 |
commit | 208f195a9bc3614e3c720d6e485830d37c4f49df (patch) | |
tree | e3fe98a5debe6147a29a244d5e8f2e9096264c56 /spec/models | |
parent | bf293d47937b3332462689c3fecc868706553f3a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/issue_spec.rb | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 9bab6fcd942..4bbe0d52486 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -433,15 +433,37 @@ RSpec.describe Issue, feature_category: :team_planning do .to contain_exactly(issue, incident) end - it 'uses the work_item_types table for filtering' do - expect do - described_class.with_issue_type(:issue).to_a - end.to make_queries_matching( - %r{ - INNER\sJOIN\s"work_item_types"\sON\s"work_item_types"\."id"\s=\s"issues"\."work_item_type_id" - \sWHERE\s"work_item_types"\."base_type"\s=\s0 - }x - ) + context 'when multiple issue_types are provided' do + it 'joins the work_item_types table for filtering' do + expect do + described_class.with_issue_type([:issue, :incident]).to_a + end.to make_queries_matching( + %r{ + INNER\sJOIN\s"work_item_types"\sON\s"work_item_types"\."id"\s=\s"issues"\."work_item_type_id" + \sWHERE\s"work_item_types"\."base_type"\sIN\s\(0,\s1\) + }x + ) + end + end + + context 'when a single issue_type is provided' do + it 'uses an optimized query for a single work item type' do + expect do + described_class.with_issue_type([:incident]).to_a + end.to make_queries_matching( + %r{ + WHERE\s\("issues"\."work_item_type_id"\s= + \s\(SELECT\s"work_item_types"\."id"\sFROM\s"work_item_types"\sWHERE\s"work_item_types"\."base_type"\s=\s1 + \sLIMIT\s1\)\) + }x + ) + end + end + + context 'when no types are provided' do + it 'activerecord handles the false condition' do + expect(described_class.with_issue_type([]).to_sql).to include('WHERE 1=0') + end end context 'when the issue_type_uses_work_item_types_table feature flag is disabled' do |