diff --git a/spec/services/reminders/set_attributes_service_spec.rb b/spec/services/reminders/set_attributes_service_spec.rb index 5804ee862d4..b550d9679d7 100644 --- a/spec/services/reminders/set_attributes_service_spec.rb +++ b/spec/services/reminders/set_attributes_service_spec.rb @@ -31,6 +31,7 @@ require "spec_helper" RSpec.describe Reminders::SetAttributesService do + let(:business_day_at_noon) { Time.zone.local(2025, 1, 8, 12, 0, 0) } let(:user) { build_stubbed(:user) } let(:model_instance) { Reminder.new } let(:remindable) { build_stubbed(:work_package) } @@ -44,6 +45,14 @@ RSpec.describe Reminders::SetAttributesService do contract_class:) end + before do + travel_to(business_day_at_noon) + end + + after do + travel_back + end + describe "building remind_at timestamp" do it "sets the remind_at attribute from date and time params" do params = { diff --git a/spec/services/reminders/update_service_spec.rb b/spec/services/reminders/update_service_spec.rb index acd00a363d2..5de4c90e384 100644 --- a/spec/services/reminders/update_service_spec.rb +++ b/spec/services/reminders/update_service_spec.rb @@ -39,18 +39,24 @@ RSpec.describe Reminders::UpdateService do describe "remind_at changed" do subject { described_class.new(user:, model: model_instance).call(call_attributes) } + let(:business_day_at_noon) { Time.zone.local(2025, 1, 8, 12, 0, 0) } let(:model_instance) { create(:reminder, :scheduled, :with_unread_notifications, creator: user) } let(:user) { create(:admin) } - let(:remind_at) { 2.days.from_now.change(hour: 12, min: 0) } + let(:remind_at) { business_day_at_noon + 2.days } let(:call_attributes) { { remind_at_date: remind_at.to_date, remind_at_time: remind_at.strftime("%H:%M") } } before do - model_instance.update(job_id: 1) + travel_to(business_day_at_noon) + model_instance.update!(job_id: 1) allow(Reminders::ScheduleReminderJob).to receive(:schedule) .with(model_instance) .and_return(instance_double(Reminders::ScheduleReminderJob, job_id: 2)) end + after do + travel_back + end + context "with an existing unfinished scheduled job" do let(:job) { instance_double(GoodJob::Job, finished?: false, destroy: true) } @@ -101,7 +107,7 @@ RSpec.describe Reminders::UpdateService do end context "with remind_at attribute in non-utc timezone" do - let(:call_attributes) { { remind_at: 2.days.from_now.in_time_zone("Africa/Nairobi") } } + let(:call_attributes) { { remind_at: remind_at.in_time_zone("Africa/Nairobi") } } it "reschedules the reminder" do expect { subject }.to change(model_instance, :job_id).from("1").to("2")