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: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gem "dartsass-rails", "~> 0.5.1"
gem "cfa-styleguide", "0.18.0", git: "https://github.com/codeforamerica/honeycrisp-gem"

gem "phonelib"
gem "valid_email2"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ GEM
unicode-emoji (4.2.0)
uri (1.1.1)
useragent (0.16.11)
valid_email2 (7.0.13)
activemodel (>= 6.0)
mail (~> 2.5)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -518,6 +521,7 @@ DEPENDENCIES
thruster
turbo-rails
tzinfo-data
valid_email2
web-console

CHECKSUMS
Expand Down Expand Up @@ -697,6 +701,7 @@ CHECKSUMS
unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6
useragent (0.16.11) sha256=700e6413ad4bb954bb63547fa098dddf7b0ebe75b40cc6f93b8d54255b173844
valid_email2 (7.0.13) sha256=a131f807c23778a00e4d35e1cd69b91550bb243886bc9aa99f49fea19bd34088
web-console (4.2.1) sha256=e7bcf37a10ea2b4ec4281649d1cee461b32232d0a447e82c786e6841fd22fe20
websocket (1.2.11) sha256=b7e7a74e2410b5e85c25858b26b3322f29161e300935f70a0e0d3c35e0462737
websocket-driver (0.8.0) sha256=ed0dba4b943c22f17f9a734817e808bc84cdce6a7e22045f5315aa57676d4962
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/email_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class EmailController < QuestionController
include BasicInfoConcern

def self.attributes_edited
[:email, :email_confirmation]
end
end
1 change: 1 addition & 0 deletions app/controllers/navigation/screener_navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ScreenerNavigation < ControllerNavigation::ControllerNavigation
ControllerNavigation::NavigationStep.new(DisabilityBenefitsController),
ControllerNavigation::NavigationStep.new(BasicInfoMilestoneController),
ControllerNavigation::NavigationStep.new(PersonalInformationController),
ControllerNavigation::NavigationStep.new(EmailController),
ControllerNavigation::NavigationStep.new(TempEndController)
])
].freeze
Expand Down
1 change: 1 addition & 0 deletions app/controllers/temp_end_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class TempEndController < QuestionController
layout "application"
def show_progress_bar
false
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/screener.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Screener < ApplicationRecord
attr_accessor :email_confirmation
enum :language_preference_spoken, {unfilled: 0, english: 1, spanish: 2}, prefix: true
enum :language_preference_written, {unfilled: 0, english: 1, spanish: 2}, prefix: true
enum :is_receiving_snap_benefits, {unfilled: 0, yes: 1, no: 2}, prefix: true
Expand All @@ -20,6 +21,7 @@ class Screener < ApplicationRecord
attr_writer :birth_date_year, :birth_date_month, :birth_date_day
attr_writer :pregnancy_due_date_year, :pregnancy_due_date_month, :pregnancy_due_date_day
normalizes :phone_number, with: ->(value) { Phonelib.parse(value, "US").national }
before_validation :strip_email_and_confirmation

with_context :language_preference do
validates :language_preference_spoken, inclusion: {in: %w[english spanish], message: "must be english or spanish"}
Expand Down Expand Up @@ -76,6 +78,10 @@ class Screener < ApplicationRecord
end
end

with_context :email do
validates :email, "valid_email_2/email": true, confirmation: true
end

def locale
language_preference_written_spanish? ? :es : :en
end
Expand Down Expand Up @@ -103,4 +109,9 @@ def pregnancy_due_date_month
def pregnancy_due_date_day
pregnancy_due_date&.day
end

def strip_email_and_confirmation
self.email = email.strip.downcase if email.present?
self.email_confirmation = email_confirmation.strip.downcase if email_confirmation.present?
end
end
11 changes: 11 additions & 0 deletions app/views/email/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% content_for :question_title, t("views.email.edit.title") %>

<h1 class="h2"><%= content_for(:question_title) %></h1>

<p><%= t("views.email.edit.title_help_text") %></p>

