Skip to content

Commit dc20f1c

Browse files
Updated the order to columns to more closely match the order of fields in the partner profile form, renamed column headers to match fields in the form
1 parent 933a162 commit dc20f1c

3 files changed

Lines changed: 155 additions & 138 deletions

File tree

app/services/exports/export_partners_csv_service.rb

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ def base_table
3131
table = {
3232
"Agency Name" => ->(partner) { partner.name },
3333
"Agency Email" => ->(partner) { partner.email },
34-
"Agency Type" => ->(partner) {
35-
symbolic_agency_type = partner.profile.agency_type&.to_sym
36-
(symbolic_agency_type == :other) ? "#{I18n.t symbolic_agency_type, scope: :partners_profile}: #{partner.profile.other_agency_type}" : (I18n.t symbolic_agency_type, scope: :partners_profile)
37-
},
34+
"Notes" => ->(partner) { partner.notes },
35+
"Agency Type" => ->(partner) { I18n.t(partner.profile.agency_type, scope: :partners_profile) }, # Columns from the agency_information partial
36+
"Other Agency Type" => ->(partner) { partner.profile.other_agency_type },
3837
"Agency Mission" => ->(partner) { partner.profile.agency_mission },
39-
"Agency Address" => ->(partner) { "#{partner.profile.address1}, #{partner.profile.address2}" },
38+
"Agency Address" => ->(partner) {
39+
(partner.profile.address1.blank? || partner.profile.address2.blank?) ?
40+
"" : "#{partner.profile.address1}, #{partner.profile.address2}"
41+
},
4042
"Agency City" => ->(partner) { partner.profile.city },
4143
"Agency State" => ->(partner) { partner.profile.state },
4244
"Agency Zip Code" => ->(partner) { partner.profile.zip_code },
4345
"Program/Delivery Address" => ->(partner) { "#{partner.profile.program_address1}, #{partner.profile.program_address2}" },
46+
"Program/Delivery Address" => ->(partner) {
47+
(partner.profile.program_address1.blank? || partner.profile.program_address2.blank?) ?
48+
"" : "#{partner.profile.program_address1}, #{partner.profile.program_address2}"
49+
},
4450
"Program City" => ->(partner) { partner.profile.program_city },
4551
"Program State" => ->(partner) { partner.profile.program_state },
46-
"Program Zip Code" => ->(partner) { partner.profile.program_zip_code },
47-
"Notes" => ->(partner) { partner.notes },
48-
"Counties Served" => ->(partner) { county_list_by_regions[partner.id] || "" },
49-
"Providing Diapers" => ->(partner) { diaper_statuses[partner.id] },
50-
"Providing Period Supplies" => ->(partner) { period_supplies_statuses[partner.id] }
52+
"Program Zip Code" => ->(partner) { partner.profile.program_zip_code }
5153
}
5254

5355
if @partials_to_show.include? "media_information"
@@ -63,7 +65,7 @@ def base_table
6365
table["Form 990 Filed"] = ->(partner) { partner.profile.form_990 }
6466
table["Program Name"] = ->(partner) { partner.profile.program_name }
6567
table["Program Description"] = ->(partner) { partner.profile.program_description }
66-
table["Program Age"] = ->(partner) { partner.profile.program_age }
68+
table["Agency Age"] = ->(partner) { partner.profile.program_age }
6769
table["Evidence Based"] = ->(partner) { partner.profile.evidence_based }
6870
table["Case Management"] = ->(partner) { partner.profile.case_management }
6971
table["How Are Essentials Used"] = ->(partner) { partner.profile.essentials_use }
@@ -79,11 +81,15 @@ def base_table
7981

8082
if @partials_to_show.include? "sources_of_funding"
8183
table["Sources Of Funding"] = ->(partner) { partner.profile.sources_of_funding }
82-
table["Sources Of Diapers"] = ->(partner) { partner.profile.sources_of_diapers }
84+
table["How do you currently obtain diapers?"] = ->(partner) { partner.profile.sources_of_diapers }
8385
table["Essentials Budget"] = ->(partner) { partner.profile.essentials_budget }
8486
table["Essentials Funding Source"] = ->(partner) { partner.profile.essentials_funding_source }
8587
end
8688

