Skip to content

Commit

Permalink
perform time comparison in unix epoch for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Nov 28, 2024
1 parent c70546b commit e9f5c93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/services/reminders/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def after_perform(service_call)
def remind_at_changed?(reminder)
# For some reason reminder.remind_at_changed? returns false
# so we assume a change if remind_at is present in the params (would have passed contract validation)
params.key?(:remind_at) && reminder.remind_at == params[:remind_at]
params.key?(:remind_at) && reminder.remind_at.to_i == params[:remind_at].to_i
end

def destroy_scheduled_reminder_job(job_id)
Expand Down
18 changes: 11 additions & 7 deletions spec/services/reminders/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@
end

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

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 @@ -72,6 +71,7 @@
end

aggregate_failures "schedule new job" do
expect(model_instance.remind_at).to eq(call_attributes[:remind_at])
expect(Reminders::ScheduleReminderJob).to have_received(:schedule).with(model_instance)
end
end
Expand All @@ -85,15 +85,15 @@
end

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

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
expect(model_instance.remind_at).to eq(call_attributes[:remind_at])
expect(Reminders::ScheduleReminderJob).to have_received(:schedule).with(model_instance)
end
end
Expand All @@ -102,9 +102,13 @@
context "with remind_at attribute in non-utc timezone" do
let(:call_attributes) { { remind_at: 2.days.from_now.in_time_zone("Africa/Nairobi") } }

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

aggregate_failures "schedule new job" do
expect(model_instance.remind_at).to eq(call_attributes[:remind_at])
expect(Reminders::ScheduleReminderJob).to have_received(:schedule).with(model_instance)
end
end
end
end
Expand Down

0 comments on commit e9f5c93

Please sign in to comment.