A platform for community discussion. Free, open, simple.
DEV: Fix upcoming change notification flaky specs (#38914)
Martin Brennan8e344695c931
diff --git a/app/services/upcoming_changes/action/track_notify_added_changes.rb b/app/services/upcoming_changes/action/track_notify_added_changes.rbindex 07e10b4de36..d34796b43c1 100644--- a/app/services/upcoming_changes/action/track_notify_added_changes.rb+++ b/app/services/upcoming_changes/action/track_notify_added_changes.rb@@ -21,7 +21,7 @@ class UpcomingChanges::Action::TrackNotifyAddedChanges < Service::ActionBase# No point in notifying admins on brand new sites, the upcoming change system# is more about notifying admins of changes to established sites.- next if Migration::Helpers.new_site? && !Rails.env.development?+ next if !UpcomingChanges.should_notify_admins?# We only want to notify admins once the change has reached a certain status,# which is the promotion status minus one (previous status).diff --git a/app/services/upcoming_changes/action/track_notify_status_changes.rb b/app/services/upcoming_changes/action/track_notify_status_changes.rbindex b8461f78adf..c2b9295a21c 100644--- a/app/services/upcoming_changes/action/track_notify_status_changes.rb+++ b/app/services/upcoming_changes/action/track_notify_status_changes.rb@@ -118,6 +118,6 @@ class UpcomingChanges::Action::TrackNotifyStatusChanges < Service::ActionBase!UpcomingChangeEvent.exists?(upcoming_change_name: change_name,event_type: :admins_notified_available_change,- ) && (!Migration::Helpers.new_site? && !Rails.env.development?)+ ) && UpcomingChanges.should_notify_admins?endenddiff --git a/app/services/upcoming_changes/notify_promotion.rb b/app/services/upcoming_changes/notify_promotion.rbindex 86eb258fa7e..1800666b6c6 100644--- a/app/services/upcoming_changes/notify_promotion.rb+++ b/app/services/upcoming_changes/notify_promotion.rb@@ -29,7 +29,7 @@ class UpcomingChanges::NotifyPromotionpolicy :meets_or_exceeds_statuspolicy :change_has_not_already_been_notified_about_promotionpolicy :admin_has_not_manually_toggled- policy :site_is_not_new+ policy :should_notify_adminstry dostep :log_promotion@@ -61,8 +61,8 @@ class UpcomingChanges::NotifyPromotion!SiteSetting.modified.key?(params.setting_name)end- def site_is_not_new(params:)- !Migration::Helpers.new_site? && !Rails.env.development?+ def should_notify_admins(params:)+ UpcomingChanges.should_notify_admins?enddef log_promotion(params:, guardian:)diff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rbindex 9189bfa5ebd..f684280b31d 100644--- a/lib/upcoming_changes.rb+++ b/lib/upcoming_changes.rb@@ -333,4 +333,13 @@ module UpcomingChanges)&.upcoming_changesendend++ # No point in notifying admins on brand new sites, the upcoming change system+ # is more about notifying admins of changes to established sites.+ #+ # Of course we don't care about this in development, we need to test notifications,+ # and we can stub this method in rspec.+ def self.should_notify_admins?+ Migration::Helpers.existing_site? || Rails.env.development?+ endenddiff --git a/spec/jobs/scheduled/check_upcoming_changes_spec.rb b/spec/jobs/scheduled/check_upcoming_changes_spec.rbindex ade145dd4ae..da6dd6867ba 100644--- a/spec/jobs/scheduled/check_upcoming_changes_spec.rb+++ b/spec/jobs/scheduled/check_upcoming_changes_spec.rb@@ -5,6 +5,8 @@ RSpec.describe Jobs::CheckUpcomingChanges dofab!(:admin)before do+ # No upcoming change notifications are sent for new sites+ UpcomingChanges.stubs(:should_notify_admins?).returns(true)SiteSetting.upcoming_change_verbose_logging = trueSiteSetting.promote_upcoming_changes_on_status = :stableenddiff --git a/spec/services/upcoming_changes/action/track_notify_added_changes_spec.rb b/spec/services/upcoming_changes/action/track_notify_added_changes_spec.rbindex 0d8962ccae4..6410b6355a8 100644--- a/spec/services/upcoming_changes/action/track_notify_added_changes_spec.rb+++ b/spec/services/upcoming_changes/action/track_notify_added_changes_spec.rb@@ -6,7 +6,7 @@ RSpec.describe UpcomingChanges::Action::TrackNotifyAddedChanges dobefore do# No upcoming change notifications are sent for new sites- Migration::Helpers.stubs(:new_site?).returns(false)+ UpcomingChanges.stubs(:should_notify_admins?).returns(true)mock_upcoming_change_metadata({enable_upload_debug_mode: {@@ -107,7 +107,7 @@ RSpec.describe UpcomingChanges::Action::TrackNotifyAddedChanges doendcontext "when the site is new (< 1 hour old)" do- before { Migration::Helpers.stubs(:new_site?).returns(true) }+ before { UpcomingChanges.stubs(:should_notify_admins?).returns(false) }it "does not notify admins that a change is available" doexpect { result }.not_to change { Notification.count }diff --git a/spec/services/upcoming_changes/action/track_notify_status_changes_spec.rb b/spec/services/upcoming_changes/action/track_notify_status_changes_spec.rbindex 776f5a5516a..69af03c04f5 100644--- a/spec/services/upcoming_changes/action/track_notify_status_changes_spec.rb+++ b/spec/services/upcoming_changes/action/track_notify_status_changes_spec.rb@@ -6,7 +6,7 @@ RSpec.describe UpcomingChanges::Action::TrackNotifyStatusChanges dobefore do# No upcoming change notifications are sent for new sites- Migration::Helpers.stubs(:new_site?).returns(false)+ UpcomingChanges.stubs(:should_notify_admins?).returns(true)mock_upcoming_change_metadata({enable_upload_debug_mode: {@@ -295,7 +295,7 @@ RSpec.describe UpcomingChanges::Action::TrackNotifyStatusChanges doendcontext "when the site is new (< 1 hour old)" do- before { Migration::Helpers.stubs(:new_site?).returns(true) }+ before { UpcomingChanges.stubs(:should_notify_admins?).returns(false) }it "does not notify admins" doexpect { result }.not_to change {diff --git a/spec/services/upcoming_changes/notify_promotion_spec.rb b/spec/services/upcoming_changes/notify_promotion_spec.rbindex a906f18790f..a8b07a56887 100644--- a/spec/services/upcoming_changes/notify_promotion_spec.rb+++ b/spec/services/upcoming_changes/notify_promotion_spec.rb@@ -28,7 +28,7 @@ RSpec.describe UpcomingChanges::NotifyPromotion dobefore do# No upcoming change notifications are sent for new sites- Migration::Helpers.stubs(:new_site?).returns(false)+ UpcomingChanges.stubs(:should_notify_admins?).returns(true)SiteSetting.promote_upcoming_changes_on_status = :stablemock_upcoming_change_metadata(enable_upload_debug_mode: {@@ -77,9 +77,9 @@ RSpec.describe UpcomingChanges::NotifyPromotion doendcontext "when the site is new (< 1 hour old)" do- before { Migration::Helpers.stubs(:new_site?).returns(true) }+ before { UpcomingChanges.stubs(:should_notify_admins?).returns(false) }- it { is_expected.to fail_a_policy(:site_is_not_new) }+ it { is_expected.to fail_a_policy(:should_notify_admins) }endcontext "when everything's ok" dodiff --git a/spec/services/upcoming_changes/notify_promotions_spec.rb b/spec/services/upcoming_changes/notify_promotions_spec.rbindex 4466f55ac32..8cec5a67c62 100644--- a/spec/services/upcoming_changes/notify_promotions_spec.rb+++ b/spec/services/upcoming_changes/notify_promotions_spec.rb@@ -11,6 +11,8 @@ RSpec.describe UpcomingChanges::NotifyPromotions dolet(:show_user_menu_avatars_status) { :beta }before do+ # No upcoming change notifications are sent for new sites+ UpcomingChanges.stubs(:should_notify_admins?).returns(true)SiteSetting.promote_upcoming_changes_on_status = :stableSiteSetting.stubs(:upcoming_change_site_settings).returns(%i[enable_upload_debug_mode show_user_menu_avatars],