89+
if @partials_to_show.include? "area_served"
90+
table["Area Served"] = ->(partner) { county_list_by_regions[partner.id] || "" }
91+
end
92+
8793
if @partials_to_show.include? "population_served"
8894
table["Income Requirement"] = ->(partner) { partner.profile.income_requirement_desc }
8995
table["Verify Income"] = ->(partner) { partner.profile.income_verification }
@@ -106,10 +112,10 @@ def base_table
106112
table["Executive Director Name"] = ->(partner) { partner.profile.executive_director_name }
107113
table["Executive Director Phone"] = ->(partner) { partner.profile.executive_director_phone }
108114
table["Executive Director Email"] = ->(partner) { partner.profile.executive_director_email }
109-
table["Contact Name"] = ->(partner) { partner.profile.primary_contact_name }
110-
table["Contact Phone"] = ->(partner) { partner.profile.primary_contact_phone }
111-
table["Contact Cell"] = ->(partner) { partner.profile.primary_contact_mobile }
112-
table["Contact Email"] = ->(partner) { partner.profile.primary_contact_email }
115+
table["Primary Contact Name"] = ->(partner) { partner.profile.primary_contact_name }
116+
table["Primary Contact Phone"] = ->(partner) { partner.profile.primary_contact_phone }
117+
table["Primary Contact Cell"] = ->(partner) { partner.profile.primary_contact_mobile }
118+
table["Primary Contact Email"] = ->(partner) { partner.profile.primary_contact_email }
113119
end
114120

115121
if @partials_to_show.include? "pick_up_person"
@@ -124,10 +130,13 @@ def base_table
124130
table["More Docs Required"] = ->(partner) { partner.profile.more_docs_required }
125131
end
126132

127-
table["Quantity-based Requests"] = ->(partner) { partner.profile.enable_quantity_based_requests }
133+
table["Quantity-based Requests"] = ->(partner) { partner.profile.enable_quantity_based_requests } # Columns from the partner_settings partial
128134
table["Child-based Requests"] = ->(partner) { partner.profile.enable_child_based_requests }
129135
table["Individual Requests"] = ->(partner) { partner.profile.enable_individual_requests }
130136

137+
table["Providing Diapers"] = ->(partner) { diaper_statuses[partner.id] }
138+
table["Providing Period Supplies"] = ->(partner) { period_supplies_statuses[partner.id] }
139+
131140
table
132141
end
133142

spec/requests/partners_requests_spec.rb

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
let(:name) { "Leslie Sue" }
5858
let(:email) { "leslie@sue.com" }
5959
let(:notes) { "Some notes" }
60-
let(:providing_diapers) { {value: "N", index: 22} }
61-
let(:providing_period_supplies) { {value: "N", index: 23} }
62-
6360
let(:agency_type) { :other } # Columns from the agency_information partial
6461
let(:other_agency_type) { "Another Agency Name" }
6562
let(:agency_mission) { "agency_mission" }
@@ -81,12 +78,16 @@
8178
let(:enable_quantity_based_requests) { true } # Columns from the partner_settings partial
8279
let(:enable_child_based_requests) { true }
8380
let(:enable_individual_requests) { true }
81+
let(:providing_diapers) { {value: "N", index: -2} }
82+
let(:providing_period_supplies) { {value: "N", index: -1} }
8483

8584
let(:expected_headers) {
8685
[
87-
"Agency Name",
86+
"Agency Name", # Technically not part of the agency_information partial, but comes at the start of the export
8887
"Agency Email",
88+
"Notes",
8989
"Agency Type", # Columns from the agency_information partial
90+
"Other Agency Type",
9091
"Agency Mission",
9192
"Agency Address",
9293
"Agency City",
@@ -96,26 +97,26 @@
9697
"Program City",
9798
"Program State",
9899
"Program Zip Code",
99-
"Notes",
100-
"Counties Served",
101-
"Providing Diapers",
102-
"Providing Period Supplies",
103100
"Agency Website", # Columns from the media_information partial
104101
"Facebook",
105102
"Twitter",
106103
"Instagram",
107104
"No Social Media Presence",
108-
"Quantity-based Requests", # Columns from the partner_settings partial
105+
"Quantity-based Requests", # Columns from the agency_information partial
109106
"Child-based Requests",
110-
"Individual Requests"
107+
"Individual Requests",
108+
"Providing Diapers", # Technically not part of the partner_settings partial, but comes at the end of the export
109+
"Providing Period Supplies"
111110
]
112111
}
113112

114113
let(:expected_values) {
115114
[
116-
partner.name,
115+
partner.name, # Technically not part of the agency_information partial, but comes at the start of the export
117116
partner.email,
118-
"#{I18n.t "partners_profile.other"}: #{other_agency_type}", # Columns from the agency_information partial
117+
notes,
118+
I18n.t("partners_profile.other").to_s, # Columns from the agency_information partial
119+
other_agency_type.to_s,
119120
agency_mission,
120121
"#{agency_address1}, #{agency_address2}",
121122
agency_city,
@@ -125,18 +126,16 @@
125126
program_city,
126127
program_state,
127128
program_zip_code.to_s,
128-
notes,
129-
"",
130-
providing_diapers[:value],
131-
providing_period_supplies[:value],
132129
agency_website, # Columns from the media_information partial
133130
facebook,
134131
twitter,
135132
instagram,
136133
no_social_media_presence.to_s,
137134
enable_quantity_based_requests.to_s, # Columns from the partner_settings partial
138135
enable_child_based_requests.to_s,
139-
enable_individual_requests.to_s
136+
enable_individual_requests.to_s,
137+
providing_diapers[:value], # Technically not part of the partner_settings partial, but comes at the end of the export
138+
providing_period_supplies[:value]
140139
]
141140
}
142141

