Merge pull request #3027 from evazion/feat-flag-cooldown

Add 3 day cooldown between flags
This commit is contained in:
Albert Yi
2017-05-08 13:05:38 -07:00
committed by GitHub
4 changed files with 37 additions and 14 deletions

View File

@@ -49,7 +49,9 @@ class PostApprovalTest < ActiveSupport::TestCase
@post.approve!(@approver2)
assert_not_equal(@approver.id, @post.approver_id)
CurrentUser.user = @user3
@post.flag!("blah blah")
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
@post.flag!("blah blah")
end
approval = @post.approve!(@approver)
assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")

View File

@@ -44,7 +44,7 @@ class PostFlagTest < ActiveSupport::TestCase
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
end
assert_equal(["You have already flagged this post"], @post_flag.errors.full_messages)
assert_equal(["have already flagged this post"], @post_flag.errors[:creator_id])
end
should "not be able to flag more than 10 posts in 24 hours" do
@@ -64,6 +64,23 @@ class PostFlagTest < ActiveSupport::TestCase
assert_equal(["Post is deleted"], @post_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)
@post.approve!
travel_to(PostFlag::COOLDOWN_PERIOD.from_now - 1.minute) do
flag2 = FactoryGirl.build(:post_flag, post: @post, creator: users.second)
assert(flag2.invalid?)
assert_match(/cannot be flagged more than once/, flag2.errors[:post].join)
end
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
flag3 = FactoryGirl.build(:post_flag, post: @post, creator: users.second)
assert(flag3.valid?)
end
end
should "initialize its creator" do
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
assert_equal(@alice.id, @post_flag.creator_id)