diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-09-21 03:46:41 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-09-21 03:47:06 +0300 |
commit | 03796e8fe2421ddfbc5380b8194ee68afbe3b88b (patch) | |
tree | 4c3cd795f80c6939eff4a181bb0c673c6ba651b0 | |
parent | 57cdc288e26c612db9626d43dcdd05075fbc8423 (diff) | |
parent | c47258a873f26743ee9dfc099f3a7605caf4cfb7 (diff) |
Merge pull request #8395 from denschub/time-travel
Fixes for two date-related spec breakages
-rw-r--r-- | spec/workers/check_birthday_spec.rb | 15 | ||||
-rw-r--r-- | spec/workers/queue_users_for_removal_spec.rb | 4 |
2 files changed, 8 insertions, 11 deletions
diff --git a/spec/workers/check_birthday_spec.rb b/spec/workers/check_birthday_spec.rb index 1f026ab61..7f8573b79 100644 --- a/spec/workers/check_birthday_spec.rb +++ b/spec/workers/check_birthday_spec.rb @@ -6,15 +6,10 @@ describe Workers::CheckBirthday do let(:contact2) { eve.contact_for(bob.person) } before do - Timecop.freeze(Time.zone.local(1999, 9, 9)) - birthday_profile.update(birthday: "1990-09-09") + birthday_profile.update(birthday: Time.zone.now) allow(Notifications::ContactsBirthday).to receive(:notify) end - after do - Timecop.return - end - it "calls notify method for the birthday person's contacts" do Workers::CheckBirthday.new.perform expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, []) @@ -24,13 +19,15 @@ describe Workers::CheckBirthday do it "does nothing if the birthday does not exist" do birthday_profile.update(birthday: nil) Workers::CheckBirthday.new.perform - expect(Notifications::ContactsBirthday).not_to have_received(:notify) + expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact1, []) + expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, []) end it "does nothing if the person's birthday is not today" do - birthday_profile.update(birthday: "1988-04-15") + birthday_profile.update(birthday: Time.zone.now - 1.day) Workers::CheckBirthday.new.perform - expect(Notifications::ContactsBirthday).not_to have_received(:notify) + expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact1, []) + expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, []) end it "does not call notify method if a person is not a contact of the birthday person" do diff --git a/spec/workers/queue_users_for_removal_spec.rb b/spec/workers/queue_users_for_removal_spec.rb index 8b9707104..2ddc4262b 100644 --- a/spec/workers/queue_users_for_removal_spec.rb +++ b/spec/workers/queue_users_for_removal_spec.rb @@ -22,7 +22,7 @@ describe Workers::QueueUsersForRemoval do user = FactoryBot.create(:user, last_seen: Time.zone.now - 732.days, sign_in_count: 5) Workers::QueueUsersForRemoval.new.perform user.reload - expect(user.remove_after.to_i).to eq(removal_date.utc.to_i) + expect(user.remove_after.to_i).to be_within(1.day).of(removal_date.utc.to_i) expect(ActionMailer::Base.deliveries.count).to eq(1) end @@ -31,7 +31,7 @@ describe Workers::QueueUsersForRemoval do user = FactoryBot.create(:user, last_seen: Time.zone.now - 735.days, sign_in_count: 0) Workers::QueueUsersForRemoval.new.perform user.reload - expect(user.remove_after.to_i).to eq(removal_date.utc.to_i) + expect(user.remove_after.to_i).to be_within(1.day).of(removal_date.utc.to_i) expect(ActionMailer::Base.deliveries.count).to eq(0) # no email sent end |