discourse/spec
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
..
fabricators FIX: Fix for Default to subcategory when parent category does not allow posting (#21537) 2023-05-19 07:37:23 -05:00
fixtures FIX: improve mailman email parsing (#21627) 2023-05-19 10:33:48 +02:00
helpers DEV: Replace #pluck_first freedom patch with AR #pick in core (#19893) 2023-02-13 12:39:45 +08:00
import_export DEV: Apply syntax_tree formatting to `spec/*` 2023-01-09 11:49:28 +00:00
initializers FEATURE: Create legal topics for set company name (#21620) 2023-05-24 23:05:36 +03:00
integration FIX: Handle all UTF-8 characters (#21344) 2023-05-15 12:45:04 +03:00
integrity DEV: Avoid leaking new site setting states in test environment (#21713) 2023-05-25 07:53:57 +08:00
jobs FIX: consider users.created_at for inactive cleanup (#21688) 2023-05-23 13:41:23 +05:30
lib FEATURE: Create legal topics for set company name (#21620) 2023-05-24 23:05:36 +03:00
mailers FIX: Likes received count in digest email (#21458) 2023-05-09 19:19:26 +02:00
models FIX: Don’t run validations when invalidating invites 2023-05-24 15:51:33 +02:00
multisite DEV: Add plugin hook for transforming site setting defaults (#20941) 2023-04-05 12:28:16 +01:00
requests DEV: Avoid leaking new site setting states in test environment (#21713) 2023-05-25 07:53:57 +08:00
script/import_scripts DEV: Correct syntax_tree violations 2023-02-02 13:03:11 +00:00
serializers DEV: Remove legacy user menu (#21308) 2023-05-17 09:16:42 -07:00
services FIX: Do not cook icon with hashtags (#21676) 2023-05-23 09:33:55 +02:00
support DEV: Avoid leaking new site setting states in test environment (#21713) 2023-05-25 07:53:57 +08:00
system FIX: flakey spec in sidebar with new font size (#21728) 2023-05-24 18:59:12 +02:00
tasks DEV: Capture output in hashtags spec (#20773) 2023-03-23 11:47:14 +10:00
views FEATURE: add category name in articleSection meta tag for schema. (#21004) 2023-04-06 23:30:19 +05:30
rails_helper.rb FIX: flakey spec in sidebar with new font size (#21728) 2023-05-24 18:59:12 +02:00
regenerate_swagger_docs DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
swagger_helper.rb DEV: Apply syntax_tree formatting to `spec/*` 2023-01-09 11:49:28 +00:00