Merge pull request #3068 from evazion/fix-pending-flags

Disallow flagging pending posts.
This commit is contained in:
Albert Yi
2017-05-22 11:37:29 -07:00
committed by GitHub
3 changed files with 22 additions and 0 deletions

View File

@@ -158,6 +158,7 @@ class PostFlag < ActiveRecord::Base
end
def validate_post
errors[:post] << "is pending and cannot be flagged" if post.is_pending? && !is_deletion
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked?
errors[:post] << "is deleted" if post.is_deleted?
end

View File

@@ -64,6 +64,13 @@ class PostFlagTest < ActiveSupport::TestCase
assert_equal(["Post is deleted"], @post_flag.errors.full_messages)
end
should "not be able to flag a pending post" do
@post.update_columns(is_pending: true)
@flag = @post.flags.create(reason: "test")
assert_equal(["Post is pending and cannot be flagged"], @flag.errors.full_messages)
end
should "not be able to flag a post in the cooldown period" do
users = FactoryGirl.create_list(:user, 2, created_at: 2.weeks.ago)
flag1 = FactoryGirl.create(:post_flag, post: @post, creator: users.first)

View File

@@ -86,6 +86,20 @@ class PostTest < ActiveSupport::TestCase
end
end
context "that is pending" do
setup do
@post = FactoryGirl.create(:post, is_pending: true)
end
should "succeed" do
@post.delete!("test")
assert_equal(true, @post.is_deleted)
assert_equal(1, @post.flags.size)
assert_match(/test/, @post.flags.last.reason)
end
end
context "with the banned_artist tag" do
should "also ban the post" do
post = FactoryGirl.create(:post, :tag_string => "banned_artist")