OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Refactor reminder mail spec to a fixed date
Oliver Günthera6f0e7a0ae9a
diff --git a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rbindex abf0eb29e90..de146280e55 100644--- a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb+++ b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb@@ -35,10 +35,15 @@ describe User, '.having_reminder_mail_to_send', type: :model dodescribed_class.having_reminder_mail_to_send(scope_time)end- # As it is hard to mock PostgreSQL's "now()" method, in the specs here we need to adopt the slot time- # relative to the local time of the user that we want to hit.- let(:current_utc_time) { ActiveSupport::TimeZone['UTC'].parse("08:10:59") }- let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("08:00") }+ # Fix the time of the specs to ensure a consistent+ around do |example|+ Timecop.travel(current_time) do+ example.run+ end+ end++ let(:current_time) { "2021-09-30T08:10:59Z".to_datetime }+ let(:scope_time) { "2021-09-30T08:00:00Z".to_datetime }let(:paris_user) doFactoryBot.create(@@ -53,14 +58,13 @@ describe User, '.having_reminder_mail_to_send', type: :model dolet(:paris_user_daily_reminders) do{enabled: true,- times: [hitting_reminder_slot_for("Paris", current_utc_time)]+ times: [hitting_reminder_slot_for("Paris", current_time)]}endlet(:notifications) { FactoryBot.create(:notification, recipient: paris_user, created_at: 5.minutes.ago) }let(:users) { [paris_user] }before do- allow(Time).to receive(:current).and_return(current_utc_time)notificationsusersend@@ -73,8 +77,8 @@ describe User, '.having_reminder_mail_to_send', type: :model doendcontext 'for a user whose local time is not matching the configured time' do- let(:current_utc_time) { ActiveSupport::TimeZone['UTC'].parse("08:20:59") }- let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("08:15") }+ let(:current_time) { "2021-09-30T08:20:59Z".to_datetime }+ let(:scope_time) { "2021-09-30T08:15:00Z".to_datetime }it 'is empty' doexpect(scope)@@ -91,7 +95,7 @@ describe User, '.having_reminder_mail_to_send', type: :model dotime_zone: "Moscow",daily_reminders: {enabled: true,- times: [hitting_reminder_slot_for("Moscow", current_utc_time)]+ times: [hitting_reminder_slot_for("Moscow", current_time)]}})@@ -112,9 +116,9 @@ describe User, '.having_reminder_mail_to_send', type: :model do{enabled: true,times: [- hitting_reminder_slot_for("Paris", current_utc_time - 3.hours),- hitting_reminder_slot_for("Paris", current_utc_time),- hitting_reminder_slot_for("Paris", current_utc_time + 3.hours)+ hitting_reminder_slot_for("Paris", current_time - 3.hours),+ hitting_reminder_slot_for("Paris", current_time),+ hitting_reminder_slot_for("Paris", current_time + 3.hours)]}end@@ -130,8 +134,8 @@ describe User, '.having_reminder_mail_to_send', type: :model do{enabled: true,times: [- hitting_reminder_slot_for("Paris", current_utc_time - 2.hours),- hitting_reminder_slot_for("Paris", current_utc_time + 3.hours)+ hitting_reminder_slot_for("Paris", current_time - 2.hours),+ hitting_reminder_slot_for("Paris", current_time + 3.hours)]}end@@ -148,12 +152,12 @@ describe User, '.having_reminder_mail_to_send', type: :model do{enabled: true,times: [- hitting_reminder_slot_for("Paris", current_utc_time - 3.hours),- hitting_reminder_slot_for("Paris", current_utc_time + 1.hour)+ hitting_reminder_slot_for("Paris", current_time - 3.hours),+ hitting_reminder_slot_for("Paris", current_time + 1.hour)]}end- let(:scope_time) { current_utc_time - 2.hours }+ let(:scope_time) { current_time - 2.hours }it 'is empty' doexpect(scope)@@ -176,7 +180,7 @@ describe User, '.having_reminder_mail_to_send', type: :model dolet(:paris_user_daily_reminders) do{enabled: false,- times: [hitting_reminder_slot_for("Paris", current_utc_time)]+ times: [hitting_reminder_slot_for("Paris", current_time)]}end@@ -196,8 +200,8 @@ describe User, '.having_reminder_mail_to_send', type: :model do})end- let(:current_utc_time) { ActiveSupport::TimeZone['Paris'].parse("08:09").utc }- let(:scope_time) { ActiveSupport::TimeZone['Paris'].parse("08:00") }+ let(:current_time) { ActiveSupport::TimeZone['Paris'].parse("2021-09-30T08:09").utc }+ let(:scope_time) { ActiveSupport::TimeZone['Paris'].parse("2021-09-30T08:00") }it 'contains the user' doexpect(scope)@@ -215,8 +219,8 @@ describe User, '.having_reminder_mail_to_send', type: :model do})end- let(:current_utc_time) { ActiveSupport::TimeZone['Paris'].parse("10:00").utc }- let(:scope_time) { ActiveSupport::TimeZone['Paris'].parse("10:00") }+ let(:current_time) { ActiveSupport::TimeZone['Paris'].parse("2021-09-30T10:00").utc }+ let(:scope_time) { ActiveSupport::TimeZone['Paris'].parse("2021-09-30T10:00") }it 'is empty' doexpect(scope)@@ -233,13 +237,13 @@ describe User, '.having_reminder_mail_to_send', type: :model dotime_zone: "Kathmandu",daily_reminders: {enabled: true,- times: [hitting_reminder_slot_for("Asia/Kathmandu", current_utc_time)]+ times: [hitting_reminder_slot_for("Asia/Kathmandu", current_time)]}})end- let(:current_utc_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("08:10").utc }- let(:scope_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("08:00").utc }+ let(:current_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("2021-09-30T08:10").utc }+ let(:scope_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("2021-09-30T08:00").utc }let(:notifications) doFactoryBot.create(:notification, recipient: kathmandu_user, created_at: 5.minutes.ago)end@@ -261,13 +265,13 @@ describe User, '.having_reminder_mail_to_send', type: :model dotime_zone: "Kathmandu",daily_reminders: {enabled: true,- times: [hitting_reminder_slot_for("Asia/Kathmandu", current_utc_time)]+ times: [hitting_reminder_slot_for("Asia/Kathmandu", current_time)]}})end- let(:current_utc_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("08:40").utc }- let(:scope_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("08:30").utc }+ let(:current_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("2021-09-30T08:40").utc }+ let(:scope_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("2021-09-30T08:30").utc }let(:notifications) doFactoryBot.create(:notification, recipient: kathmandu_user, created_at: 5.minutes.ago)end@@ -289,13 +293,13 @@ describe User, '.having_reminder_mail_to_send', type: :model dotime_zone: "Kathmandu",daily_reminders: {enabled: true,- times: [hitting_reminder_slot_for("Asia/Kathmandu", current_utc_time)]+ times: [hitting_reminder_slot_for("Asia/Kathmandu", current_time)]}})end- let(:current_utc_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("07:55").utc }- let(:scope_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("07:45").utc }+ let(:current_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("2021-09-30T07:55").utc }+ let(:scope_time) { ActiveSupport::TimeZone['Asia/Kathmandu'].parse("2021-09-30T07:45").utc }let(:notifications) doFactoryBot.create(:notification, recipient: kathmandu_user, created_at: 5.minutes.ago)end@@ -349,7 +353,7 @@ describe User, '.having_reminder_mail_to_send', type: :model dolet(:paris_user_daily_reminders) do{enabled: true,- times: [hitting_reminder_slot_for("Paris", current_utc_time + 1.hour)]+ times: [hitting_reminder_slot_for("Paris", current_time + 1.hour)]}end@@ -363,7 +367,7 @@ describe User, '.having_reminder_mail_to_send', type: :model dolet(:paris_user_daily_reminders) do{enabled: true,- times: [hitting_reminder_slot_for("Paris", current_utc_time - 1.hour)]+ times: [hitting_reminder_slot_for("Paris", current_time - 1.hour)]}end@@ -381,7 +385,7 @@ describe User, '.having_reminder_mail_to_send', type: :model dopreferences: {daily_reminders: {enabled: true,- times: [hitting_reminder_slot_for("UTC", current_utc_time)]+ times: [hitting_reminder_slot_for("UTC", current_time)]}})@@ -401,7 +405,7 @@ describe User, '.having_reminder_mail_to_send', type: :model dopreferences: {})end- let(:current_utc_time) { ActiveSupport::TimeZone['UTC'].parse("08:00").utc }+ let(:current_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T08:00").utc }it 'is including the user as UTC at 08:00 is assumed' doexpect(scope)@@ -417,8 +421,8 @@ describe User, '.having_reminder_mail_to_send', type: :model dopreferences: {})end- let(:current_utc_time) { ActiveSupport::TimeZone['UTC'].parse("10:00").utc }- let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("10:00").utc }+ let(:current_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T10:00").utc }+ let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T10:00").utc }it 'is empty as UTC at 08:00 is assumed' doexpect(scope)@@ -436,8 +440,8 @@ describe User, '.having_reminder_mail_to_send', type: :model doendcontext 'for a user without preferences at 08:00' do- let(:current_utc_time) { ActiveSupport::TimeZone['UTC'].parse("08:00").utc }- let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("08:00").utc }+ let(:current_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T08:00").utc }+ let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T08:00").utc }before doparis_user.pref.destroy@@ -450,8 +454,8 @@ describe User, '.having_reminder_mail_to_send', type: :model doendcontext 'for a user without preferences at 10:00' do- let(:current_utc_time) { ActiveSupport::TimeZone['UTC'].parse("10:00").utc }- let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("10:00").utc }+ let(:current_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T10:00").utc }+ let(:scope_time) { ActiveSupport::TimeZone['UTC'].parse("2021-09-30T10:00").utc }before doparis_user.pref.destroy