discourse/spec/support
Alan Guo Xiang Tan 916495e0a1
DEV: Avoid leaking new site setting states in test environment (#21713)
What is the problem?

In the test environement, we were calling `SiteSetting.setting` directly
to introduce new site settings. However, this leads to changes in state of the SiteSettings
hash that is stored in memory as test runs. Changing or leaking states
when running tests is one of the major contributors of test flakiness.

An example of how this resulted in test flakiness is our `spec/integrity/i18n_spec.rb` spec file which
had a test case that would fail because a new "plugin_setting" site
setting was registered in another test case but the site setting did not
have translations for the site setting set.

What is the fix?

There are a couple of changes being introduced in this commit:

1. Make `SiteSetting.setting` a private method as it is not safe to be
   exposed as a public method of the `SiteSetting` class

2. Change test cases to use existing site settings in Discourse instead
   of creating custom site settings. Existing site settings are not
   removed often so we don't really need to dynamically add new site
   settings in test cases. Even if the site settings being used in test
   cases are removed, updating the test cases to rely on other site
   settings is a very easy change.

3. Set up a plugin instance in the test environment as a "fixture"
   instead of having each test create its own plugin instance.
2023-05-25 07:53:57 +08:00
..
versioning DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
bookmarkable_helper.rb DEV: Change Bookmarkable registration to DiscoursePluginRegistry (#20556) 2023-03-08 10:39:12 +10:00
common_basic_reviewable_serializer.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
concurrency.rb DEV: Enable unless cops 2023-02-21 10:30:48 +01:00
diagnostics_helper.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
discourse_event_helper.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
fake_bookmark_hashtag_data_source.rb DEV: Change HashtagAutocompleteService to use DiscoursePluginRegistry (#19491) 2022-12-19 13:46:17 +10:00
fake_logger.rb Build(deps-dev): Bump rspec-rails from 5.1.2 to 6.0.0 (#18534) 2022-10-12 20:25:49 +02:00
fake_s3.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
fast_image_helpers.rb FIX: remove 'crawl_images' site setting (#14646) 2021-10-19 17:12:29 +05:30
final_destination_helper.rb Revert "DEV: Allow webmock to intercept FinalDestination::HTTP requests (#20575)" (#20576) 2023-03-08 11:26:32 +08:00
helpers.rb DEV: Disable SearchIndexer after fabrication (#21378) 2023-05-04 09:20:52 +08:00
imap_helper.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
integration_helpers.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
match_html_matcher.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
mock_git_importer.rb SECURITY: Expand and improve SSRF Protections (#18815) 2022-11-01 16:33:17 +00:00
negated_matcher.rb DEV: Don’t use change { … }.by(0) in specs 2022-07-26 10:34:15 +02:00
onebox_helpers.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
rate_limit_matcher.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
sample_plugin_site_settings.yml DEV: Avoid leaking new site setting states in test environment (#21713) 2023-05-25 07:53:57 +08:00
session_controller_helper_routes.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
shared_examples_for_stats_cacheable.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
sidekiq_helpers.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
site_settings_helpers.rb DEV: Avoid leaking new site setting states in test environment (#21713) 2023-05-25 07:53:57 +08:00
system_helpers.rb DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
test_second_factor_action.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
time_matcher.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
topic_guardian_can_see_consistency_check.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
ts_vector_matcher.rb FIX: domain searches not working properly for URLs (#20136) 2023-02-03 09:55:28 +11:00
uploads_helpers.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
user_sidebar_serializer_attributes.rb SECURITY: Default tags to show count of topics in unrestricted categories (#19916) 2023-01-20 09:50:24 +08:00
webauthn_integration_helpers.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00