[Fix #1309] Datetime value should be print with yyyy-mm-dd format

This commit is contained in:
Mathieu Magnin 2018-01-19 11:50:34 +01:00 committed by Paul Chavard
parent fdd6cedeb8
commit dcb38d79a3
5 changed files with 38 additions and 6 deletions

View file

@ -24,7 +24,7 @@ class ChampDecorator < Draper::Decorator
if type_champ == "date"
object.value
elsif type_champ == "datetime" && object.value != ' 00:00'
DateTime.parse(object.value, "%d/%m/%Y %H:%M").strftime("%d/%m/%Y")
DateTime.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
end
end
end

View file

@ -249,7 +249,7 @@ shared_examples 'description_controller_spec' do
describe 'Sauvegarde des champs' do
let(:champs_dossier) { dossier.champs }
let(:dossier_text_value) { 'test value' }
let(:dossier_date_value) { '23/06/2016' }
let(:dossier_date_value) { '2018-01-31' }
let(:dossier_hour_value) { '17' }
let(:dossier_minute_value) { '00' }
let(:dossier_datetime_champ_id) { dossier.champs.find { |c| c.type_champ == "datetime" }.id }

View file

@ -61,4 +61,36 @@ describe ChampDecorator do
end
end
end
describe '#date_for_input' do
subject { decorator.date_for_input }
describe "for a date" do
let(:type_champ) { :date }
context "when value is an ISO date" do
before { champ.update value: "2017-12-31" }
it { is_expected.to eq "2017-12-31" }
end
context "when value is empty" do
before { champ.update value: nil }
it { is_expected.to eq nil }
end
end
describe "for a datetime" do
let(:type_champ) { :date }
context "when value is an formatted datetime" do
before { champ.update value: "2017-12-30 23:17" }
it { is_expected.to eq "2017-12-30" }
end
context "when value is empty" do
before { champ.update value: nil }
it { is_expected.to eq nil }
end
end
end
end

View file

@ -179,10 +179,10 @@ describe TagsSubstitutionConcern, type: :model do
dossier.champs
.select { |champ| champ.type_champ == 'datetime' }
.first
.update_attributes(value: '13/09/2017 09:00')
.update_attributes(value: '2017-09-13 09:00')
end
it { is_expected.to eq('15/04/2017 13/09/2017 09:00') }
it { is_expected.to eq('15/04/2017 2017-09-13 09:00') }
end
end
end

View file

@ -66,7 +66,7 @@ describe 'users/description/show.html.haml', type: :view do
let(:champ_datetime) { champs.where(type_de_champ_id: types_de_champ.id).first }
before do
champ_datetime.value = "22/06/2016 12:05"
champ_datetime.value = "2016-06-22 12:05"
champ_datetime.save
render
end
@ -82,7 +82,7 @@ describe 'users/description/show.html.haml', type: :view do
end
describe 'datetime value is correctly setup when is not nil' do
it { expect(rendered).to have_css("input[type='date'][id='champs_#{champ_datetime.id}'][value='22/06/2016']") }
it { expect(rendered).to have_css("input[type='date'][id='champs_#{champ_datetime.id}'][value='2016-06-22']") }
it { expect(rendered).to have_css("option[value='12'][selected='selected']") }
it { expect(rendered).to have_css("option[value='05'][selected='selected']") }
end