mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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
|
@raw = raw
|
||||||
end
|
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)
|
def self.words_for_action(action)
|
||||||
words = WatchedWord
|
words = WatchedWord
|
||||||
.where(action: WatchedWord.actions[action.to_sym])
|
.where(action: WatchedWord.actions[action.to_sym])
|
||||||
@ -24,10 +37,14 @@ class WordWatcher
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.get_cached_words(action)
|
def self.get_cached_words(action)
|
||||||
|
if cache_disabled?
|
||||||
|
words_for_action(action).presence
|
||||||
|
else
|
||||||
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
||||||
words_for_action(action).presence
|
words_for_action(action).presence
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This regexp is run in miniracer, and the client JS app
|
# This regexp is run in miniracer, and the client JS app
|
||||||
# Make sure it is compatible with major browsers when changing
|
# Make sure it is compatible with major browsers when changing
|
||||||
|
@ -520,11 +520,12 @@ describe Report do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
freeze_time
|
freeze_time
|
||||||
|
|
||||||
PostActionCreator.new(flagger, post, PostActionType.types[:spam], message: 'bad').perform
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a report with data" do
|
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
|
expect(report.data).to be_present
|
||||||
|
|
||||||
row = report.data[0]
|
row = report.data[0]
|
||||||
|
@ -105,6 +105,7 @@ module TestSetup
|
|||||||
UserActionManager.disable
|
UserActionManager.disable
|
||||||
NotificationEmailer.disable
|
NotificationEmailer.disable
|
||||||
SiteIconManager.disable
|
SiteIconManager.disable
|
||||||
|
WordWatcher.disable_cache
|
||||||
|
|
||||||
SiteSetting.provider.all.each do |setting|
|
SiteSetting.provider.all.each do |setting|
|
||||||
SiteSetting.remove_override!(setting.name)
|
SiteSetting.remove_override!(setting.name)
|
||||||
|
Loading…
Reference in New Issue
Block a user