Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/mailers/screener_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class ScreenerMailer < ApplicationMailer

def send_screener_results(outgoing_email:)
@screener = outgoing_email.screener
@county_data = LocationData::Counties.get(@screener.state, @screener.county)
attachments.inline["gbh_email_header.png"] = File.binread(Rails.root.join("app/assets/images/gbh_email_header.png"))
Copy link
Copy Markdown
Collaborator

@anisharamnani anisharamnani Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i’m not totally sure why these need to be instance variables since they’re accessible by the @screener

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them, and just created the state and county in the two erb files to make things easier to read!

mail(to: @screener.email, subject: I18n.t("views.screener_mailer.send_screener_results.subject"))
end
Expand Down
32 changes: 16 additions & 16 deletions app/models/location_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ def self.load_all

ALL_COUNTIES = load_all

def self.fetch_county!(state_code, county_key)
raise ArgumentError, "state_code is required" if state_code.blank?
raise ArgumentError, "county_key is required" if county_key.blank?

county = ALL_COUNTIES.dig(state_code, county_key)
raise StandardError, "County not found for #{state_code} / #{county_key}" unless county

county
end

def self.for_state(state)
ALL_COUNTIES[state] || {}
end
Expand All @@ -80,29 +70,39 @@ def self.options_for(state)
end

def self.get(state, county_key)
for_state(state)[county_key]
raise ArgumentError, "state_code is required" if state.blank?
raise ArgumentError, "county_key is required" if county_key.blank?

county = ALL_COUNTIES.dig(state, county_key)
raise StandardError, "County not found for #{state} / #{county_key}" unless county

county
end

def self.website_for(state_code, county_key)
fetch_county!(state_code, county_key)[:website]
get(state_code, county_key)[:website]
end

def self.upload_portal_or_email_for(state_code, county_key)
county = fetch_county!(state_code, county_key)
county = get(state_code, county_key)
county[:upload_portal_or_email].presence || county[:email]
end

def self.email_for(state_code, county_key)
get(state_code, county_key)[:email]
end

def self.mailing_address_for(state_code, county_key)
fetch_county!(state_code, county_key)[:mailing_address]
get(state_code, county_key)[:mailing_address]
end

def self.physical_address_for(state_code, county_key)
county = fetch_county!(state_code, county_key)
county = get(state_code, county_key)
county[:physical_address].presence || county[:mailing_address]
end

def self.phone_for(state_code, county_key)
fetch_county!(state_code, county_key)[:phone]
get(state_code, county_key)[:phone]
end
end
end
21 changes: 13 additions & 8 deletions app/views/screener_mailer/send_screener_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@
<h3 style="font-weight: bold;">
<%= t('views.screener_mailer.send_screener_results.how_to_submit_heading') %>
</h3>
<% state = @screener.state %>
<% county = @screener.county %>
<% website = LocationData::Counties.website_for(state, county) %>
<% email = LocationData::Counties.email_for(state, county) %>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just so make it easier to read, since the values are reused in a couple places within the file.


<ol style="line-height: 2;">
<li>
<strong><%= t('views.screener_mailer.send_screener_results.online_label') %></strong> <%= t('views.screener_mailer.send_screener_results.online_epass_html').html_safe %>
<br/><br/>
<%= 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? %>.
</li>
<%= 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? %>.
</li>
<li>
<strong><%= t('views.screener_mailer.send_screener_results.mail_label') %></strong> <%= t('views.screener_mailer.send_screener_results.mail_instructions') %>
<br/><br/>
<div style="font-style: italic;">
<% @county_data[:mailing_address].split("\n").map do |line| %>
<% LocationData::Counties.mailing_address_for(state, county).split("\n").map do |line| %>
<%= line %>
<br/>
<% end %>
Expand All @@ -48,7 +51,7 @@
<strong><%= t('views.screener_mailer.send_screener_results.in_person_label') %></strong> <%= t('views.screener_mailer.send_screener_results.in_person_instructions') %>
<br/><br/>
<div style="font-style: italic;">
<% @county_data[:physical_address].split("\n").map do |line| %>
<% LocationData::Counties.physical_address_for(state, county).split("\n").map do |line| %>
<%= line %>
<br/>
<% end %>
Expand All @@ -61,11 +64,13 @@
</p>

<ul style="line-height: 2;">
<li><%= t('views.screener_mailer.send_screener_results.check_website', website: @county_data[:website]) %></li>
<% if @county_data[:email].present? %>
<li><%= t('views.screener_mailer.send_screener_results.check_website', website: website) %></li>
<% if email.present? %>
<li>
<%= t('views.screener_mailer.send_screener_results.email_office', email: @county_data[:email]) %>
<%= t('views.screener_mailer.send_screener_results.email_office', email: email) %>
</li>
<% end %>
<li><%= t('views.screener_mailer.send_screener_results.call_office', phone: @county_data[:phone]) %></li>
<% if (phone = LocationData::Counties.phone_for(state, county)).present? %>
<li><%= t('views.screener_mailer.send_screener_results.call_office', phone: phone) %></li>
<% end %>
</ul>
20 changes: 13 additions & 7 deletions app/views/screener_mailer/send_screener_results.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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]) %>
4 changes: 3 additions & 1 deletion spec/controllers/out_of_state_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions spec/models/location_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand All @@ -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 }

Expand Down
Loading