summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/reference_parser/issue_parser_spec.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-04-02 16:14:20 +0100
committerSean McGivern <sean@gitlab.com>2018-04-05 13:59:05 +0100
commite7b1d201dd56611eff7e796e9a390a7b21df51d1 (patch)
tree77918cabd27f31980c5f2d49d4fcd562682688b3 /spec/lib/banzai/reference_parser/issue_parser_spec.rb
parent8dca091ff7f04bb92a7835ebeff783b7f0ef76cd (diff)
downloadgitlab-ce-e7b1d201dd56611eff7e796e9a390a7b21df51d1.tar.gz
Fix N+1 in MergeRequestParser
read_project can be prevented by a very expensive condition, which we want to avoid, while still not writing manual SQL queries. read_project_for_iids is used by read_issue_iid and read_merge_request_iid to satisfy both of those constraints, and allow the declarative policy runner to use its normal caching strategy.
Diffstat (limited to 'spec/lib/banzai/reference_parser/issue_parser_spec.rb')
-rw-r--r--spec/lib/banzai/reference_parser/issue_parser_spec.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb
index 0a63567ee40..cb7f8b20dda 100644
--- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb
@@ -117,4 +117,27 @@ describe Banzai::ReferenceParser::IssueParser do
expect(subject.records_for_nodes(nodes)).to eq({ link => issue })
end
end
+
+ context 'when checking multiple merge requests on another project' do
+ let(:other_project) { create(:project, :public) }
+ let(:other_issue) { create(:issue, project: other_project) }
+
+ let(:control_links) do
+ [issue_link(other_issue)]
+ end
+
+ let(:actual_links) do
+ control_links + [issue_link(create(:issue, project: other_project))]
+ end
+
+ def issue_link(issue)
+ Nokogiri::HTML.fragment(%Q{<a data-issue="#{issue.id}"></a>}).children[0]
+ end
+
+ before do
+ project.add_developer(user)
+ end
+
+ it_behaves_like 'no N+1 queries'
+ end
end