Make the birthday field a date field
And remove the date picker (you can now use the native one)
This commit is contained in:
parent
8126549a0d
commit
6cb78acd85
3 changed files with 51 additions and 15 deletions
|
@ -122,7 +122,7 @@ class Users::DossiersController < UsersController
|
||||||
@facade = facade params[:dossier][:id]
|
@facade = facade params[:dossier][:id]
|
||||||
|
|
||||||
if checked_autorisation_donnees?
|
if checked_autorisation_donnees?
|
||||||
unless Dossier.find(@facade.dossier.id).update_attributes update_params
|
unless Dossier.find(@facade.dossier.id).update_attributes update_params_with_formatted_birthdate
|
||||||
flash.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
flash.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
||||||
|
|
||||||
return redirect_to users_dossier_path(id: @facade.dossier.id)
|
return redirect_to users_dossier_path(id: @facade.dossier.id)
|
||||||
|
@ -171,6 +171,25 @@ class Users::DossiersController < UsersController
|
||||||
params.require(:dossier).permit(:id, :autorisation_donnees, individual_attributes: [:gender, :nom, :prenom, :birthdate])
|
params.require(:dossier).permit(:id, :autorisation_donnees, individual_attributes: [:gender, :nom, :prenom, :birthdate])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_params_with_formatted_birthdate
|
||||||
|
editable_params = update_params
|
||||||
|
|
||||||
|
# If the user was shown a date input field (if its browser supports it),
|
||||||
|
# the returned param will follow the YYYY-MM-DD pattern, which we need
|
||||||
|
# do convert to the DD/MM/YYYY pattern we use
|
||||||
|
if editable_params &&
|
||||||
|
editable_params[:individual_attributes] &&
|
||||||
|
editable_params[:individual_attributes][:birthdate] &&
|
||||||
|
editable_params[:individual_attributes][:birthdate] =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
|
||||||
|
|
||||||
|
original_birthdate = editable_params[:individual_attributes][:birthdate]
|
||||||
|
formatted_birthdate = I18n.l(original_birthdate.to_date, format: '%d/%m/%Y')
|
||||||
|
editable_params[:individual_attributes][:birthdate] = formatted_birthdate
|
||||||
|
end
|
||||||
|
|
||||||
|
editable_params
|
||||||
|
end
|
||||||
|
|
||||||
def checked_autorisation_donnees?
|
def checked_autorisation_donnees?
|
||||||
update_params[:autorisation_donnees] == '1'
|
update_params[:autorisation_donnees] == '1'
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
%label
|
%label
|
||||||
%h4
|
%h4
|
||||||
Date de naissance *
|
Date de naissance *
|
||||||
= ff.text_field :birthdate, {class: 'form-control', 'data-provide' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy'}
|
= ff.date_field :birthdate, {class: 'form-control', placeholder: 'jj/mm/aaaa'}
|
||||||
|
|
||||||
%p
|
%p
|
||||||
%label{ style:'font-weight:normal' }
|
%label{ style:'font-weight:normal' }
|
||||||
|
|
|
@ -9,19 +9,36 @@ feature 'As a User I wanna create a dossier' do
|
||||||
let(:procedure_with_siret) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) }
|
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) }
|
||||||
|
|
||||||
scenario 'Identification for individual' do
|
context 'Identification for individual' do
|
||||||
login_as user, scope: :user
|
before do
|
||||||
visit commencer_path(procedure_path: procedure_for_individual.path)
|
login_as user, scope: :user
|
||||||
fill_in 'dossier_individual_attributes_nom', with: 'Nom'
|
visit commencer_path(procedure_path: procedure_for_individual.path)
|
||||||
fill_in 'dossier_individual_attributes_prenom', with: 'Prenom'
|
fill_in 'dossier_individual_attributes_nom', with: 'Nom'
|
||||||
fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987'
|
fill_in 'dossier_individual_attributes_prenom', with: 'Prenom'
|
||||||
find(:css, "#dossier_autorisation_donnees[value='1']").set(true)
|
find(:css, "#dossier_autorisation_donnees[value='1']").set(true)
|
||||||
page.find_by_id('etape_suivante').click
|
end
|
||||||
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s), only_path: true)
|
|
||||||
page.find_by_id('etape_suivante').click
|
scenario "with a proper date input field for birthdate (type='date' supported)" do
|
||||||
fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1'
|
fill_in 'dossier_individual_attributes_birthdate', with: '1987-10-14'
|
||||||
page.find_by_id('suivant').click
|
page.find_by_id('etape_suivante').click
|
||||||
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s), only_path: true)
|
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s), only_path: true)
|
||||||
|
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("14/10/1987")
|
||||||
|
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s), only_path: true)
|
||||||
|
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), only_path: true)
|
||||||
|
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("14/10/1987")
|
||||||
|
expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s), only_path: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Identification through siret', vcr: {cassette_name: 'search_ban_paris'}, js: true do
|
scenario 'Identification through siret', vcr: {cassette_name: 'search_ban_paris'}, js: true do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue