Skip to content

Commit 96ecac6

Browse files
committed
Merge remote-tracking branch 'origin/main' into WRSAT-443-add-pdf-attachment-to-email
2 parents b981cf7 + ec66d20 commit 96ecac6

File tree

6 files changed

+66
-54
lines changed

6 files changed

+66
-54
lines changed

app/mailers/screener_mailer.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class ScreenerMailer < ApplicationMailer
33

44
def send_screener_results(outgoing_email:)
55
@screener = outgoing_email.screener
6-
@county_data = LocationData::Counties.get(@screener.state, @screener.county)
76
attachments.inline["gbh_email_header.png"] = File.binread(Rails.root.join("app/assets/images/gbh_email_header.png"))
87
attachments["work_requirements.pdf"] = {
98
mime_type: "application/pdf",

app/models/location_data.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ def self.load_all
6161

6262
ALL_COUNTIES = load_all
6363

64-
def self.fetch_county!(state_code, county_key)
65-
raise ArgumentError, "state_code is required" if state_code.blank?
66-
raise ArgumentError, "county_key is required" if county_key.blank?
67-
68-
county = ALL_COUNTIES.dig(state_code, county_key)
69-
raise StandardError, "County not found for #{state_code} / #{county_key}" unless county
70-
71-
county
72-
end
73-
7464
def self.for_state(state)
7565
ALL_COUNTIES[state] || {}
7666
end
@@ -80,29 +70,39 @@ def self.options_for(state)
8070
end
8171

8272
def self.get(state, county_key)
83-
for_state(state)[county_key]
73+
raise ArgumentError, "state_code is required" if state.blank?
74+
raise ArgumentError, "county_key is required" if county_key.blank?
75+
76+
county = ALL_COUNTIES.dig(state, county_key)
77+
raise StandardError, "County not found for #{state} / #{county_key}" unless county
78+
79+
county
8480
end
8581

8682
def self.website_for(state_code, county_key)
87-
fetch_county!(state_code, county_key)[:website]
83+
get(state_code, county_key)[:website]
8884
end
8985

9086
def self.upload_portal_or_email_for(state_code, county_key)
91-
county = fetch_county!(state_code, county_key)
87+
county = get(state_code, county_key)
9288
county[:upload_portal_or_email].presence || county[:email]
9389
end
9490

91+
def self.email_for(state_code, county_key)
92+
get(state_code, county_key)[:email]
93+
end
94+
9595
def self.mailing_address_for(state_code, county_key)
96-
fetch_county!(state_code, county_key)[:mailing_address]
96+
get(state_code, county_key)[:mailing_address]
9797
end
9898

9999
def self.physical_address_for(state_code, county_key)
100-
county = fetch_county!(state_code, county_key)
100+
county = get(state_code, county_key)
101101
county[:physical_address].presence || county[:mailing_address]
102102
end
103103

104104
def self.phone_for(state_code, county_key)
105-
fetch_county!(state_code, county_key)[:phone]
105+
get(state_code, county_key)[:phone]
106106
end
107107
end
108108
end

app/views/screener_mailer/send_screener_results.html.erb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@
2626
<h3 style="font-weight: bold;">
2727
<%= t('views.screener_mailer.send_screener_results.how_to_submit_heading') %>
2828
</h3>
29+
<% state = @screener.state %>
30+
<% county = @screener.county %>
31+
<% website = LocationData::Counties.website_for(state, county) %>
32+
<% email = LocationData::Counties.email_for(state, county) %>
2933

3034
<ol style="line-height: 2;">
3135
<li>
3236
<strong><%= t('views.screener_mailer.send_screener_results.online_label') %></strong> <%= t('views.screener_mailer.send_screener_results.online_epass_html').html_safe %>
3337
<br/><br/>
34-
<%= t('views.screener_mailer.send_screener_results.online_county', website: @county_data[:website]) %><%= t('views.screener_mailer.send_screener_results.online_county_with_email', email: @county_data[:email]) if @county_data[:email].present? %>.
35-
</li>
38+
<%= t('views.screener_mailer.send_screener_results.online_county', website: website) %><%= t('views.screener_mailer.send_screener_results.online_county_with_email', email: email) if email.present? %>.
3639
</li>
3740
<li>
3841
<strong><%= t('views.screener_mailer.send_screener_results.mail_label') %></strong> <%= t('views.screener_mailer.send_screener_results.mail_instructions') %>
3942
<br/><br/>
4043
<div style="font-style: italic;">
41-
<% @county_data[:mailing_address].split("\n").map do |line| %>
44+
<% LocationData::Counties.mailing_address_for(state, county).split("\n").map do |line| %>
4245
<%= line %>
4346
<br/>
4447
<% end %>
@@ -48,7 +51,7 @@
4851
<strong><%= t('views.screener_mailer.send_screener_results.in_person_label') %></strong> <%= t('views.screener_mailer.send_screener_results.in_person_instructions') %>
4952
<br/><br/>
5053
<div style="font-style: italic;">
51-
<% @county_data[:physical_address].split("\n").map do |line| %>
54+
<% LocationData::Counties.physical_address_for(state, county).split("\n").map do |line| %>
5255
<%= line %>
5356
<br/>
5457
<% end %>
@@ -61,11 +64,13 @@
6164
</p>
6265

6366
<ul style="line-height: 2;">
64-
<li><%= t('views.screener_mailer.send_screener_results.check_website', website: @county_data[:website]) %></li>
65-
<% if @county_data[:email].present? %>
67+
<li><%= t('views.screener_mailer.send_screener_results.check_website', website: website) %></li>
68+
<% if email.present? %>
6669
<li>
67-
<%= t('views.screener_mailer.send_screener_results.email_office', email: @county_data[:email]) %>
70+
<%= t('views.screener_mailer.send_screener_results.email_office', email: email) %>
6871
</li>
6972
<% end %>
70-
<li><%= t('views.screener_mailer.send_screener_results.call_office', phone: @county_data[:phone]) %></li>
73+
<% if (phone = LocationData::Counties.phone_for(state, county)).present? %>
74+
<li><%= t('views.screener_mailer.send_screener_results.call_office', phone: phone) %></li>
75+
<% end %>
7176
</ul>

app/views/screener_mailer/send_screener_results.text.erb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,31 @@
1111
<%= t('views.screener_mailer.send_screener_results.reference_code', code: @screener.confirmation_code) %>
1212

1313
---
14+
<% state = @screener.state %>
15+
<% county = @screener.county %>
16+
<% website = LocationData::Counties.website_for(state, county) %>
17+
<% email = LocationData::Counties.email_for(state, county) %>
1418

1519
<%= t('views.screener_mailer.send_screener_results.how_to_submit_heading') %>
1620

1721
1. <%= t('views.screener_mailer.send_screener_results.online_label') %> <%= t('views.screener_mailer.send_screener_results.online_epass_text') %>
1822

19-
<%= t('views.screener_mailer.send_screener_results.online_county', website: @county_data[:website]) %><%= " #{t('views.screener_mailer.send_screener_results.online_county_with_email', email: @county_data[:email])}" if @county_data[:email].present? %>.
23+
<%= t('views.screener_mailer.send_screener_results.online_county', website: website) %><%= " #{t('views.screener_mailer.send_screener_results.online_county_with_email', email: email)}" if email.present? %>.
2024

2125
2. <%= t('views.screener_mailer.send_screener_results.mail_label') %> <%= t('views.screener_mailer.send_screener_results.mail_instructions') %>
2226

23-
<%= @county_data[:mailing_address].split("\n").join("\n ") %>
27+
<%= LocationData::Counties.mailing_address_for(state, county).split("\n").join("\n ") %>
2428

2529
3. <%= t('views.screener_mailer.send_screener_results.in_person_label') %> <%= t('views.screener_mailer.send_screener_results.in_person_instructions') %>
2630

27-
<%= @county_data[:physical_address].split("\n").join("\n ") %>
31+
<%= LocationData::Counties.physical_address_for(state, county).split("\n").join("\n ") %>
2832

2933
<%= t('views.screener_mailer.send_screener_results.questions_intro') %>
3034

31-
- <%= t('views.screener_mailer.send_screener_results.check_website', website: @county_data[:website]) %>
32-
<% if @county_data[:email].present? %>
33-
- <%= t('views.screener_mailer.send_screener_results.email_office', email: @county_data[:email]) %>
35+
- <%= t('views.screener_mailer.send_screener_results.check_website', website: website) %>
36+
<% if email.present? %>
37+
- <%= t('views.screener_mailer.send_screener_results.email_office', email: email) %>
38+
<% end %>
39+
<% if (phone = LocationData::Counties.phone_for(state, county)).present? %>
40+
- <%= t('views.screener_mailer.send_screener_results.call_office', phone: phone) %>
3441
<% end %>
35-
- <%= t('views.screener_mailer.send_screener_results.call_office', phone: @county_data[:phone]) %>

spec/controllers/out_of_state_controller_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def county_name(county)
3535
describe ".county_not_supported?" do
3636
it "returns false when county is nil" do
3737
screener = create(:screener, state: state_with_counties, county: nil)
38-
expect(described_class.county_not_supported?(screener)).to eq(false)
38+
expect {
39+
described_class.county_not_supported?(screener)
40+
}.to raise_error(ArgumentError, /county_key is required/)
3941
end
4042

4143
it "returns false for supported counties" do

spec/models/location_data_spec.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,6 @@
6363
end
6464
end
6565

66-
describe ".get" do
67-
it "returns the correct data for each county" do
68-
all_counties.each do |state, counties|
69-
counties.each do |county_name, data|
70-
result = described_class.get(state, county_name)
71-
expect(result).to eq(data)
72-
end
73-
end
74-
end
75-
76-
it "returns nil for unknown county or state" do
77-
expect(described_class.get("NC", "Fake County")).to be_nil
78-
expect(described_class.get("FAKE", "Some County")).to be_nil
79-
end
80-
end
81-
8266
describe "county counts" do
8367
it "reports correct number of counties per state" do
8468
all_counties.each do |state, counties|
@@ -89,30 +73,30 @@
8973
end
9074
end
9175

92-
describe ".fetch_county!" do
76+
describe ".get" do
9377
let(:state) { all_counties.keys.first }
9478
let(:county) { all_counties[state].keys.first }
9579

9680
it "returns the county when valid inputs are provided" do
97-
result = described_class.fetch_county!(state, county)
81+
result = described_class.get(state, county)
9882
expect(result).to eq(all_counties[state][county])
9983
end
10084

10185
it "raises error when state_code is blank" do
10286
expect {
103-
described_class.fetch_county!(nil, county)
87+
described_class.get(nil, county)
10488
}.to raise_error(ArgumentError, /state_code is required/)
10589
end
10690

10791
it "raises error when county_key is blank" do
10892
expect {
109-
described_class.fetch_county!(state, nil)
93+
described_class.get(state, nil)
11094
}.to raise_error(ArgumentError, /county_key is required/)
11195
end
11296

11397
it "raises error when county does not exist" do
11498
expect {
115-
described_class.fetch_county!(state, "Fake County")
99+
described_class.get(state, "Fake County")
116100
}.to raise_error(StandardError, /County not found/)
117101
end
118102
end
@@ -133,6 +117,22 @@
133117
end
134118
end
135119

120+
describe ".email_for" do
121+
let(:state) { all_counties.keys.first }
122+
let(:county) { all_counties[state].keys.first }
123+
124+
it "returns the email for a valid county" do
125+
expected = all_counties[state][county][:email]
126+
expect(described_class.email_for(state, county)).to eq(expected)
127+
end
128+
129+
it "raises when county not found" do
130+
expect {
131+
described_class.email_for(state, "Fake County")
132+
}.to raise_error(StandardError)
133+
end
134+
end
135+
136136
describe ".upload_portal_or_email_for" do
137137
let(:state) { all_counties.keys.first }
138138

0 commit comments

Comments
 (0)