OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add export specs for hiding custom fields based on view permissions
Dombi Attilab5b98032c2a0
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.rbindex 21a2a620382..37aca09cf86 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@@ -94,13 +94,13 @@ RSpec.describe XlsExport::Project::Exporter::XLS doendend- context "without admin permission" do- it "renders all visible globally available project custom fields in the header" do+ context "with view_project_attributes permission" do+ it "renders available project custom fields in the header if enabled in any project" docf_names = global_project_custom_fields.map(&:name)expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public", *cf_names]- expect(header).to include not_used_string_cf.name+ expect(header).not_to include not_used_string_cf.nameexpect(header).not_to include hidden_cf.namecustom_values = global_project_custom_fields.map do |cf|@@ -121,6 +121,17 @@ RSpec.describe XlsExport::Project::Exporter::XLS do*custom_values]endend++ context "without view_project_attributes permission" do+ 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(sheet.row(1))+ .to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false"]+ end+ endendcontext "when ee not enabled" dodiff --git a/spec/models/projects/exporter/csv_integration_spec.rb b/spec/models/projects/exporter/csv_integration_spec.rbindex 464e77efa57..3813efdafed 100644--- a/spec/models/projects/exporter/csv_integration_spec.rb+++ b/spec/models/projects/exporter/csv_integration_spec.rb@@ -69,13 +69,29 @@ RSpec.describe Projects::Exports::CSV, "integration" doparsedend- context "without admin permission" do- it "renders all visible globally available project custom fields in the header" do+ context "without view_project_attributes permission" do+ let(:permissions) { %i(view_projects) }++ it "does not render project custom fields in the header" do+ expect(parsed.size).to eq 2++ expect(header).to eq ["id", "Identifier", "Name", "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"]+ end+ end++ context "with view_project_attributes permission" do+ it "renders available project custom fields in the header if enabled in any project" doexpect(parsed.size).to eq 2cf_names = global_project_custom_fields.map(&:name)- expect(cf_names).to include(not_used_string_cf.name)+ expect(cf_names).not_to include(not_used_string_cf.name)expect(cf_names).not_to include(hidden_cf.name)expect(header).to eq ["id", "Identifier", "Name", "Description", "Status", "Public", *cf_names]diff --git a/spec/models/projects/exporter/exportable_project_context.rb b/spec/models/projects/exporter/exportable_project_context.rbindex 77960e54256..4f27cd4c3b2 100644--- a/spec/models/projects/exporter/exportable_project_context.rb+++ b/spec/models/projects/exporter/exportable_project_context.rb@@ -81,9 +81,11 @@ RSpec.shared_context "with an instance of the described exporter" dologin_as current_userend+ let(:permissions) { %i(view_projects view_project_attributes) }+let(:current_user) docreate(:user,- member_with_permissions: { project => %i(view_projects) })+ member_with_permissions: { project => permissions })endlet(:query_columns) { %w[name description project_status public] }let(:query) do