refactor(gallery test): use freeze_time instead of Timecop
This commit is contained in:
parent
72ae654ce7
commit
3397beb71d
1 changed files with 5 additions and 6 deletions
|
@ -10,14 +10,12 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||||
let(:filename) { attachment.blob.filename.to_s }
|
let(:filename) { attachment.blob.filename.to_s }
|
||||||
let(:gallery_demande) { false }
|
let(:gallery_demande) { false }
|
||||||
let(:seen_at) { nil }
|
let(:seen_at) { nil }
|
||||||
let(:now) { Time.zone.parse('01/01/2010') }
|
let(:now) { Time.zone.now }
|
||||||
|
|
||||||
let(:component) { described_class.new(attachment: attachment, gallery_demande:, seen_at: seen_at) }
|
let(:component) { described_class.new(attachment: attachment, gallery_demande:, seen_at: seen_at) }
|
||||||
|
|
||||||
subject { render_inline(component).to_html }
|
subject { render_inline(component).to_html }
|
||||||
|
|
||||||
after { Timecop.return }
|
|
||||||
|
|
||||||
context "when attachment is from a piece justificative champ" do
|
context "when attachment is from a piece justificative champ" do
|
||||||
let(:champ) { dossier.champs.first }
|
let(:champ) { dossier.champs.first }
|
||||||
let(:libelle) { champ.libelle }
|
let(:libelle) { champ.libelle }
|
||||||
|
@ -71,10 +69,10 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when instructeur has not seen it yet" do
|
context "when instructeur has not seen it yet" do
|
||||||
let(:seen_at) { Timecop.freeze(now - 1.day) }
|
let(:seen_at) { now - 1.day }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
attachment.blob.update(created_at: Timecop.freeze(now))
|
attachment.blob.update(created_at: now)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'displays datetime in the right style' do
|
it 'displays datetime in the right style' do
|
||||||
|
@ -83,9 +81,10 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when instructeur has already seen it" do
|
context "when instructeur has already seen it" do
|
||||||
let!(:seen_at) { Timecop.freeze(now) }
|
let!(:seen_at) { now }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
freeze_time
|
||||||
attachment.blob.touch(:created_at)
|
attachment.blob.touch(:created_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue