Skip to content

Commit

Permalink
Work around membership_years subscription export issue (#1325, #1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed Dec 11, 2024
1 parent 38ad240 commit 0e94620
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/jobs/sac_cas/export/subscriptions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 16 additions & 2 deletions spec/jobs/export/subscriptions_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0e94620

Please sign in to comment.