2017-01-23 15:40:25 -05:00
|
|
|
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
|
|
|
|
|
2017-02-17 20:58:24 -05:00
|
|
|
it "counts merge requests closing issues icons for each issue" do
|
|
|
|
visit_issuable_list(:issue)
|
2017-02-17 19:47:56 -05:00
|
|
|
|
2017-02-20 20:07:50 -05:00
|
|
|
expect(page).to have_selector('.icon-merge-request-unmerged', count: 1)
|
2017-02-17 20:58:24 -05:00
|
|
|
expect(first('.icon-merge-request-unmerged').find(:xpath, '..')).to have_content(1)
|
|
|
|
end
|
2017-02-17 19:47:56 -05:00
|
|
|
|
2017-01-23 15:40:25 -05:00
|
|
|
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)
|
2017-03-23 09:08:39 -04:00
|
|
|
3.times do |n|
|
2017-02-22 10:10:32 -05:00
|
|
|
issuable =
|
|
|
|
if issuable_type == :issue
|
|
|
|
create(:issue, project: project, author: user)
|
|
|
|
else
|
2017-03-23 12:37:14 -04:00
|
|
|
create(:merge_request, source_project: project, source_branch: generate(:branch))
|
2017-02-22 10:10:32 -05:00
|
|
|
end
|
2017-01-23 15:40:25 -05:00
|
|
|
|
|
|
|
2.times do
|
2017-03-23 09:08:39 -04:00
|
|
|
create(:note_on_issue, noteable: issuable, project: project)
|
2017-01-23 15:40:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
create(:award_emoji, :downvote, awardable: issuable)
|
|
|
|
create(:award_emoji, :upvote, awardable: issuable)
|
2017-02-21 17:08:20 -05:00
|
|
|
end
|
2017-02-20 20:07:50 -05:00
|
|
|
|
2017-02-21 17:00:03 -05:00
|
|
|
if issuable_type == :issue
|
|
|
|
issue = Issue.reorder(:iid).first
|
|
|
|
merge_request = create(:merge_request,
|
|
|
|
source_project: project,
|
2017-03-23 12:37:14 -04:00
|
|
|
source_branch: generate(:branch))
|
2017-02-20 20:07:50 -05:00
|
|
|
|
2017-04-12 07:38:00 -04:00
|
|
|
create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request)
|
2017-01-23 15:40:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|