diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index 3f2f63eefb4..3c4614df142 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -98,12 +98,12 @@ class NewPostManager user.trust_level < SiteSetting.approve_new_topics_unless_trust_level.to_i ) + return :watched_word if WordWatcher.new("#{manager.args[:title]} #{manager.args[:raw]}").requires_approval? + return :fast_typer if is_fast_typer?(manager) return :auto_silence_regex if matches_auto_silence_regex?(manager) - return :watched_word if WordWatcher.new("#{manager.args[:title]} #{manager.args[:raw]}").requires_approval? - return :staged if SiteSetting.approve_unless_staged? && user.staged? return :category if post_needs_approval_in_its_category?(manager) diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb index 65cbe56cf30..847db93db57 100644 --- a/spec/components/new_post_manager_spec.rb +++ b/spec/components/new_post_manager_spec.rb @@ -209,7 +209,6 @@ describe NewPostManager do end context 'with a fast typer' do - let(:manager) { NewPostManager.new(topic.user, raw: 'this is new post content', topic_id: topic.id, first_post_checks: true) } let(:user) { manager.user } before do @@ -217,12 +216,27 @@ describe NewPostManager do end it "adds the silence reason in the system locale" do + manager = build_manager_with('this is new post content') I18n.with_locale(:fr) do # Simulate french user result = NewPostManager.default_handler(manager) end expect(user.silenced?).to eq(true) expect(user.silence_reason).to eq(I18n.t("user.new_user_typed_too_fast", locale: :en)) end + + it 'runs the watched words check before checking if the user is a fast typer' do + Fabricate(:watched_word, word: "darn", action: WatchedWord.actions[:require_approval]) + manager = build_manager_with('this is darn new post content') + + result = NewPostManager.default_handler(manager) + + expect(result.action).to eq(:enqueued) + expect(result.reason).to eq(:watched_word) + end + + def build_manager_with(raw) + NewPostManager.new(topic.user, raw: raw, topic_id: topic.id, first_post_checks: true) + end end end