diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-02-13 11:43:26 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-02-13 11:43:26 +0000 |
commit | 7d4d9365c0d9025d5c08ec503be304b4d3f63997 (patch) | |
tree | 4373f47e3a71451f52cdf10757fefaaea0d34c30 /spec/features | |
parent | 6a1b3ef73f57d58d159e343f79e1f74418c2f763 (diff) | |
parent | 0b14b654b6e5d936f7241dcc0c249e0d4cc42728 (diff) | |
download | gitlab-ce-7d4d9365c0d9025d5c08ec503be304b4d3f63997.tar.gz |
Merge branch 'issue_25900_2' into 'master'
Gather issuable metadata to avoid n+ queries on index view
Closes #25900
See merge request !9006
Diffstat (limited to 'spec/features')
-rw-r--r-- | spec/features/issuables/issuable_list_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/features/issuables/issuable_list_spec.rb b/spec/features/issuables/issuable_list_spec.rb new file mode 100644 index 00000000000..e31bc40adc3 --- /dev/null +++ b/spec/features/issuables/issuable_list_spec.rb @@ -0,0 +1,57 @@ +require 'rails_helper' + +describe 'issuable list', feature: true do + let(:project) { create(:empty_project) } + let(:user) { create(:user) } + + issuable_types = [:issue, :merge_request] + + before do + project.add_user(user, :developer) + login_as(user) + issuable_types.each { |type| create_issuables(type) } + end + + issuable_types.each do |issuable_type| + it "avoids N+1 database queries for #{issuable_type.to_s.humanize.pluralize}" do + control_count = ActiveRecord::QueryRecorder.new { visit_issuable_list(issuable_type) }.count + + create_issuables(issuable_type) + + expect { visit_issuable_list(issuable_type) }.not_to exceed_query_limit(control_count) + end + + it "counts upvotes, downvotes and notes count for each #{issuable_type.to_s.humanize}" do + visit_issuable_list(issuable_type) + + expect(first('.fa-thumbs-up').find(:xpath, '..')).to have_content(1) + expect(first('.fa-thumbs-down').find(:xpath, '..')).to have_content(1) + expect(first('.fa-comments').find(:xpath, '..')).to have_content(2) + end + end + + def visit_issuable_list(issuable_type) + if issuable_type == :issue + visit namespace_project_issues_path(project.namespace, project) + else + visit namespace_project_merge_requests_path(project.namespace, project) + end + end + + def create_issuables(issuable_type) + 3.times do + if issuable_type == :issue + issuable = create(:issue, project: project, author: user) + else + issuable = create(:merge_request, title: FFaker::Lorem.sentence, source_project: project, source_branch: FFaker::Name.name) + end + + 2.times do + create(:note_on_issue, noteable: issuable, project: project, note: 'Test note') + end + + create(:award_emoji, :downvote, awardable: issuable) + create(:award_emoji, :upvote, awardable: issuable) + end + end +end |