Skip to content

Commit

Permalink
Adding counties to partner export for NDBN reporting (#4840)
Browse files Browse the repository at this point in the history
* County export

* rubocop happiness

* suggested changes, plus added second profile to test

* rubocop happiness
  • Loading branch information
cielf authored Dec 13, 2024
1 parent e1e3d11 commit b5586da
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def self.csv_export_headers
"Contact Name",
"Contact Phone",
"Contact Email",
"Notes"
"Notes",
"Counties Served"
]
end

Expand All @@ -202,7 +203,8 @@ def csv_export_attributes
contact_person[:name],
contact_person[:phone],
contact_person[:email],
notes
notes,
profile.county_list_by_region
]
end

Expand Down
6 changes: 6 additions & 0 deletions app/models/partners/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Profile < Base

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

has_many :counties, through: :served_areas
accepts_nested_attributes_for :served_areas, allow_destroy: true

has_many_attached :documents
Expand Down Expand Up @@ -125,6 +126,11 @@ def split_pick_up_emails
pick_up_email.split(/,|\s+/).compact_blank
end

def county_list_by_region
# provides a county list in case insensitive alpha order, by region, then county name
counties.order(%w(lower(region) lower(name))).pluck(:name).join("; ")
end

private

def check_social_media
Expand Down
14 changes: 12 additions & 2 deletions spec/models/partner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,16 @@
partner.update(notes: notes)
end

it "should has the info in the columns order" do
it "should have the expected info in the columns order" do
county_1 = create(:county, name: "High County, Maine", region: "Maine")
county_2 = create(:county, name: "laRue County, Louisiana", region: "Louisiana")
county_3 = create(:county, name: "Ste. Anne County, Louisiana", region: "Louisiana")
create(:partners_served_area, partner_profile: partner.profile, county: county_1, client_share: 50)
create(:partners_served_area, partner_profile: partner.profile, county: county_2, client_share: 40)
create(:partners_served_area, partner_profile: partner.profile, county: county_3, client_share: 10)
partner.profile.reload # not sure if this is needed
# county ordering is a bit esoteric -- it is human alphabetical by county within region (region is state)
correctly_ordered_counties = "laRue County, Louisiana; Ste. Anne County, Louisiana; High County, Maine"
expect(partner.csv_export_attributes).to eq([
partner.name,
partner.email,
Expand All @@ -330,7 +339,8 @@
contact_name,
contact_phone,
contact_email,
notes
notes,
correctly_ordered_counties
])
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/models/partners/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,25 @@
end
end

describe "county_list" do
it "provides a county list in human-alpha by county within region order" do
county_1 = create(:county, name: "High County, Maine", region: "Maine")
county_2 = create(:county, name: "laRue County, Louisiana", region: "Louisiana")
county_3 = create(:county, name: "Ste. Anne County, Louisiana", region: "Louisiana")
county_4 = create(:county, name: "Other County, Louisiana", region: "Louisiana")
profile = create(:partner_profile)
profile_2 = create(:partner_profile)
create(:partners_served_area, partner_profile: profile, county: county_1, client_share: 50)
create(:partners_served_area, partner_profile: profile, county: county_2, client_share: 40)
create(:partners_served_area, partner_profile: profile, county: county_3, client_share: 10)
create(:partners_served_area, partner_profile: profile_2, county: county_4)
profile.reload
profile_2.reload
## This is human-alpha by county within region (i.e. state)
expect(profile.county_list_by_region).to eq("laRue County, Louisiana; Ste. Anne County, Louisiana; High County, Maine")
end
end

describe "versioning" do
it { is_expected.to be_versioned }
end
Expand Down

0 comments on commit b5586da

Please sign in to comment.