diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 7d70b8ecb73..33c316007a4 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -196,7 +196,7 @@ class PostDestroyer end def agree_with_flags - if @post.is_flagged? && @user.id > 0 && @user.staff? + if @post.has_active_flag? && @user.id > 0 && @user.staff? Jobs.enqueue( :send_system_message, user_id: @post.user.id, diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 9c81366a0d1..f1c772478f3 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -606,6 +606,16 @@ describe PostDestroyer do Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists? ).to eq(false) end + + it "should not send the flags_agreed_and_post_deleted message if flags were deferred" do + second_post.expects(:update_flagged_posts_count) + PostAction.defer_flags!(second_post, moderator) + second_post.reload + PostDestroyer.new(moderator, second_post).destroy + expect( + Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists? + ).to eq(false) + end end describe "user actions" do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 9ea0db26dc2..99dbfe7fb4e 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -141,7 +141,7 @@ describe Post do let(:user) { Fabricate(:coding_horror) } let(:admin) { Fabricate(:admin) } - it 'isFlagged is accurate' do + it 'is_flagged? is accurate' do PostAction.act(user, post, PostActionType.types[:off_topic]) post.reload expect(post.is_flagged?).to eq(true) @@ -151,7 +151,21 @@ describe Post do expect(post.is_flagged?).to eq(false) end - it 'has_active_flag is accurate' do + it 'is_flagged? is true if flag was deferred' do + PostAction.act(user, post, PostActionType.types[:off_topic]) + PostAction.defer_flags!(post.reload, admin) + post.reload + expect(post.is_flagged?).to eq(true) + end + + it 'is_flagged? is true if flag was cleared' do + PostAction.act(user, post, PostActionType.types[:off_topic]) + PostAction.clear_flags!(post.reload, admin) + post.reload + expect(post.is_flagged?).to eq(true) + end + + it 'has_active_flag? is false for deferred flags' do PostAction.act(user, post, PostActionType.types[:spam]) post.reload expect(post.has_active_flag?).to eq(true) @@ -160,6 +174,13 @@ describe Post do post.reload expect(post.has_active_flag?).to eq(false) end + + it 'has_active_flag? is false for cleared flags' do + PostAction.act(user, post, PostActionType.types[:spam]) + PostAction.clear_flags!(post.reload, admin) + post.reload + expect(post.has_active_flag?).to eq(false) + end end describe "maximum images" do