<%= form_with model: @model, url: { action: :update }, data: { turbo: false }, local: true, method: "put", builder: Cfa::Styleguide::CfaFormBuilder do |f| %>
<%= f.cfa_input_field(:email, t("views.email.edit.email")) %>
<%= f.cfa_input_field(:email_confirmation, t("views.email.edit.email_confirmation")) %>
<%= f.submit t("general.continue"), class: "button button--primary" %>
<% end %>
61 changes: 36 additions & 25 deletions app/views/temp_end/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
<div>
<h2>End of example</h2>
<br/>
<table>
<tr style="font-weight: bold; border-bottom: 1px solid #ddd;">
<th style="padding-right: 15px;">screener id</th>
<th style="padding-right: 15px;">written language</th>
<th style="padding-right: 15px;">spoken language</th>
<th style="padding-right: 15px;">is_receiving_snap_benefits</th>
</tr>
<% Screener.all.each do |screener| %>
<tr style="border-bottom: 1px solid #ddd;">
<td><%= screener.id %></td>
<td><%= screener.language_preference_written %></td>
<td><%= screener.language_preference_spoken %></td>
<td><%= screener.first_name %></td>
<td><%= screener.middle_name %></td>
<td><%= screener.last_name %></td>
<td><%= screener.birth_date %></td>
<td><%= screener.phone_number %></td>
<td><%= screener.is_receiving_snap_benefits_yes? %></td>
</tr>
<% end %>
</table>
</div>
<section class="slab">
<div class="grid">
<div class="grid__item width-one-whole">
<h2>End of example</h2>
<br/>
<table style="display: block;overflow-x: auto;white-space: nowrap;">
<tr style="font-weight: bold; border-bottom: 1px solid #ddd;">
<th style="padding-right: 15px;">screener id</th>
<th style="padding-right: 15px;">written language</th>
<th style="padding-right: 15px;">spoken language</th>
<th style="padding-right: 15px;">first_name</th>
<th style="padding-right: 15px;">middle_name</th>
<th style="padding-right: 15px;">last_name</th>
<th style="padding-right: 15px;">birth_date</th>
<th style="padding-right: 15px;">phone_number</th>
<th style="padding-right: 15px;">is_receiving_snap_benefits</th>
<th style="padding-right: 15px;">email</th>
</tr>
<% Screener.all.each do |screener| %>
<tr style="border-bottom: 1px solid #ddd;">
<td><%= screener.id %></td>
<td><%= screener.language_preference_written %></td>
<td><%= screener.language_preference_spoken %></td>
<td><%= screener.first_name %></td>
<td><%= screener.middle_name %></td>
<td><%= screener.last_name %></td>
<td><%= screener.birth_date %></td>
<td><%= screener.phone_number %></td>
<td><%= screener.is_receiving_snap_benefits_yes? %></td>
<td><%= screener.email %></td>
</tr>
<% end %>
</table>
</div>
</div>
</section>
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ en:
receiving_benefits_workers_compensation: Worker’s compensation
receiving_benefits_write_in: If you don’t see your benefit above, please write it here.
title: Are you receiving any of these disability benefits?
email:
edit:
email: Email
email_confirmation: Confirm your email
title: Where can we send your results?
title_help_text: We'll email you next steps with form results that you should submit to your SNAP agency.
has_child:
edit:
help_text: You do not have to be the child’s parent, be responsible for the child, or be their legal guardian. If you live with the child, select “Yes,” even if they aren’t included in your SNAP case.
Expand Down
6 changes: 6 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ es:
receiving_benefits_workers_compensation: Compensación para trabajadores
receiving_benefits_write_in: Si el beneficio que recibe no está en la lista, escríbalo aquí.
title: "¿Recibe alguno de estos beneficios por discapacidad?"
email:
edit:
email: Email
email_confirmation: Correo electrónico
title: Confirme su correo electrónico
title_help_text: Le enviaremos los próximos pasos junto con los resultados de su formulario que deberá presentar a su agencia de SNAP, por correo electrónico.
has_child:
edit:
help_text: You do not have to be the child’s parent, be responsible for the child, or be their legal guardian. If you live with the child, select “Yes,” even if they aren’t included in your SNAP case.
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20260106232306_add_email_to_screener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEmailToScreener < ActiveRecord::Migration[8.1]
def change
add_column :screeners, :email, :string
end
end
1 change: 1 addition & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions spec/controllers/email_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "rails_helper"

RSpec.describe EmailController, type: :controller do
describe "#update" do
it "saves the email regardless of white spaces or capitalization" do
screener = create(:screener)

params = {
email: "[email protected] ",
email_confirmation: " [email protected]"
}

post :update, params: {screener: params}
expect(response).to redirect_to subject.next_path
expect(screener.reload.email).to eq "[email protected]"
end
end
end
5 changes: 5 additions & 0 deletions spec/features/flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
fill_in I18n.t("views.personal_information.edit.phone_number_label"), with: "415-816-1286"
click_on I18n.t("general.continue")

expect(page).to have_selector("h1", text: I18n.t("views.email.edit.title"))
fill_in I18n.t("views.email.edit.email"), with: "[email protected]"
fill_in I18n.t("views.email.edit.email_confirmation"), with: "[email protected]"
click_on I18n.t("general.continue")

expect(page).to have_selector("h2", text: "End of example")
end
end
23 changes: 23 additions & 0 deletions spec/models/screener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,28 @@

expect(screener.reload.pregnancy_due_date).to be_nil
end

context "with_context :email" do
it "requires a valid email" do
screener = Screener.new(email: "hi.gmail", email_confirmation: "hi.gmail")
screener.valid?(:email)

expect(screener.errors).to match_array ["Email is invalid"]
end

it "requires a confirmed email" do
screener = Screener.new(email: "[email protected]", email_confirmation: "[email protected]")
screener.valid?(:email)

expect(screener.errors).to match_array ["Email confirmation doesn't match Email"]
end

it "removed white spaces from the email and confirmation" do
screener = Screener.new(email: "[email protected] ", email_confirmation: " [email protected]")
screener.valid?(:email)

expect(screener.errors).to match_array []
end
end
end
end