Individual: use birthdate as a ... date :)

This commit is contained in:
simon lehericey 2018-04-03 16:38:54 +02:00
parent b67b13aac8
commit c019cb623a
8 changed files with 16 additions and 32 deletions

View file

@ -3,6 +3,6 @@ FactoryBot.define do
gender 'M.'
nom 'Julien'
prenom 'Xavier'
birthdate '1991-11-01'
birthdate Date.new(1991, 11, 01)
end
end

View file

@ -30,7 +30,7 @@ feature 'As a User I wanna create a dossier' do
expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last))
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14")
expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
end
scenario "with a basic text input field for birthdate (type='date' unsupported)" do
@ -42,7 +42,7 @@ feature 'As a User I wanna create a dossier' do
expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last))
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14")
expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
end
end

View file

@ -4,7 +4,6 @@ describe Individual do
it { is_expected.to have_db_column(:gender) }
it { is_expected.to have_db_column(:nom) }
it { is_expected.to have_db_column(:prenom) }
it { is_expected.to have_db_column(:birthdate) }
it { is_expected.to belong_to(:dossier) }
describe "#save" do
@ -21,24 +20,21 @@ describe Individual do
context "and the format is dd/mm/yyy " do
let(:birthdate_from_user) { "12/11/1980" }
it { expect(individual.valid?).to be true }
it { expect(individual.birthdate).to eq("1980-11-12") }
it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) }
end
context "and the format is ISO" do
let(:birthdate_from_user) { "1980-11-12" }
it { expect(individual.valid?).to be true }
it { expect(individual.birthdate).to eq("1980-11-12") }
it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) }
end
context "and the format is WTF" do
let(:birthdate_from_user) { "1980 1 12" }
it { expect(individual.valid?).to be false }
it { expect(individual.birthdate).to eq("1980 1 12") }
it { expect(individual.birthdate).to be_nil }
it { expect(individual.second_birthdate).to be_nil }
end
end

View file

@ -34,6 +34,6 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
it { expect(rendered).to include(individual.gender) }
it { expect(rendered).to include(individual.nom) }
it { expect(rendered).to include(individual.prenom) }
it { expect(rendered).to include(Date.parse(individual.birthdate).strftime("%d/%m/%Y")) }
it { expect(rendered).to include(individual.birthdate.strftime("%d/%m/%Y")) }
end
end