Skip to content

Commit b5586da

Browse files
authored
Adding counties to partner export for NDBN reporting (#4840)
* County export * rubocop happiness * suggested changes, plus added second profile to test * rubocop happiness
1 parent e1e3d11 commit b5586da

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

app/models/partner.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ def self.csv_export_headers
185185
"Contact Name",
186186
"Contact Phone",
187187
"Contact Email",
188-
"Notes"
188+
"Notes",
189+
"Counties Served"
189190
]
190191
end
191192

@@ -202,7 +203,8 @@ def csv_export_attributes
202203
contact_person[:name],
203204
contact_person[:phone],
204205
contact_person[:email],
205-
notes
206+
notes,
207+
profile.county_list_by_region
206208
]
207209
end
208210

app/models/partners/profile.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class Profile < Base
9191

9292
has_many :served_areas, foreign_key: "partner_profile_id", class_name: "Partners::ServedArea", dependent: :destroy, inverse_of: :partner_profile
9393

94+
has_many :counties, through: :served_areas
9495
accepts_nested_attributes_for :served_areas, allow_destroy: true
9596

9697
has_many_attached :documents
@@ -125,6 +126,11 @@ def split_pick_up_emails
125126
pick_up_email.split(/,|\s+/).compact_blank
126127
end
127128

129+
def county_list_by_region
130+
# provides a county list in case insensitive alpha order, by region, then county name
131+
counties.order(%w(lower(region) lower(name))).pluck(:name).join("; ")
132+
end
133+
128134
private
129135

130136
def check_social_media

spec/models/partner_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,16 @@
317317
partner.update(notes: notes)
318318
end
319319

320-
it "should has the info in the columns order" do
320+
it "should have the expected info in the columns order" do
321+
county_1 = create(:county, name: "High County, Maine", region: "Maine")
322+
county_2 = create(:county, name: "laRue County, Louisiana", region: "Louisiana")
323+
county_3 = create(:county, name: "Ste. Anne County, Louisiana", region: "Louisiana")
324+
create(:partners_served_area, partner_profile: partner.profile, county: county_1, client_share: 50)
325+
create(:partners_served_area, partner_profile: partner.profile, county: county_2, client_share: 40)
326+
create(:partners_served_area, partner_profile: partner.profile, county: county_3, client_share: 10)
327+
partner.profile.reload # not sure if this is needed
328+
# county ordering is a bit esoteric -- it is human alphabetical by county within region (region is state)
329+
correctly_ordered_counties = "laRue County, Louisiana; Ste. Anne County, Louisiana; High County, Maine"
321330
expect(partner.csv_export_attributes).to eq([
322331
partner.name,
323332
partner.email,
@@ -330,7 +339,8 @@
330339
contact_name,
331340
contact_phone,
332341
contact_email,
333-
notes
342+
notes,
343+
correctly_ordered_counties
334344
])
335345
end
336346
end

spec/models/partners/profile_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@
307307
end
308308
end
309309

310+
describe "county_list" do
311+
it "provides a county list in human-alpha by county within region order" do
312+
county_1 = create(:county, name: "High County, Maine", region: "Maine")
313+
county_2 = create(:county, name: "laRue County, Louisiana", region: "Louisiana")
314+
county_3 = create(:county, name: "Ste. Anne County, Louisiana", region: "Louisiana")
315+
county_4 = create(:county, name: "Other County, Louisiana", region: "Louisiana")
316+
profile = create(:partner_profile)
317+
profile_2 = create(:partner_profile)
318+
create(:partners_served_area, partner_profile: profile, county: county_1, client_share: 50)
319+
create(:partners_served_area, partner_profile: profile, county: county_2, client_share: 40)
320+
create(:partners_served_area, partner_profile: profile, county: county_3, client_share: 10)
321+
create(:partners_served_area, partner_profile: profile_2, county: county_4)
322+
profile.reload
323+
profile_2.reload
324+
## This is human-alpha by county within region (i.e. state)
325+
expect(profile.county_list_by_region).to eq("laRue County, Louisiana; Ste. Anne County, Louisiana; High County, Maine")
326+
end
327+
end
328+
310329
describe "versioning" do
311330
it { is_expected.to be_versioned }
312331
end

0 commit comments

Comments
 (0)