mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:17:36 +08:00
FEATURE: topic title is validated for blocked words (#8127)
Currently, the topic is only validated for censored words and should be validated for blocked words as well. Blocked word validation is now used by both Post and Topic. To avoid code duplication, I extracted blocked words validation code into separate Validator, and use it in both places. The only downside is that even if the topic contains blocked words validation message is saying "Your post contains a word that's not allowed: tomato" but I think this is descriptive enough.
This commit is contained in:
@ -86,6 +86,22 @@ describe Topic do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'blocked words' do
|
||||
describe 'when title contains watched words' do
|
||||
it 'should not be valid' do
|
||||
Fabricate(:watched_word, word: 'pineapple', action: WatchedWord.actions[:block])
|
||||
|
||||
topic.title = 'pen PinEapple apple pen is a complete sentence'
|
||||
|
||||
expect(topic).to_not be_valid
|
||||
|
||||
expect(topic.errors.full_messages.first).to include(I18n.t(
|
||||
'contains_blocked_word', word: 'PinEapple'
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user