Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix spec cleanup issues for upcoming changes (#39024)

Martin Brennandd0da69c158f
diff --git a/spec/jobs/check_new_features_spec.rb b/spec/jobs/check_new_features_spec.rb
index aec7b373873..092ca4a02ab 100644
--- a/spec/jobs/check_new_features_spec.rb
+++ b/spec/jobs/check_new_features_spec.rb
@@ -96,8 +96,6 @@ RSpec.describe Jobs::CheckNewFeatures do
stub_new_features_endpoint(feature1)
end
- after { clear_mocked_upcoming_change_metadata }
-
it "notifies admins and bumps last_viewed_feature_date from the status_changed time" do
Notification.destroy_all
@@ -171,8 +169,6 @@ RSpec.describe Jobs::CheckNewFeatures do
stub_new_features_endpoint(feature_stale)
end
- after { clear_mocked_upcoming_change_metadata }
-
it "seeds last_viewed to the UC when the fetch adds nothing newer, without notifying" do
Notification.destroy_all
diff --git a/spec/lib/discourse_updates_spec.rb b/spec/lib/discourse_updates_spec.rb
index cc846c5bef1..809d2168a9a 100644
--- a/spec/lib/discourse_updates_spec.rb
+++ b/spec/lib/discourse_updates_spec.rb
@@ -362,8 +362,6 @@ RSpec.describe DiscourseUpdates do
)
end
- after { clear_mocked_upcoming_change_metadata }
-
it "marks the injected item as seen" do
freeze_time
expect(DiscourseUpdates.has_unseen_features?(admin.id)).to eq(true)
@@ -411,8 +409,6 @@ RSpec.describe DiscourseUpdates do
)
end
- after { clear_mocked_upcoming_change_metadata }
-
context "when there are no permanent upcoming changes" do
before { mock_merge_uc_metadata(:beta) }
diff --git a/spec/multisite/upcoming_changes_spec.rb b/spec/multisite/upcoming_changes_spec.rb
index a62fd053879..8b08f45ef84 100644
--- a/spec/multisite/upcoming_changes_spec.rb
+++ b/spec/multisite/upcoming_changes_spec.rb
@@ -22,7 +22,6 @@ RSpec.describe "Multisite UpcomingChanges cache", type: :multisite do
Discourse.cache.delete(UpcomingChanges.permanent_upcoming_changes_cache_key)
end
end
- clear_mocked_upcoming_change_metadata
end
it "keeps current_statuses tied to each site's upcoming_change_events" do
diff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rb
index 312f7e044d0..b05e4796dc7 100644
--- a/spec/requests/admin/dashboard_controller_spec.rb
+++ b/spec/requests/admin/dashboard_controller_spec.rb
@@ -303,8 +303,6 @@ RSpec.describe Admin::DashboardController do
)
end
- after { clear_mocked_upcoming_change_metadata }
-
it "includes the permanent upcoming change in the whats-new payload" do
freeze_time do
get "/admin/whats-new.json"
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 12f207d787d..acd5675d44c 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -342,7 +342,9 @@ module Helpers
end
def mock_upcoming_change_metadata(metadata)
- @original_upcoming_changes_metadata = SiteSetting.upcoming_change_metadata.dup
+ # Without ||= here nested blocks would further mutate the instance var so
+ # resetting in clear_mocked_upcoming_change_metadata would not work.
+ @original_upcoming_changes_metadata ||= SiteSetting.upcoming_change_metadata.dup
# We do this because upcoming changes are ephemeral in site settings,
# so we cannot rely on them for specs. Instead we can fake some metadata
@@ -354,7 +356,7 @@ module Helpers
end
def clear_mocked_upcoming_change_metadata
- return if @original_upcoming_changes_metadata.blank?
+ return if @original_upcoming_changes_metadata.nil?
SiteSetting.instance_variable_set(
:@upcoming_change_metadata,