Skip to content

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.rb
index 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.rb
index 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?
end
end
diff --git a/app/services/upcoming_changes/notify_promotion.rb b/app/services/upcoming_changes/notify_promotion.rb
index 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::NotifyPromotion
policy :meets_or_exceeds_status
policy :change_has_not_already_been_notified_about_promotion
policy :admin_has_not_manually_toggled
- policy :site_is_not_new
+ policy :should_notify_admins
try do
step :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?
end
def log_promotion(params:, guardian:)
diff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rb
index 9189bfa5ebd..f684280b31d 100644
--- a/lib/upcoming_changes.rb
+++ b/lib/upcoming_changes.rb
@@ -333,4 +333,13 @@ module UpcomingChanges
)&.upcoming_changes
end
end
+
+ # 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?
+ end
end
diff --git a/spec/jobs/scheduled/check_upcoming_changes_spec.rb b/spec/jobs/scheduled/check_upcoming_changes_spec.rb
index 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 do
fab!(:admin)
before do
+ # No upcoming change notifications are sent for new sites
+ UpcomingChanges.stubs(:should_notify_admins?).returns(true)
SiteSetting.upcoming_change_verbose_logging = true
SiteSetting.promote_upcoming_changes_on_status = :stable
end
diff --git a/spec/services/upcoming_changes/action/track_notify_added_changes_spec.rb b/spec/services/upcoming_changes/action/track_notify_added_changes_spec.rb
index 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 do
before 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 do
end
context "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" do
expect { 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.rb
index 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 do
before 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 do
end
context "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" do
expect { result }.not_to change {
diff --git a/spec/services/upcoming_changes/notify_promotion_spec.rb b/spec/services/upcoming_changes/notify_promotion_spec.rb
index 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 do
before 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 = :stable
mock_upcoming_change_metadata(
enable_upload_debug_mode: {
@@ -77,9 +77,9 @@ RSpec.describe UpcomingChanges::NotifyPromotion do
end
context "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) }
end
context "when everything's ok" do
diff --git a/spec/services/upcoming_changes/notify_promotions_spec.rb b/spec/services/upcoming_changes/notify_promotions_spec.rb
index 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 do
let(: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 = :stable
SiteSetting.stubs(:upcoming_change_site_settings).returns(
%i[enable_upload_debug_mode show_user_menu_avatars],