From c7108e077e35ffc4a0ee76aea8ed451b01546820 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 5 Jun 2017 15:21:19 +0900 Subject: [PATCH] FIX: Bot should only respond to regular posts. --- .../lib/discourse_narrative_bot/track_selector.rb | 2 +- .../discourse_narrative_bot/track_selector_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb index 94fdfd9f831..33c1f0fa9aa 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/track_selector.rb @@ -28,7 +28,7 @@ module DiscourseNarrativeBot def select data = Store.get(@user.id) - if @post && !is_topic_action? + if @post && @post.post_type == Post.types[:regular] && !is_topic_action? is_reply = @input == :reply return if is_reply && reset_track diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb index 63b224770ca..39de599ac6a 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb @@ -104,6 +104,18 @@ describe DiscourseNarrativeBot::TrackSelector do end end + context 'when a non regular post is created' do + it 'should not do anything' do + moderator_post = Fabricate(:moderator_post, user: user, topic: topic) + + expect do + described_class.new( + :reply, user, post_id: moderator_post.id + ).select + end.to_not change { Post.count } + end + end + describe 'when user thank the bot' do it 'should like the post' do post.update!(raw: 'thanks!')