Skip to content

Commit

Permalink
[#55021] project list export drops the id and identifier default
Browse files Browse the repository at this point in the history
From now on, if you want to export these columns, you must explicitly
select these in the view configuration before exporting. Your export
will always reflect the columns that you see in the web view.
  • Loading branch information
Tobias Dillmann committed Sep 11, 2024
1 parent 439e21b commit 625fc1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
9 changes: 1 addition & 8 deletions app/models/projects/exports/query_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QueryExporter < Exports::Exporter
alias :query :object

def columns
@columns ||= (forced_columns + selected_columns)
@columns ||= selected_columns
end

def page
Expand All @@ -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
Expand Down
31 changes: 18 additions & 13 deletions spec/models/projects/exporter/csv_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,29 @@

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
let(:query_columns) { %w[name description project_status status_explanation public] }

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)
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 625fc1c

Please sign in to comment.