Skip to content

Commit 7d69c9b

Browse files
Added organization argument to ExportPartnersCSVService so which partials to show can be determined even when no partials are present
1 parent ee35185 commit 7d69c9b

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

app/controllers/partners_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def index
1515

1616
respond_to do |format|
1717
format.html
18-
format.csv { send_data Exports::ExportPartnersCSVService.new(@partners.unscope(:includes)).generate_csv, filename: "Partners-#{Time.zone.today}.csv" }
18+
format.csv { send_data Exports::ExportPartnersCSVService.new(@partners.unscope(:includes), current_organization).generate_csv, filename: "Partners-#{Time.zone.today}.csv" }
1919
end
2020
end
2121

app/services/exports/export_partners_csv_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ class ExportPartnersCSVService
44
# to this service object; this is happening within the same request/response cycle, so it's already
55
# in memory, so we can pass that collection in directly. Should this be moved to a background / async
66
# job, we will need to pass in a collection of IDs instead.
7-
def initialize(partners)
7+
def initialize(partners, organization)
88
@partners = partners.includes(:profile)
99
# Assumes that all of the partners belong to the same organization. This is true for the time being
1010
# and, were that to change, base_table would need to be reworked anyway to account for partners from
1111
# different orgs having different partials enabled, and thus different columns in the CSV.
12-
@partials_to_show = partners.first.partials_to_show
12+
@partials_to_show = organization.partials_to_show
1313
end
1414

1515
def generate_csv

spec/services/exports/export_partners_csv_service_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RSpec.describe Exports::ExportPartnersCSVService do
22
describe "#generate_csv" do
3-
subject { CSV.parse(described_class.new(partners).generate_csv) }
3+
subject { CSV.parse(described_class.new(partners, organization).generate_csv) }
44

55
let(:organization) { create(:organization) }
66

@@ -392,7 +392,7 @@
392392
partial_to_headers.keys.each do |partial|
393393
organization.update(partner_form_fields: [partial])
394394
partners.reload
395-
limited_export = CSV.parse(described_class.new(partners).generate_csv)
395+
limited_export = CSV.parse(described_class.new(partners, organization).generate_csv)
396396
expect(limited_export[0]).to eq(headers_base + partial_to_headers[partial])
397397
expect(limited_export[1]).to eq(values_base + partial_to_values[partial])
398398
end

0 commit comments

Comments
 (0)