messagerie: better format message dates

This commit is contained in:
Pierre de La Morinerie 2018-09-06 13:04:43 +00:00 committed by gregoirenovel
parent fe13871380
commit 211674435e
5 changed files with 57 additions and 1 deletions

View file

@ -18,4 +18,34 @@ RSpec.describe CommentaireHelper, type: :helper do
it { is_expected.to eq nil }
end
end
describe '.commentaire_date' do
let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) }
let(:creation_date) { present_date }
let(:commentaire) do
Timecop.freeze(creation_date) { create(:commentaire, email: "michel@pref.fr") }
end
subject do
Timecop.freeze(present_date) { commentaire_date(commentaire) }
end
it 'doesnt include the creation year' do
expect(subject).to eq 'le 2 septembre à 10 h 05'
end
context 'when displaying a commentaire created on a previous year' do
let(:creation_date) { present_date.prev_year }
it 'includes the creation year' do
expect(subject).to eq 'le 2 septembre 2017 à 10 h 05'
end
end
context 'when formatting the first day of the month' do
let(:present_date) { Time.local(2018, 9, 1, 10, 5, 0) }
it 'includes the ordinal' do
expect(subject).to eq 'le 1er septembre à 10 h 05'
end
end
end
end