diff --git a/app/jobs/sac_cas/export/subscriptions_job.rb b/app/jobs/sac_cas/export/subscriptions_job.rb index f4d1b8c8a..2684a0654 100644 --- a/app/jobs/sac_cas/export/subscriptions_job.rb +++ b/app/jobs/sac_cas/export/subscriptions_job.rb @@ -11,6 +11,7 @@ module SacCas::Export::SubscriptionsJob def data return recipients_data if @options[:recipients] return recipient_households_data if @options[:recipient_households] + return recipient_table_display_without_membership_years if @options[:selection] super end @@ -19,6 +20,13 @@ def entries super.select("household_key") end + # As adding .with_membership_years entries does not work we ignore membership_years column + def recipient_table_display_without_membership_years + table_display = TableDisplay.for(@user_id, Person) + table_display.selected -= %w[membership_years] + Export::Tabular::People::TableDisplays.export(@format, entries, table_display) + end + def recipients_data Export::Tabular::People::SacRecipients.export(@format, entries, mailing_list.group) end diff --git a/spec/jobs/export/subscriptions_job_spec.rb b/spec/jobs/export/subscriptions_job_spec.rb index 86bb3bb6c..9d8cc0366 100644 --- a/spec/jobs/export/subscriptions_job_spec.rb +++ b/spec/jobs/export/subscriptions_job_spec.rb @@ -38,17 +38,31 @@ described_class.new(:csv, user.id, mailing_list.id, selection: true, filename: "dummy") end - it "suceeds in exporting with Familien ID" do + def export_table_display_as_csv Tempfile.create do |file| Subscription.create!(mailing_list: mailing_list, subscriber: people(:familienmitglied)) expect(Export::Tabular::People::TableDisplays).to receive(:export).and_call_original expect(AsyncDownloadFile).to receive(:maybe_from_filename).and_return(file) job.perform file.rewind - csv = CSV.parse(file.read, col_sep: ";", headers: true) + yield CSV.parse(file.read, col_sep: ";", headers: true) + end + end + + it "suceeds in exporting with Familien ID" do + export_table_display_as_csv do |csv| expect(csv.headers).to include "Familien ID" expect(csv.pluck("Familien ID").compact.uniq).to eq %w[F4242] end end + + it "exports row but without membership_years" do + TableDisplay.create!(person_id: user.id, selected: %w[language membership_years], table_model_class: "Person") + export_table_display_as_csv do |csv| + expect(csv.headers).to include "Sprache" + expect(csv.pluck("Sprache").compact.uniq).to eq %w[de] + expect(csv.headers).not_to include "Anzahl Mitglieder-Jahre" + end + end end end