mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-01 04:07:14 +08:00
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'
```
|
||
|---|---|---|
| .. | ||
| distributed_cache_spec.rb | ||
| flags_spec.rb | ||
| hashtag_autocomplete_service_spec.rb | ||
| jobs_spec.rb | ||
| pausable_multisite_spec.rb | ||
| post_spec.rb | ||
| request_tracker_spec.rb | ||
| s3_store_spec.rb | ||
| site_settings_spec.rb | ||
| upcoming_changes_spec.rb | ||