Merge pull request #1402 from betagouv/fix-1296

Fix 1296 - Birthday field is optional in procedure
This commit is contained in:
Mathieu Magnin 2018-02-07 16:16:31 +01:00 committed by GitHub
commit 2a5963f59b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 31 deletions

View file

@ -254,7 +254,7 @@ class Admin::ProceduresController < AdminController
if @procedure.try(:locked?)
params.require(:procedure).permit(*editable_params)
else
params.require(:procedure).permit(*editable_params, :lien_demarche, :cerfa_flag, :for_individual, :individual_with_siret, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
params.require(:procedure).permit(*editable_params, :lien_demarche, :cerfa_flag, :for_individual, :individual_with_siret, :ask_birthday, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
end
end

View file

@ -220,6 +220,7 @@ class Users::DossiersController < UsersController
end
if update_params[:individual_attributes].present? &&
update_params[:individual_attributes][:birthdate] &&
!/^\d{4}\-\d{2}\-\d{2}$/.match(update_params[:individual_attributes][:birthdate]) &&
!/^\d{2}\/\d{2}\/\d{4}$/.match(update_params[:individual_attributes][:birthdate])
errors << "Le format de la date de naissance doit être JJ/MM/AAAA"

View file

@ -9,8 +9,4 @@ class UserDecorator < Draper::Decorator
'Mme'
end
end
def birthdate_fr
birthdate.strftime('%d/%m/%Y')
end
end

View file

@ -79,6 +79,11 @@
%label
= f.check_box :individual_with_siret
Donner la possibilité de renseigner un SIRET au cours de la construction du dossier.
%li
.checkbox
%label
= f.check_box :ask_birthday
Demander la date de naissance.
.row
.col-md-6
%h4 Options avancées

View file

@ -27,11 +27,13 @@
%h4
Prénom *
= ff.text_field :prenom, { class: 'form-control', required: true }
.form-group
%label
%h4
Date de naissance *
= ff.date_field :birthdate, { value: @facade.individual.birthdate, class: 'form-control', placeholder: 'jj/mm/aaaa', required: true }
- if @facade.procedure.ask_birthday?
.form-group
%label
%h4
Date de naissance *
= ff.date_field :birthdate, { value: @facade.individual.birthdate, class: 'form-control', placeholder: 'jj/mm/aaaa', required: true }
%p
%label{ style: 'font-weight: normal;' }

View file

@ -0,0 +1,5 @@
class AddAskBirthdayToProcedure < ActiveRecord::Migration[5.0]
def change
add_column :procedures, :ask_birthday, :boolean, default: false, null: false
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180201163642) do
ActiveRecord::Schema.define(version: 20180206153121) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -382,6 +382,7 @@ ActiveRecord::Schema.define(version: 20180201163642) do
t.datetime "hidden_at"
t.datetime "archived_at"
t.datetime "whitelisted_at"
t.boolean "ask_birthday", default: false, null: false
t.index ["hidden_at"], name: "index_procedures_on_hidden_at", using: :btree
end

View file

@ -7,7 +7,7 @@ feature 'As a User I wanna create a dossier' do
context 'Right after sign_in I shall see inscription by credentials/siret, I can create a new Dossier' do
let(:procedure_with_siret) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) }
let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) }
let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative, ask_birthday: ask_birthday) }
context 'Identification for individual' do
before do
@ -18,26 +18,44 @@ feature 'As a User I wanna create a dossier' do
find(:css, "#dossier_autorisation_donnees[value='1']").set(true)
end
scenario "with a proper date input field for birthdate (type='date' supported)" do
fill_in 'dossier_individual_attributes_birthdate', with: '1987-10-14'
page.find_by_id('etape_suivante').click
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
page.find_by_id('etape_suivante').click
fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1'
page.find_by_id('suivant').click
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14")
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s))
context "when birthday is asked" do
let(:ask_birthday) { true }
scenario "with a proper date input field for birthdate (type='date' supported)" do
fill_in 'dossier_individual_attributes_birthdate', with: '1987-10-14'
page.find_by_id('etape_suivante').click
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
page.find_by_id('etape_suivante').click
fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1'
page.find_by_id('suivant').click
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14")
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s))
end
scenario "with a basic text input field for birthdate (type='date' unsupported)" do
fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987'
page.find_by_id('etape_suivante').click
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
page.find_by_id('etape_suivante').click
fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1'
page.find_by_id('suivant').click
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14")
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s))
end
end
scenario "with a basic text input field for birthdate (type='date' unsupported)" do
fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987'
page.find_by_id('etape_suivante').click
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
page.find_by_id('etape_suivante').click
fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1'
page.find_by_id('suivant').click
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14")
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s))
context "when birthday is not asked" do
let(:ask_birthday) { false }
scenario "no need for birthday" do
page.find_by_id('etape_suivante').click
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
page.find_by_id('etape_suivante').click
fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1'
page.find_by_id('suivant').click
expect(user.dossiers.first.individual.birthdate).to eq(nil)
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s))
end
end
end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
feature 'As a User I want to sort and paginate dossiers', js: true do
let(:user) { create(:user) }
let(:procedure_for_individual) { create(:procedure, :published, :for_individual) }
let(:procedure_for_individual) { create(:procedure, :published, :for_individual, ask_birthday: true) }
before "Create dossier" do
login_as user, scope: :user