@@ -158,31 +157,33 @@
158157
primary_contact_email: nil
159158
))
160159

160+
# The agency_information and settings sections contain information stored on the partner and not the
161+
# profile, so they won't be completely empty
161162
expected_values = [
162163
partner.name,
163164
partner.email,
165+
notes,
164166
"", # Columns from the agency_information partial
165167
"",
166-
", ",
167168
"",
168169
"",
169170
"",
170-
", ",
171171
"",
172172
"",
173173
"",
174-
notes,
175174
"",
176-
providing_diapers[:value],
177-
providing_period_supplies[:value],
175+
"",
176+
"",
178177
"", # Columns from the media_information partial
179178
"",
180179
"",
181180
"",
182-
"".to_s,
181+
"",
183182
enable_quantity_based_requests.to_s, # Columns from the partner_settings partial
184183
enable_child_based_requests.to_s,
185-
enable_individual_requests.to_s
184+
enable_individual_requests.to_s,
185+
providing_diapers[:value],
186+
providing_period_supplies[:value]
186187
]
187188

188189
get partners_path(partner, format: response_format)
@@ -210,6 +211,10 @@
210211
end
211212

212213
context "with served counties" do
214+
before do
215+
organization.update(partner_form_fields: organization.partner_form_fields += ["area_served"])
216+
end
217+
213218
it "returns them in correct order" do
214219
county_1 = create(:county, name: "High County, Maine", region: "Maine")
215220
county_2 = create(:county, name: "laRue County, Louisiana", region: "Louisiana")
@@ -222,7 +227,7 @@
222227

223228
csv = CSV.parse(response.body, headers: true)
224229

225-
expect(csv[0]["Counties Served"]).to eq("laRue County, Louisiana; Ste. Anne County, Louisiana; High County, Maine")
230+
expect(csv[0]["Area Served"]).to eq("laRue County, Louisiana; Ste. Anne County, Louisiana; High County, Maine")
226231
end
227232
end
228233

@@ -259,9 +264,6 @@
259264
let(:name_2) { "Jane Doe" }
260265
let(:email_2) { "jane@doe.com" }
261266
let(:notes_2) { "Some notes" }
262-
let(:providing_diapers_2) { {value: "N", index: 22} }
263-
let(:providing_period_supplies_2) { {value: "N", index: 23} }
264-
265267
let(:agency_type_2) { :other } # Columns from the agency_information partial
266268
let(:other_agency_type_2) { "Another Agency Name" }
267269
let(:agency_mission_2) { "agency_mission" }
@@ -283,6 +285,8 @@
283285
let(:enable_quantity_based_requests_2) { true } # Columns from the partner_settings partial
284286
let(:enable_child_based_requests_2) { true }
285287
let(:enable_individual_requests_2) { true }
288+
let(:providing_diapers_2) { {value: "N", index: 22} }
289+
let(:providing_period_supplies_2) { {value: "N", index: 23} }
286290

287291
it "orders partners alphaetically" do
288292
get partners_path(partner, format: response_format)
@@ -293,7 +297,9 @@
293297
[
294298
partner_2.name,
295299
partner_2.email,
296-
"#{I18n.t "partners_profile.other"}: #{other_agency_type_2}", # Columns from the agency_information partial
300+
notes_2,
301+
I18n.t("partners_profile.other").to_s, # Columns from the agency_information partial
302+
other_agency_type_2.to_s,
297303
agency_mission_2,
298304
"#{agency_address1_2}, #{agency_address2_2}",
299305
agency_city_2,
@@ -303,18 +309,16 @@
303309
program_city_2,
304310
program_state_2,
305311
program_zip_code_2.to_s,
306-
notes_2,
307-
"", # no counties
308-
providing_diapers_2[:value],
309-
providing_period_supplies_2[:value],
310312
agency_website_2, # Columns from the media_information partial
311313
facebook_2,
312314
twitter_2,
313315
instagram_2,
314316
no_social_media_presence_2.to_s,
315317
enable_quantity_based_requests_2.to_s, # Columns from the partner_settings partial
316318
enable_child_based_requests_2.to_s,
317-
enable_individual_requests_2.to_s
319+
enable_individual_requests_2.to_s,
320+
providing_diapers_2[:value],
321+
providing_period_supplies_2[:value]
318322
]
319323
)
320324
end

0 commit comments

Comments
 (0)