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
15 changes: 15 additions & 0 deletions app/controllers/birth_date_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BirthDateController < QuestionController
include DateHelper

def show_progress_bar
false
end

private

def form_params(model)
model_from_params = params["screener"]
birth_date = parse_date_params(model_from_params[:birth_date_year], model_from_params[:birth_date_month], model_from_params[:birth_date_day])
{birth_date: birth_date}
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 @@ -4,6 +4,7 @@ class ScreenerNavigation < ControllerNavigation::ControllerNavigation
ControllerNavigation::NavigationSection.new("navigation.section_1", [
ControllerNavigation::NavigationStep.new(OverviewController),
ControllerNavigation::NavigationStep.new(LanguagePreferenceController),
ControllerNavigation::NavigationStep.new(BirthDateController),
ControllerNavigation::NavigationStep.new(ReceivingBenefitsController),
ControllerNavigation::NavigationStep.new(AmericanIndianController),
ControllerNavigation::NavigationStep.new(HasChildController),
Expand Down
11 changes: 1 addition & 10 deletions app/controllers/personal_information_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
class PersonalInformationController < QuestionController
include BasicInfoConcern
include DateHelper

def self.attributes_edited
[:first_name, :middle_name, :last_name, :birth_date, :phone_number]
end

private

def form_params(model)
model_from_params = params[model.class.params_key]
birth_date = parse_date_params(model_from_params[:birth_date_year].to_i, model_from_params[:birth_date_month].to_i, model_from_params[:birth_date_day].to_i)
params.expect(model.class.params_key => self.class.attributes_edited).merge({birth_date: birth_date})
[:first_name, :middle_name, :last_name, :phone_number]
end
end
6 changes: 5 additions & 1 deletion app/models/screener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ class Screener < ApplicationRecord
before_save :remove_volunteer_attributes_if_no
before_save :remove_pregnancy_attributes_if_no

with_context :birth_date do
validates :birth_date, presence: {message: I18n.t("validations.date_missing_or_invalid")}
end

with_context :language_preference do
validates :language_preference_spoken, inclusion: {in: %w[english spanish], message: "must be english or spanish"}
validates :language_preference_written, inclusion: {in: %w[english spanish], message: "must be english or spanish"}
end

with_context :personal_information do
validates :first_name, :last_name, :birth_date, :phone_number, presence: true
validates :first_name, :last_name, :phone_number, presence: true
validates :phone_number, phone: {possible: true, country_specifier: ->(_) { "US" }, allow_blank: true}
end

Expand Down
27 changes: 27 additions & 0 deletions app/views/birth_date/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<% content_for :question_title, t("views.birth_date.edit.title") %>

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

<div class="notice teal">
<div class="media-box">
<div class="media-box__media media--icon">
<i class="icon-help"></i>
</div>
<div class="media-box__content">
<%= t("views.birth_date.edit.help_text") %>
</div>
</div>
</div>

<%= form_with model: @model, url: { action: :update }, data: { turbo: false }, local: true, method: "put", builder: Cfa::Styleguide::CfaFormBuilder do |f| %>
<%= f.cfa_date_select(
:birth_date,
"",
options: {
start_year: Time.now.year,
end_year: Time.now.year - 150,
}
) %>

<%= f.submit t("general.continue"), class: "button button--primary" %>
<% end %>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ en:
progress_bar_text_html: Section %{step} of 3 <strong>%{section_name}</strong>
work_rules: Work rules
validations:
date_missing_or_invalid: Date is missing or invalid
date_must_be_in_future: Date must be in the future
must_answer_yes_or_no: Must answer yes or no
views:
Expand All @@ -27,6 +28,10 @@ en:
edit:
help_text_html: This information will help your agency find your SNAP case.
title: Basic information
birth_date:
edit:
help_text: You do not have to follow the work rules if you are younger than 18, or older than 65+ years.
title: What is your date of birth? (required)
caring_for_someone:
edit:
child_under_6: Child under age 6
Expand Down
5 changes: 5 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ es:
progress_bar_text_html: Sección %{step} de 3 <strong>%{section_name}</strong>
work_rules: Reglas de trabajo
validations:
date_missing_or_invalid: La fecha falta o no es válida
date_must_be_in_future: La fecha debe ser en el futuro
must_answer_yes_or_no: Debe responder sí o no
views:
Expand All @@ -27,6 +28,10 @@ es:
edit:
help_text_html: Esta información ayudará a que su agencia encuentre su caso de SNAP.
title: Información básica
birth_date:
edit:
help_text: No tiene que cumplir con las reglas de trabajo SNAP si es menor de 18 años o tiene 65 años o más.
title: "¿Cuál es su fecha de nacimiento? (requerido)"
caring_for_someone:
edit:
child_under_6: Niño menor de 6 años
Expand Down
49 changes: 49 additions & 0 deletions spec/controllers/birth_date_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "rails_helper"

RSpec.describe BirthDateController, type: :controller do
describe "#edit" do
render_views

it "reads and displays the individual date attributes if birth_date is saved on screener" do
create(:screener, birth_date: Date.new(1973, 10, 13))
get :edit

expect(response.body).to have_select("Year", selected: "1973")
expect(response.body).to have_select("Month", selected: "October")
expect(response.body).to have_select("Day", selected: "13")
end
end

describe "#update" do
context "birth date" do
it "combines the date picker params into the birth_date attribute" do
screener = create(:screener)

params = {
birth_date_month: "10",
birth_date_day: "13",
birth_date_year: "1973"
}

post :update, params: {screener: params}
expect(screener.reload.birth_date).to eq Date.new(1973, 10, 13)
end

render_views

it "displays an error if any parameters are is missing" do
create(:screener)

params = {
birth_date_month: "5",
birth_date_day: "3",
birth_date_year: ""
}

post :update, params: {screener: params}
expect(response).to render_template :edit
expect(response.body).to have_text I18n.t("validations.date_missing_or_invalid")
end
end
end
end
68 changes: 16 additions & 52 deletions spec/controllers/personal_information_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,59 +1,23 @@
require "rails_helper"

RSpec.describe PersonalInformationController, type: :controller do
describe "#edit" do
context "birth date" do
render_views

it "reads and displays the individual date attributes if birth_date is saved on screener" do
create(:screener, birth_date: Date.new(1973, 10, 13))
get :edit

expect(response.body).to have_select("Year", selected: "1973")
expect(response.body).to have_select("Month", selected: "October")
expect(response.body).to have_select("Day", selected: "13")
end
end
end

describe "#update" do
context "birth date" do
it "combines the date picker params into the birth_date attribute" do
screener = create(:screener)

params = {
first_name: "Noel",
middle_name: "G",
last_name: "Fielding",
phone_number: "4158161286",
birth_date_month: "10",
birth_date_day: "13",
birth_date_year: "1973"
}

post :update, params: {screener: params}
expect(screener.reload.birth_date).to eq Date.new(1973, 10, 13)
end

render_views

it "displays an error if birth_date is missing" do
create(:screener)

params = {
first_name: "Noel",
middle_name: "G",
last_name: "Fielding",
phone_number: "5551231234",
birth_date_month: "",
birth_date_day: "",
birth_date_year: ""
}

post :update, params: {screener: params}
expect(response).to render_template :edit
expect(response.body).to have_text "can't be blank"
end
it "persists attributes to the screener" do
screener = create(:screener)

params = {
first_name: "Noel",
middle_name: "G",
last_name: "Fielding",
phone_number: "4158161286"
}

post :update, params: {screener: params}
expect(response).to redirect_to subject.next_path
expect(screener.reload.first_name).to eq "Noel"
Copy link
Collaborator

Choose a reason for hiding this comment

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

expect(screener.reload.middle_name).to eq "G"
expect(screener.reload.last_name).to eq "Fielding"
expect(screener.reload.phone_number).to eq "(415) 816-1286"
end
end
end
9 changes: 6 additions & 3 deletions spec/features/flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
expect(page).to have_selector("h1", text: I18n.t("views.language_preference.edit.title"))
click_on I18n.t("general.continue")

expect(page).to have_selector("h1", text: I18n.t("views.birth_date.edit.title"))
select "September", from: "Month"
select "21", from: "Day"
select "1940", from: "Year"
click_on I18n.t("general.continue")

expect(page).to have_selector("h1", text: I18n.t("views.receiving_benefits.edit.title"))
choose I18n.t("views.receiving_benefits.edit.is_yes")
click_on I18n.t("general.continue")
Expand Down Expand Up @@ -57,9 +63,6 @@
expect(page).to have_selector("h1", text: I18n.t("views.personal_information.edit.title"))
fill_in I18n.t("views.personal_information.edit.first_name_label"), with: "Prue"
fill_in I18n.t("views.personal_information.edit.last_name_label"), with: "Leith"
select "September", from: "Month"
select "21", from: "Day"
select "1940", from: "Year"
fill_in I18n.t("views.personal_information.edit.phone_number_label"), with: "415-816-1286"
click_on I18n.t("general.continue")

Expand Down
14 changes: 11 additions & 3 deletions spec/models/screener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
end
end

context "with_context :birth_date" do
it "requires birth date" do
screener = Screener.new(birth_date: nil)
screener.valid?(:birth_date)

expect(screener.errors).to match_array ["Birth date #{I18n.t("validations.date_missing_or_invalid")}"]
end
end

context "with_context :language_preference" do
it "requires language preferences to be filled out" do
screener = Screener.new(language_preference_spoken: "unfilled", language_preference_written: "unfilled")
Expand All @@ -30,14 +39,13 @@
end

context "with_context :personal_information" do
it "requires first name, last name, birth date, and phone number" do
screener = Screener.new(first_name: nil, last_name: nil, birth_date: nil, phone_number: nil)
it "requires first name, last name, and phone number" do
screener = Screener.new(first_name: nil, last_name: nil, phone_number: nil)
screener.valid?(:personal_information)

expect(screener.errors).to match_array [
"First name can't be blank",
"Last name can't be blank",
"Birth date can't be blank",
"Phone number can't be blank"
]
end
Expand Down