diff options
Diffstat (limited to 'spec/services/issues/export_csv_service_spec.rb')
-rw-r--r-- | spec/services/issues/export_csv_service_spec.rb | 214 |
1 files changed, 114 insertions, 100 deletions
diff --git a/spec/services/issues/export_csv_service_spec.rb b/spec/services/issues/export_csv_service_spec.rb index d3359447fd8..1ac64c0301d 100644 --- a/spec/services/issues/export_csv_service_spec.rb +++ b/spec/services/issues/export_csv_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Issues::ExportCsvService, :with_license do +RSpec.describe Issues::ExportCsvService, :with_license, feature_category: :team_planning do let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, :public, group: group) } @@ -57,137 +57,151 @@ RSpec.describe Issues::ExportCsvService, :with_license do time_estimate: 72000) end - it 'includes the columns required for import' do - expect(csv.headers).to include('Title', 'Description') - end - - it 'returns two issues' do - expect(csv.count).to eq(2) - end + shared_examples 'exports CSVs for issues' do + it 'includes the columns required for import' do + expect(csv.headers).to include('Title', 'Description') + end - specify 'iid' do - expect(csv[0]['Issue ID']).to eq issue.iid.to_s - end + it 'returns two issues' do + expect(csv.count).to eq(2) + end - specify 'url' do - expect(csv[0]['URL']).to match(/http.*#{project.full_path}.*#{issue.iid}/) - end + specify 'iid' do + expect(csv[0]['Issue ID']).to eq issue.iid.to_s + end - specify 'title' do - expect(csv[0]['Title']).to eq issue.title - end + specify 'url' do + expect(csv[0]['URL']).to match(/http.*#{project.full_path}.*#{issue.iid}/) + end - specify 'state' do - expect(csv[0]['State']).to eq 'Open' - end + specify 'title' do + expect(csv[0]['Title']).to eq issue.title + end - specify 'description' do - expect(csv[0]['Description']).to eq issue.description - expect(csv[1]['Description']).to eq nil - end + specify 'state' do + expect(csv[0]['State']).to eq 'Open' + end - specify 'author name' do - expect(csv[0]['Author']).to eq issue.author_name - end + specify 'description' do + expect(csv[0]['Description']).to eq issue.description + expect(csv[1]['Description']).to eq nil + end - specify 'author username' do - expect(csv[0]['Author Username']).to eq issue.author.username - end + specify 'author name' do + expect(csv[0]['Author']).to eq issue.author_name + end - specify 'assignee name' do - expect(csv[0]['Assignee']).to eq user.name - expect(csv[1]['Assignee']).to eq '' - end + specify 'author username' do + expect(csv[0]['Author Username']).to eq issue.author.username + end - specify 'assignee username' do - expect(csv[0]['Assignee Username']).to eq user.username - expect(csv[1]['Assignee Username']).to eq '' - end + specify 'assignee name' do + expect(csv[0]['Assignee']).to eq user.name + expect(csv[1]['Assignee']).to eq '' + end - specify 'confidential' do - expect(csv[0]['Confidential']).to eq 'No' - end + specify 'assignee username' do + expect(csv[0]['Assignee Username']).to eq user.username + expect(csv[1]['Assignee Username']).to eq '' + end - specify 'milestone' do - expect(csv[0]['Milestone']).to eq issue.milestone.title - expect(csv[1]['Milestone']).to eq nil - end + specify 'confidential' do + expect(csv[0]['Confidential']).to eq 'No' + end - specify 'labels' do - expect(csv[0]['Labels']).to eq 'Feature,Idea' - expect(csv[1]['Labels']).to eq nil - end + specify 'milestone' do + expect(csv[0]['Milestone']).to eq issue.milestone.title + expect(csv[1]['Milestone']).to eq nil + end - specify 'due_date' do - expect(csv[0]['Due Date']).to eq '2014-03-02' - expect(csv[1]['Due Date']).to eq nil - end + specify 'labels' do + expect(csv[0]['Labels']).to eq 'Feature,Idea' + expect(csv[1]['Labels']).to eq nil + end - specify 'created_at' do - expect(csv[0]['Created At (UTC)']).to eq '2015-04-03 02:01:00' - end + specify 'due_date' do + expect(csv[0]['Due Date']).to eq '2014-03-02' + expect(csv[1]['Due Date']).to eq nil + end - specify 'updated_at' do - expect(csv[0]['Updated At (UTC)']).to eq '2016-05-04 03:02:01' - end + specify 'created_at' do + expect(csv[0]['Created At (UTC)']).to eq '2015-04-03 02:01:00' + end - specify 'closed_at' do - expect(csv[0]['Closed At (UTC)']).to eq '2017-06-05 04:03:02' - expect(csv[1]['Closed At (UTC)']).to eq nil - end + specify 'updated_at' do + expect(csv[0]['Updated At (UTC)']).to eq '2016-05-04 03:02:01' + end - specify 'discussion_locked' do - expect(csv[0]['Locked']).to eq 'Yes' - end + specify 'closed_at' do + expect(csv[0]['Closed At (UTC)']).to eq '2017-06-05 04:03:02' + expect(csv[1]['Closed At (UTC)']).to eq nil + end - specify 'weight' do - expect(csv[0]['Weight']).to eq '4' - end + specify 'discussion_locked' do + expect(csv[0]['Locked']).to eq 'Yes' + end - specify 'time estimate' do - expect(csv[0]['Time Estimate']).to eq '72000' - expect(csv[1]['Time Estimate']).to eq '0' - end + specify 'weight' do + expect(csv[0]['Weight']).to eq '4' + end - specify 'time spent' do - expect(csv[0]['Time Spent']).to eq '560' - expect(csv[1]['Time Spent']).to eq '0' - end + specify 'time estimate' do + expect(csv[0]['Time Estimate']).to eq '72000' + expect(csv[1]['Time Estimate']).to eq '0' + end - context 'with issues filtered by labels and project' do - subject do - described_class.new( - IssuesFinder.new(user, - project_id: project.id, - label_name: %w(Idea Feature)).execute, project) + specify 'time spent' do + expect(csv[0]['Time Spent']).to eq '560' + expect(csv[1]['Time Spent']).to eq '0' end - it 'returns only filtered objects' do - expect(csv.count).to eq(1) - expect(csv[0]['Issue ID']).to eq issue.iid.to_s + context 'with issues filtered by labels and project' do + subject do + described_class.new( + IssuesFinder.new(user, + project_id: project.id, + label_name: %w(Idea Feature)).execute, project) + end + + it 'returns only filtered objects' do + expect(csv.count).to eq(1) + expect(csv[0]['Issue ID']).to eq issue.iid.to_s + end end - end - context 'with label links' do - let(:labeled_issues) { create_list(:labeled_issue, 2, project: project, author: user, labels: [feature_label, idea_label]) } + context 'with label links' do + let(:labeled_issues) { create_list(:labeled_issue, 2, project: project, author: user, labels: [feature_label, idea_label]) } - it 'does not run a query for each label link' do - control_count = ActiveRecord::QueryRecorder.new { csv }.count + it 'does not run a query for each label link' do + control_count = ActiveRecord::QueryRecorder.new { csv }.count - labeled_issues + labeled_issues - expect { csv }.not_to exceed_query_limit(control_count) - expect(csv.count).to eq(4) - end + expect { csv }.not_to exceed_query_limit(control_count) + expect(csv.count).to eq(4) + end - it 'returns the labels in sorted order' do - labeled_issues + it 'returns the labels in sorted order' do + labeled_issues - labeled_rows = csv.select { |entry| labeled_issues.map(&:iid).include?(entry['Issue ID'].to_i) } - expect(labeled_rows.count).to eq(2) - expect(labeled_rows.map { |entry| entry['Labels'] }).to all(eq("Feature,Idea")) + labeled_rows = csv.select { |entry| labeled_issues.map(&:iid).include?(entry['Issue ID'].to_i) } + expect(labeled_rows.count).to eq(2) + expect(labeled_rows.map { |entry| entry['Labels'] }).to all(eq("Feature,Idea")) + end end end + + context 'with export_csv_preload_in_batches feature flag disabled' do + before do + stub_feature_flags(export_csv_preload_in_batches: false) + end + + it_behaves_like 'exports CSVs for issues' + end + + context 'with export_csv_preload_in_batches feature flag enabled' do + it_behaves_like 'exports CSVs for issues' + end end context 'with minimal details' do |