Skip to content

Commit

Permalink
Remove timetravel in tests
Browse files Browse the repository at this point in the history
Due to the changes in the gem upgrade the time travel blocks do not work for out purpose in these tests. I believe this is because the noticed event is created inside the time travel block, but that creates noticed notifications in the background outside of the time travel block, so i have stubbed the created_at on the notifications to recreate these tests as best I can.
  • Loading branch information
KyleMacPherson committed Jun 18, 2024
1 parent 63d7645 commit 1ce6939
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@

context "when the notification was delivered yesterday" do
before do
travel_to 1.day.ago do
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
end
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
allow_any_instance_of(Noticed::Notification).to receive(:created_at) { Time.current - 1.day }
end

it "returns the correct timestamp" do
Expand All @@ -55,11 +54,10 @@

context "when the notification was delivered before yesterday" do
before do
travel_to DateTime.new(2000, 0o1, 0o1, 14, 30) do
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
end
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
allow_any_instance_of(Noticed::Notification).to receive(:created_at) { DateTime.new(2000, 0o1, 0o1, 14, 30) }
end

it "returns the correct timestamp" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
let(:job_application) { create(:job_application, :status_submitted, vacancy: vacancy) }

describe "#timestamp" do
subject { Noticed::Notification.last.timestamp }

context "when the notification is delivered today" do
before do
described_class
Expand All @@ -15,35 +13,33 @@
end

it "returns the correct timestamp" do
expect(subject).to match(/Today at/)
expect(Noticed::Notification.last.timestamp).to match(/Today at/)
end
end

context "when the notification was delivered yesterday" do
before do
travel_to 1.day.ago do
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(vacancy.publisher)
end
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(vacancy.publisher)
allow_any_instance_of(Noticed::Notification).to receive(:created_at) { Time.current - 1.day }
end

it "returns the correct timestamp" do
expect(subject).to match(/Yesterday at/)
expect(Noticed::Notification.last.timestamp).to match(/Yesterday at/)
end
end

context "when the notification was delivered before yesterday" do
before do
travel_to DateTime.new(2000, 0o1, 0o1, 14, 30) do
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(vacancy.publisher)
end
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(vacancy.publisher)
allow_any_instance_of(Noticed::Notification).to receive(:created_at) { DateTime.new(2000, 0o1, 0o1, 14, 30) }
end

it "returns the correct timestamp" do
expect(subject).to eq("1 January at 2:30pm")
expect(Noticed::Notification.last.timestamp).to eq("1 January at 2:30pm")
end
end
end
Expand Down

0 comments on commit 1ce6939

Please sign in to comment.