Add new fields to form
- Add :date_of_birth and :postal_code - Only display new fields when aplication has configured the custom census API and contains alias values for fields. Add 2 class Setting methods to check this feature: - force_presence_date_of_birth? - force_presence_postal_code?
This commit is contained in:
@@ -20,7 +20,8 @@ class Officing::ResidenceController < Officing::BaseController
|
||||
private
|
||||
|
||||
def residence_params
|
||||
params.require(:residence).permit(:document_number, :document_type, :year_of_birth)
|
||||
params.require(:residence).permit(:document_number, :document_type, :year_of_birth,
|
||||
:date_of_birth, :postal_code)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -197,5 +197,15 @@ class Setting < ApplicationRecord
|
||||
self[name] = value unless find_by(key: name)
|
||||
end
|
||||
end
|
||||
|
||||
def force_presence_date_of_birth?
|
||||
Setting["feature.remote_census"].present? &&
|
||||
Setting["remote_census.request.date_of_birth"].present?
|
||||
end
|
||||
|
||||
def force_presence_postal_code?
|
||||
Setting["feature.remote_census"].present? &&
|
||||
Setting["remote_census.request.postal_code"].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,18 @@
|
||||
placeholder: t("officing.residence.new.document_number"),
|
||||
autocomplete: "off" %>
|
||||
</div>
|
||||
|
||||
<% if Setting.force_presence_date_of_birth? %>
|
||||
<div class="date-of-birth small-12 medium-6 clear">
|
||||
<%= f.date_select :date_of_birth,
|
||||
prompt: true,
|
||||
start_year: 1900, end_year: minimum_required_age.years.ago.year %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Setting.force_presence_postal_code? %>
|
||||
<div class="small-12 medium-6">
|
||||
<%= f.text_field :postal_code, aria: {describedby: "postal-code-help-text"} %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="date-of-birth small-12 medium-6">
|
||||
<%= f.text_field :year_of_birth, type: "number", autocomplete: "off" %>
|
||||
</div>
|
||||
|
||||
@@ -116,4 +116,61 @@ describe "Residence", :with_frozen_time do
|
||||
expect(page).to have_content "Vote introduced!"
|
||||
end
|
||||
|
||||
context "With remote census configuration" do
|
||||
|
||||
before do
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.date_of_birth"] = "some.value"
|
||||
Setting["remote_census.request.postal_code"] = "some.value"
|
||||
create(:poll_officer_assignment, officer: officer)
|
||||
login_through_form_as_officer(officer.user)
|
||||
visit officing_root_path
|
||||
end
|
||||
|
||||
after do
|
||||
Setting["feature.remote_census"] = nil
|
||||
Setting["remote_census.request.date_of_birth"] = nil
|
||||
Setting["remote_census.request.postal_code"] = nil
|
||||
end
|
||||
|
||||
describe "Display form fields according to the remote census configuration" do
|
||||
|
||||
scenario "by default (without custom census) not display date_of_birth and postal_code" do
|
||||
Setting["feature.remote_census"] = false
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Validate document"
|
||||
end
|
||||
|
||||
expect(page).to have_css("#residence_document_type")
|
||||
expect(page).to have_css("#residence_document_number")
|
||||
expect(page).to have_css("#residence_year_of_birth")
|
||||
expect(page).not_to have_content("Date of birth")
|
||||
expect(page).not_to have_css("#residence_postal_code")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
scenario "can verify voter with date_of_birth and postal_code fields" do
|
||||
access_user_data = "get_habita_datos_response.get_habita_datos_return.datos_habitante.item"
|
||||
access_residence_data = "get_habita_datos_response.get_habita_datos_return.datos_vivienda.item"
|
||||
Setting["remote_census.response.date_of_birth"] = "#{access_user_data}.fecha_nacimiento_string"
|
||||
Setting["remote_census.response.postal_code"] = "#{access_residence_data}.codigo_postal"
|
||||
Setting["remote_census.response.valid"] = access_user_data
|
||||
within("#side_menu") do
|
||||
click_link "Validate document"
|
||||
end
|
||||
|
||||
select "DNI", from: "residence_document_type"
|
||||
fill_in "residence_document_number", with: "12345678Z"
|
||||
select_date "31-December-1980", from: "residence_date_of_birth"
|
||||
fill_in "residence_postal_code", with: "28001"
|
||||
|
||||
click_button "Validate document"
|
||||
|
||||
expect(page).to have_content "Document verified with Census"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -236,4 +236,50 @@ describe Setting do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".force_presence_date_of_birth?" do
|
||||
|
||||
it "return false when feature remote_census is not active" do
|
||||
Setting["feature.remote_census"] = false
|
||||
|
||||
expect(Setting.force_presence_date_of_birth?).to eq false
|
||||
end
|
||||
|
||||
it "return false when feature remote_census is active and date_of_birth is nil" do
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.date_of_birth"] = nil
|
||||
|
||||
expect(Setting.force_presence_date_of_birth?).to eq false
|
||||
end
|
||||
|
||||
it "return true when feature remote_census is active and date_of_birth is empty" do
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.date_of_birth"] = "some.value"
|
||||
|
||||
expect(Setting.force_presence_date_of_birth?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
describe ".force_presence_postal_code?" do
|
||||
|
||||
it "return false when feature remote_census is not active" do
|
||||
Setting["feature.remote_census"] = false
|
||||
|
||||
expect(Setting.force_presence_postal_code?).to eq false
|
||||
end
|
||||
|
||||
it "return false when feature remote_census is active and postal_code is nil" do
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.postal_code"] = nil
|
||||
|
||||
expect(Setting.force_presence_postal_code?).to eq false
|
||||
end
|
||||
|
||||
it "return true when feature remote_census is active and postal_code is empty" do
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.postal_code"] = "some.value"
|
||||
|
||||
expect(Setting.force_presence_postal_code?).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user