Skip to content

Commit

Permalink
Reset model job id in before hook to reliably check for state change
Browse files Browse the repository at this point in the history
Failing in CI - perhaps when ran in global context
  • Loading branch information
akabiru committed Nov 28, 2024
1 parent 64cecd3 commit 8053cb6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions spec/services/reminders/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
describe "remind_at changed" do
subject { described_class.new(user:, model: model_instance).call(call_attributes) }

let(:model_instance) { create(:reminder, :scheduled, :with_unread_notifications, creator: user, job_id: 1) }
let(:model_instance) { create(:reminder, :scheduled, :with_unread_notifications, creator: user) }
let(:user) { create(:admin) }
let(:call_attributes) { { remind_at: 2.days.from_now } }

before do
model_instance.update(job_id: 1)
allow(Reminders::ScheduleReminderJob).to receive(:schedule)
.with(model_instance)
.and_return(instance_double(Reminders::ScheduleReminderJob, job_id: 2))
Expand All @@ -57,11 +58,12 @@
end

it "reschedules the reminder" do
expect { subject }.to change(model_instance.reload, :job_id).from("1").to("2")
subject

aggregate_failures "destroy existing job" do
expect(GoodJob::Job).to have_received(:find_by).with(id: "1")
expect(job).to have_received(:destroy)
expect(model_instance.reload.job_id).to eq("2")
end

aggregate_failures "marks unread notifications as read" do
Expand All @@ -83,11 +85,12 @@
end

it "schedules a new job" do
expect { subject }.to change(model_instance.reload, :job_id).from("1").to("2")
subject

aggregate_failures "does NOT destroy existing job" do
expect(GoodJob::Job).to have_received(:find_by).with(id: "1")
expect(job).not_to have_received(:destroy)
expect(model_instance.reload.job_id).to eq("2")
end

aggregate_failures "schedule new job" do
Expand All @@ -100,7 +103,8 @@
let(:call_attributes) { { remind_at: 2.days.from_now.in_time_zone("Africa/Nairobi") } }

it "schedules the reminder" do
expect { subject }.to change(model_instance.reload, :job_id).from("1").to("2")
subject
expect(model_instance.reload.job_id).to eq("2")
end
end
end
Expand Down

0 comments on commit 8053cb6

Please sign in to comment.