diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 21:38:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 21:38:24 +0300 |
commit | 983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch) | |
tree | b153cd387c14ba23bd5a07514c7c01fddf6a78a0 /spec/features/issues/csv_spec.rb | |
parent | a2bddee2cdb38673df0e004d5b32d9f77797de64 (diff) |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/features/issues/csv_spec.rb')
-rw-r--r-- | spec/features/issues/csv_spec.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/spec/features/issues/csv_spec.rb b/spec/features/issues/csv_spec.rb new file mode 100644 index 00000000000..193c83d2a40 --- /dev/null +++ b/spec/features/issues/csv_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Issues csv' do + let(:user) { create(:user) } + let(:project) { create(:project, :public) } + let(:milestone) { create(:milestone, title: 'v1.0', project: project) } + let(:idea_label) { create(:label, project: project, title: 'Idea') } + let(:feature_label) { create(:label, project: project, title: 'Feature', priority: 10) } + let!(:issue) { create(:issue, project: project, author: user) } + + before do + sign_in(user) + end + + def request_csv(params = {}) + visit project_issues_path(project, params) + page.within('.nav-controls') do + click_on 'Export as CSV' + end + click_on 'Export issues' + end + + def attachment + ActionMailer::Base.deliveries.last.attachments.first + end + + def csv + CSV.parse(attachment.decode_body, headers: true) + end + + it 'triggers an email export' do + expect(ExportCsvWorker).to receive(:perform_async).with(user.id, project.id, hash_including("project_id" => project.id)) + + request_csv + end + + it "doesn't send request params to ExportCsvWorker" do + expect(ExportCsvWorker).to receive(:perform_async).with(anything, anything, hash_excluding("controller" => anything, "action" => anything)) + + request_csv + end + + it 'displays flash message' do + request_csv + + expect(page).to have_content 'CSV export has started' + expect(page).to have_content "emailed to #{user.notification_email}" + end + + it 'includes a csv attachment', :sidekiq_might_not_need_inline do + request_csv + + expect(attachment.content_type).to include('text/csv') + end + + it 'ignores pagination', :sidekiq_might_not_need_inline do + create_list(:issue, 30, project: project, author: user) + + request_csv + + expect(csv.count).to eq 31 + end + + it 'uses filters from issue index', :sidekiq_might_not_need_inline do + request_csv(state: :closed) + + expect(csv.count).to eq 0 + end + + it 'ignores sorting from issue index', :sidekiq_might_not_need_inline do + issue2 = create(:labeled_issue, project: project, author: user, labels: [feature_label]) + + request_csv(sort: :label_priority) + + expected = [issue.iid.to_s, issue2.iid.to_s] + expect(csv.map { |row| row['Issue ID'] }).to eq expected + end + + it 'uses array filters, such as label_name', :sidekiq_might_not_need_inline do + issue.update!(labels: [idea_label]) + + request_csv("label_name[]" => 'Bug') + + expect(csv.count).to eq 0 + end + + it 'avoids excessive database calls' do + control_count = ActiveRecord::QueryRecorder.new { request_csv }.count + create_list(:labeled_issue, + 10, + project: project, + assignees: [user], + author: user, + milestone: milestone, + labels: [feature_label, idea_label]) + expect { request_csv }.not_to exceed_query_limit(control_count + 5) + end +end |