fix intermittent failing tests, some watched word refactoring
This commit is contained in:
parent
ad04d188ae
commit
68b3dd43ce
|
@ -13,7 +13,7 @@ export default Ember.Component.extend(bufferedRender({
|
||||||
this.get('word').destroy().then(() => {
|
this.get('word').destroy().then(() => {
|
||||||
this.sendAction('action', this.get('word'));
|
this.sendAction('action', this.get('word'));
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
|
bootbox.alert(I18n.t("generic_error_with_reason", {error: `http: ${e.status} - ${e.body}`}));
|
||||||
});;
|
});;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -273,12 +273,6 @@ class PostRevisor
|
||||||
@post.word_count = @fields[:raw].scan(/[[:word:]]+/).size if @fields.has_key?(:raw)
|
@post.word_count = @fields[:raw].scan(/[[:word:]]+/).size if @fields.has_key?(:raw)
|
||||||
@post.self_edits += 1 if self_edit?
|
@post.self_edits += 1 if self_edit?
|
||||||
|
|
||||||
if !@post.acting_user.staff? && !@post.acting_user.staged && WordWatcher.new(@post.raw).should_block?
|
|
||||||
@post.errors[:base] << I18n.t('contains_blocked_words')
|
|
||||||
@post_successfully_saved = false
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
remove_flags_and_unhide_post
|
remove_flags_and_unhide_post
|
||||||
|
|
||||||
@post.extract_quoted_post_numbers
|
@post.extract_quoted_post_numbers
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Validators::PostValidator < ActiveModel::Validator
|
||||||
return if options[:skip_post_body] || post.topic&.pm_with_non_human_user?
|
return if options[:skip_post_body] || post.topic&.pm_with_non_human_user?
|
||||||
stripped_length(post)
|
stripped_length(post)
|
||||||
raw_quality(post)
|
raw_quality(post)
|
||||||
|
watched_words(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stripped_length(post)
|
def stripped_length(post)
|
||||||
|
@ -55,6 +56,12 @@ class Validators::PostValidator < ActiveModel::Validator
|
||||||
post.errors.add(:raw, I18n.t(:is_invalid)) unless sentinel.valid?
|
post.errors.add(:raw, I18n.t(:is_invalid)) unless sentinel.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def watched_words(post)
|
||||||
|
if !post.acting_user&.staff? && !post.acting_user&.staged && WordWatcher.new(post.raw).should_block?
|
||||||
|
post.errors[:base] << I18n.t('contains_blocked_words')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Ensure maximum amount of mentions in a post
|
# Ensure maximum amount of mentions in a post
|
||||||
def max_mention_validator(post)
|
def max_mention_validator(post)
|
||||||
return if post.acting_user.try(:staff?)
|
return if post.acting_user.try(:staff?)
|
||||||
|
|
|
@ -247,11 +247,14 @@ describe PrettyText do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does censor code fences' do
|
it 'does censor code fences' do
|
||||||
|
begin
|
||||||
['apple', 'banana'].each { |w| Fabricate(:watched_word, word: w, action: WatchedWord.actions[:censor]) }
|
['apple', 'banana'].each { |w| Fabricate(:watched_word, word: w, action: WatchedWord.actions[:censor]) }
|
||||||
expect(PrettyText.cook("# banana")).not_to include('banana')
|
expect(PrettyText.cook("# banana")).not_to include('banana')
|
||||||
|
ensure
|
||||||
$redis.flushall
|
$redis.flushall
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "rel nofollow" do
|
describe "rel nofollow" do
|
||||||
|
@ -788,13 +791,16 @@ HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can censor words correctly' do
|
it 'can censor words correctly' do
|
||||||
|
begin
|
||||||
['apple', 'banana'].each { |w| Fabricate(:watched_word, word: w, action: WatchedWord.actions[:censor]) }
|
['apple', 'banana'].each { |w| Fabricate(:watched_word, word: w, action: WatchedWord.actions[:censor]) }
|
||||||
expect(PrettyText.cook('yay banana yay')).not_to include('banana')
|
expect(PrettyText.cook('yay banana yay')).not_to include('banana')
|
||||||
expect(PrettyText.cook('yay `banana` yay')).not_to include('banana')
|
expect(PrettyText.cook('yay `banana` yay')).not_to include('banana')
|
||||||
expect(PrettyText.cook("# banana")).not_to include('banana')
|
expect(PrettyText.cook("# banana")).not_to include('banana')
|
||||||
expect(PrettyText.cook("# banana")).to include("\u25a0\u25a0")
|
expect(PrettyText.cook("# banana")).to include("\u25a0\u25a0")
|
||||||
|
ensure
|
||||||
$redis.flushall
|
$redis.flushall
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'supports typographer' do
|
it 'supports typographer' do
|
||||||
SiteSetting.enable_markdown_typographer = true
|
SiteSetting.enable_markdown_typographer = true
|
||||||
|
|
|
@ -12,6 +12,10 @@ describe WatchedWord do
|
||||||
let(:flag_word) { Fabricate(:watched_word, action: WatchedWord.actions[:flag]) }
|
let(:flag_word) { Fabricate(:watched_word, action: WatchedWord.actions[:flag]) }
|
||||||
let(:block_word) { Fabricate(:watched_word, action: WatchedWord.actions[:block]) }
|
let(:block_word) { Fabricate(:watched_word, action: WatchedWord.actions[:block]) }
|
||||||
|
|
||||||
|
after do
|
||||||
|
$redis.flushall
|
||||||
|
end
|
||||||
|
|
||||||
context "block" do
|
context "block" do
|
||||||
def should_block_post(manager)
|
def should_block_post(manager)
|
||||||
expect {
|
expect {
|
||||||
|
|
Loading…
Reference in New Issue