diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 7d787b7a69f..292b5f60fc9 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -156,6 +156,7 @@ class PostAction < ActiveRecord::Base def add_moderator_post_if_needed(moderator, disposition, delete_post=false) return unless related_post + return if related_post.topic.posts.where(post_type: Post.types[:moderator_action]).exists? message_key = "flags_dispositions.#{disposition}" message_key << "_and_deleted" if delete_post related_post.topic.add_moderator_post(moderator, I18n.t(message_key)) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 19209ec5026..11fe6676d20 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -9,6 +9,7 @@ describe PostAction do let(:moderator) { Fabricate(:moderator) } let(:codinghorror) { Fabricate(:coding_horror) } + let(:admin) { Fabricate(:admin) } let(:post) { Fabricate(:post) } let(:second_post) { Fabricate(:post, topic_id: post.topic_id) } let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.types[:bookmark] , post_id: post.id) } @@ -47,6 +48,19 @@ describe PostAction do action.reload action.deleted_at.should be_nil + + # Acting on the flag should post an automated status message + topic.posts.count.should == 2 + PostAction.agree_flags!(post, admin) + topic.reload + topic.posts.count.should == 3 + topic.posts.last.post_type.should == Post.types[:moderator_action] + + # Clearing the flags should not post another automated status message + PostAction.act(mod, post, PostActionType.types[:notify_moderators], message: "another special message") + PostAction.clear_flags!(post, admin) + topic.reload + topic.posts.count.should == 3 end describe 'notify_moderators' do