FIX: make sure no more than one 'status' reply is put in a PM (for multiple flags on the same post)

This commit is contained in:
Régis Hanol 2014-08-04 19:39:36 +02:00
parent 925a15c9aa
commit 17debbdcda
2 changed files with 15 additions and 0 deletions

View File

@ -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))

View File

@ -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