DEV: Don't cache watched words in test env (#16731)
The cache was causing state to leak between tests since the `WatchedWord` record in the DB would have been rolled back but `WordWatcher` still had the word in the cache.
This commit is contained in:
parent
8e9164fb60
commit
fd1dc91eed
|
@ -7,6 +7,19 @@ class WordWatcher
|
|||
@raw = raw
|
||||
end
|
||||
|
||||
def self.disable_cache
|
||||
@disabled = true
|
||||
end
|
||||
|
||||
def self.enable_cache
|
||||
@disabled = false
|
||||
end
|
||||
|
||||
# Don't cache in tests mode
|
||||
def self.cache_disabled?
|
||||
@disabled
|
||||
end
|
||||
|
||||
def self.words_for_action(action)
|
||||
words = WatchedWord
|
||||
.where(action: WatchedWord.actions[action.to_sym])
|
||||
|
@ -24,8 +37,12 @@ class WordWatcher
|
|||
end
|
||||
|
||||
def self.get_cached_words(action)
|
||||
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
||||
if cache_disabled?
|
||||
words_for_action(action).presence
|
||||
else
|
||||
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
||||
words_for_action(action).presence
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -520,11 +520,12 @@ describe Report do
|
|||
|
||||
before do
|
||||
freeze_time
|
||||
|
||||
PostActionCreator.new(flagger, post, PostActionType.types[:spam], message: 'bad').perform
|
||||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
result = PostActionCreator.new(flagger, post, PostActionType.types[:spam], message: 'bad').perform
|
||||
|
||||
expect(result.success).to eq(true)
|
||||
expect(report.data).to be_present
|
||||
|
||||
row = report.data[0]
|
||||
|
|
|
@ -105,6 +105,7 @@ module TestSetup
|
|||
UserActionManager.disable
|
||||
NotificationEmailer.disable
|
||||
SiteIconManager.disable
|
||||
WordWatcher.disable_cache
|
||||
|
||||
SiteSetting.provider.all.each do |setting|
|
||||
SiteSetting.remove_override!(setting.name)
|
||||
|
|
Loading…
Reference in New Issue