discourse/spec/multisite
Martin Brennan dd0da69c15
DEV: Fix spec cleanup issues for upcoming changes (#39024)
Fixes two bugs in `clear_mocked_upcoming_change_metadata` /
`mock_upcoming_change_metadata`:

  1. .blank? vs .nil? — {}.blank? is true, so when the original metadata
     was an empty hash (no real upcoming changes loaded in test), the
     clear function returned early without restoring. Fixed by changing
     to .nil?.
  2. Nested mock overwrites original — The `permanent_upcoming_changes`
     describe block in upcoming_changes_spec.rb calls
     `mock_upcoming_change_metadata` a second time in its own before
block. This overwrote `@original_upcoming_changes_metadata` with the
     already-mocked state from the outer before. When clear ran after
     the last example (if it happened to be one from that nested block),
     it restored to the contaminated state instead of the true original.
     Fixed by changing = to ||= so the original is only captured on the
     first call.

Fixes spec failures like this we are seeing:

```
Error encountered while processing /admin/users/1695/revoke_moderation.json.
  NoMethodError: undefined method 'alpha_setting' for class SiteSetting
    ...(1 framework line(s) excluded)
    /__w/discourse/discourse/lib/upcoming_changes.rb:151:in 'Kernel#public_send'
    /__w/discourse/discourse/lib/upcoming_changes.rb:151:in 'UpcomingChanges.enabled_for_user?'
    /__w/discourse/discourse/app/models/user.rb:1971:in 'User#upcoming_change_enabled?'
    /__w/discourse/discourse/lib/upcoming_changes.rb:205:in 'block in UpcomingChanges.stats_for_user'
```
2026-04-01 14:15:02 +10:00
..
distributed_cache_spec.rb DEV: Improve distributed cache multisite specs (#30662) 2025-01-13 17:03:56 +11:00
flags_spec.rb FIX: do not memoize score types (#30657) 2025-01-09 13:20:59 +11:00
hashtag_autocomplete_service_spec.rb DEV: Change HashtagAutocompleteService to use DiscoursePluginRegistry (#19491) 2022-12-19 13:46:17 +10:00
jobs_spec.rb FEATURE: Merge permanent upcoming changes with new features feed (#38526) 2026-03-25 07:52:31 +10:00
pausable_multisite_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
post_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
request_tracker_spec.rb DEV: API to register custom request rate limiting conditions (#30239) 2024-12-23 09:57:18 +08:00
s3_store_spec.rb FIX: Enforce content disposition on S3 presigned URLs (#38850) 2026-03-27 10:04:00 +08:00
site_settings_spec.rb FEATURE: Themeable site settings (#32233) 2025-07-16 11:00:21 +10:00
upcoming_changes_spec.rb DEV: Fix spec cleanup issues for upcoming changes (#39024) 2026-04-01 14:15:02 +10:00