- <% @county_data[:mailing_address].split("\n").map do |line| %>
+ <% LocationData::Counties.mailing_address_for(state, county).split("\n").map do |line| %>
<%= line %>
<%= t('views.screener_mailer.send_screener_results.in_person_instructions') %>
- <% @county_data[:physical_address].split("\n").map do |line| %>
+ <% LocationData::Counties.physical_address_for(state, county).split("\n").map do |line| %>
<%= line %>
<% end %>
@@ -61,11 +64,13 @@
- - <%= t('views.screener_mailer.send_screener_results.check_website', website: @county_data[:website]) %>
- <% if @county_data[:email].present? %>
+ - <%= t('views.screener_mailer.send_screener_results.check_website', website: website) %>
+ <% if email.present? %>
-
- <%= t('views.screener_mailer.send_screener_results.email_office', email: @county_data[:email]) %>
+ <%= t('views.screener_mailer.send_screener_results.email_office', email: email) %>
<% end %>
- - <%= t('views.screener_mailer.send_screener_results.call_office', phone: @county_data[:phone]) %>
+ <% if (phone = LocationData::Counties.phone_for(state, county)).present? %>
+ - <%= t('views.screener_mailer.send_screener_results.call_office', phone: phone) %>
+ <% end %>
diff --git a/app/views/screener_mailer/send_screener_results.text.erb b/app/views/screener_mailer/send_screener_results.text.erb
index 5551e071..8eb6c54e 100644
--- a/app/views/screener_mailer/send_screener_results.text.erb
+++ b/app/views/screener_mailer/send_screener_results.text.erb
@@ -11,25 +11,31 @@
<%= t('views.screener_mailer.send_screener_results.reference_code', code: @screener.confirmation_code) %>
---
+<% state = @screener.state %>
+<% county = @screener.county %>
+<% website = LocationData::Counties.website_for(state, county) %>
+<% email = LocationData::Counties.email_for(state, county) %>
<%= t('views.screener_mailer.send_screener_results.how_to_submit_heading') %>
1. <%= t('views.screener_mailer.send_screener_results.online_label') %> <%= t('views.screener_mailer.send_screener_results.online_epass_text') %>
- <%= 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? %>.
+ <%= 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? %>.
2. <%= t('views.screener_mailer.send_screener_results.mail_label') %> <%= t('views.screener_mailer.send_screener_results.mail_instructions') %>
- <%= @county_data[:mailing_address].split("\n").join("\n ") %>
+ <%= LocationData::Counties.mailing_address_for(state, county).split("\n").join("\n ") %>
3. <%= t('views.screener_mailer.send_screener_results.in_person_label') %> <%= t('views.screener_mailer.send_screener_results.in_person_instructions') %>
- <%= @county_data[:physical_address].split("\n").join("\n ") %>
+ <%= LocationData::Counties.physical_address_for(state, county).split("\n").join("\n ") %>
<%= t('views.screener_mailer.send_screener_results.questions_intro') %>
-- <%= t('views.screener_mailer.send_screener_results.check_website', website: @county_data[:website]) %>
-<% if @county_data[:email].present? %>
-- <%= t('views.screener_mailer.send_screener_results.email_office', email: @county_data[:email]) %>
+- <%= t('views.screener_mailer.send_screener_results.check_website', website: website) %>
+<% if email.present? %>
+- <%= t('views.screener_mailer.send_screener_results.email_office', email: email) %>
+<% end %>
+<% if (phone = LocationData::Counties.phone_for(state, county)).present? %>
+- <%= t('views.screener_mailer.send_screener_results.call_office', phone: phone) %>
<% end %>
-- <%= t('views.screener_mailer.send_screener_results.call_office', phone: @county_data[:phone]) %>
diff --git a/spec/controllers/out_of_state_controller_spec.rb b/spec/controllers/out_of_state_controller_spec.rb
index 56ede4cf..610b629c 100644
--- a/spec/controllers/out_of_state_controller_spec.rb
+++ b/spec/controllers/out_of_state_controller_spec.rb
@@ -35,7 +35,9 @@ def county_name(county)
describe ".county_not_supported?" do
it "returns false when county is nil" do
screener = create(:screener, state: state_with_counties, county: nil)
- expect(described_class.county_not_supported?(screener)).to eq(false)
+ expect {
+ described_class.county_not_supported?(screener)
+ }.to raise_error(ArgumentError, /county_key is required/)
end
it "returns false for supported counties" do
diff --git a/spec/models/location_data_spec.rb b/spec/models/location_data_spec.rb
index 87692d3f..80dffd00 100644
--- a/spec/models/location_data_spec.rb
+++ b/spec/models/location_data_spec.rb
@@ -63,22 +63,6 @@
end
end
- describe ".get" do
- it "returns the correct data for each county" do
- all_counties.each do |state, counties|
- counties.each do |county_name, data|
- result = described_class.get(state, county_name)
- expect(result).to eq(data)
- end
- end
- end
-
- it "returns nil for unknown county or state" do
- expect(described_class.get("NC", "Fake County")).to be_nil
- expect(described_class.get("FAKE", "Some County")).to be_nil
- end
- end
-
describe "county counts" do
it "reports correct number of counties per state" do
all_counties.each do |state, counties|
@@ -89,30 +73,30 @@
end
end
- describe ".fetch_county!" do
+ describe ".get" do
let(:state) { all_counties.keys.first }
let(:county) { all_counties[state].keys.first }
it "returns the county when valid inputs are provided" do
- result = described_class.fetch_county!(state, county)
+ result = described_class.get(state, county)
expect(result).to eq(all_counties[state][county])
end
it "raises error when state_code is blank" do
expect {
- described_class.fetch_county!(nil, county)
+ described_class.get(nil, county)
}.to raise_error(ArgumentError, /state_code is required/)
end
it "raises error when county_key is blank" do
expect {
- described_class.fetch_county!(state, nil)
+ described_class.get(state, nil)
}.to raise_error(ArgumentError, /county_key is required/)
end
it "raises error when county does not exist" do
expect {
- described_class.fetch_county!(state, "Fake County")
+ described_class.get(state, "Fake County")
}.to raise_error(StandardError, /County not found/)
end
end
@@ -133,6 +117,22 @@
end
end
+ describe ".email_for" do
+ let(:state) { all_counties.keys.first }
+ let(:county) { all_counties[state].keys.first }
+
+ it "returns the email for a valid county" do
+ expected = all_counties[state][county][:email]
+ expect(described_class.email_for(state, county)).to eq(expected)
+ end
+
+ it "raises when county not found" do
+ expect {
+ described_class.email_for(state, "Fake County")
+ }.to raise_error(StandardError)
+ end
+ end
+
describe ".upload_portal_or_email_for" do
let(:state) { all_counties.keys.first }