diff --git a/app/models/projects/exports/query_exporter.rb b/app/models/projects/exports/query_exporter.rb index a26d2ec7e69e..e4a110afd9bf 100644 --- a/app/models/projects/exports/query_exporter.rb +++ b/app/models/projects/exports/query_exporter.rb @@ -32,7 +32,7 @@ class QueryExporter < Exports::Exporter alias :query :object def columns - @columns ||= (forced_columns + selected_columns) + @columns ||= selected_columns end def page @@ -51,13 +51,6 @@ def projects private - def forced_columns - [ - { name: :id, caption: Project.human_attribute_name(:id) }, - { name: :identifier, caption: Project.human_attribute_name(:identifier) } - ] - end - def selected_columns query .selects diff --git a/modules/xls_export/spec/models/xls_export/project/exporter/xls_integration_spec.rb b/modules/xls_export/spec/models/xls_export/project/exporter/xls_integration_spec.rb index bddf083e1391..69081bee1c31 100644 --- a/modules/xls_export/spec/models/xls_export/project/exporter/xls_integration_spec.rb +++ b/modules/xls_export/spec/models/xls_export/project/exporter/xls_integration_spec.rb @@ -27,8 +27,7 @@ it "performs a successful export" do expect(rows.count).to eq(1) - expect(sheet.row(1)).to eq [project.id.to_s, project.identifier, - project.name, project.description, "Off track", "false"] + expect(sheet.row(1)).to eq [project.name, project.description, "Off track", "false"] end context "with project description containing html" do @@ -38,8 +37,7 @@ it "performs a successful export" do expect(rows.count).to eq(1) - expect(sheet.row(1)).to eq [project.id.to_s, project.identifier, project.name, - "This is an html description.", "Off track", "false"] + expect(sheet.row(1)).to eq [project.name, "This is an html description.", "Off track", "false"] end end @@ -48,12 +46,21 @@ it "performs a successful export" do expect(rows.count).to eq(1) - expect(sheet.row(1)).to eq [project.id.to_s, project.identifier, - project.name, project.description, + expect(sheet.row(1)).to eq [project.name, project.description, "Off track", project.status_explanation, "false"] end end + context "with id and identifier enabled" do + let(:query_columns) { %w[name description project_status public id identifier] } + + it "performs a successful export" do + expect(rows.count).to eq(1) + expect(sheet.row(1)).to eq [project.name, project.description, "Off track", + "false", project.id.to_s, project.identifier] + end + end + describe "custom field columns selected" do let(:query_columns) { %w[name description project_status public] + global_project_custom_fields.map(&:column_name) } @@ -66,7 +73,7 @@ it "renders all those columns" do cf_names = global_project_custom_fields.map(&:name) - expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public", *cf_names] + expect(header).to eq ["Name", "Description", "Status", "Public", *cf_names] expect(header).to include not_used_string_cf.name expect(header).to include hidden_cf.name @@ -85,8 +92,7 @@ end expect(sheet.row(1)) - .to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false", - *custom_values] + .to eq [project.name, project.description, "Off track", "false", *custom_values] # The column for the project-level-disabled custom field is blank expect(sheet.row(1)[header.index(not_used_string_cf.name)]).to be_nil @@ -97,7 +103,7 @@ it "renders available project custom fields in the header if enabled in any project" do cf_names = global_project_custom_fields.map(&:name) - expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public", *cf_names] + expect(header).to eq ["Name", "Description", "Status", "Public", *cf_names] expect(header).not_to include not_used_string_cf.name expect(header).not_to include hidden_cf.name @@ -116,8 +122,7 @@ end expect(sheet.row(1)) - .to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false", - *custom_values] + .to eq [project.name, project.description, "Off track", "false", *custom_values] end end @@ -125,10 +130,10 @@ let(:permissions) { %i(view_projects) } it "does not render project custom fields in the header" do - expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public"] + expect(header).to eq %w[Name Description Status Public] expect(sheet.row(1)) - .to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false"] + .to eq [project.name, project.description, "Off track", "false"] end end end diff --git a/spec/models/projects/exporter/csv_integration_spec.rb b/spec/models/projects/exporter/csv_integration_spec.rb index 11dcb17aa1db..77d5e362d2c4 100644 --- a/spec/models/projects/exporter/csv_integration_spec.rb +++ b/spec/models/projects/exporter/csv_integration_spec.rb @@ -43,8 +43,7 @@ it "performs a successful export" do expect(parsed.size).to eq(2) - expect(parsed.last).to eq [project.id.to_s, project.identifier, - project.name, project.description, "Off track", "false"] + expect(parsed.last).to eq [project.name, project.description, "Off track", "false"] end context "with status_explanation enabled" do @@ -52,12 +51,21 @@ it "performs a successful export" do expect(parsed.size).to eq(2) - expect(parsed.last).to eq [project.id.to_s, project.identifier, - project.name, project.description, + expect(parsed.last).to eq [project.name, project.description, "Off track", "some explanation", "false"] end end + context "with id and identifier selected" do + let(:query_columns) { %w[name description id identifier project_status public] } + + it "performs a successful export" do + expect(parsed.size).to eq(2) + expect(parsed.last).to eq [project.name, project.description, project.id.to_s, + project.identifier, "Off track", "false"] + end + end + describe "custom field columns selected" do let(:query_columns) do %w[name description project_status public] + global_project_custom_fields.map(&:column_name) @@ -74,13 +82,12 @@ it "does not render project custom fields in the header" do expect(parsed.size).to eq 2 - expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public"] + expect(header).to eq ["\xEF\xBB\xBFName", "Description", "Status", "Public"] end it "does not render the custom field values in the rows if enabled for a project" do expect(rows.first) - .to eq [project.id.to_s, project.identifier, project.name, - project.description, "Off track", "false"] + .to eq [project.name, project.description, "Off track", "false"] end end @@ -93,7 +100,7 @@ expect(cf_names).not_to include(not_used_string_cf.name) expect(cf_names).not_to include(hidden_cf.name) - expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public", *cf_names] + expect(header).to eq ["\xEF\xBB\xBFName", "Description", "Status", "Public", *cf_names] end it "renders the custom field values in the rows if enabled for a project" do @@ -110,8 +117,7 @@ end end expect(rows.first) - .to eq [project.id.to_s, project.identifier, project.name, - project.description, "Off track", "false", *custom_values] + .to eq [project.name, project.description, "Off track", "false", *custom_values] end end @@ -126,7 +132,7 @@ expect(cf_names).to include(not_used_string_cf.name) expect(cf_names).to include(hidden_cf.name) - expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public", *cf_names] + expect(header).to eq ["\xEF\xBB\xBFName", "Description", "Status", "Public", *cf_names] end it "renders the custom field values in the rows if enabled for a project" do @@ -145,8 +151,7 @@ end end expect(rows.first) - .to eq [project.id.to_s, project.identifier, project.name, - project.description, "Off track", "false", *custom_values] + .to eq [project.name, project.description, "Off track", "false", *custom_values] end end end