flags: add flag cooldown test.
This commit is contained in:
@@ -163,8 +163,8 @@ class PostFlag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize_creator
|
def initialize_creator
|
||||||
self.creator_id = CurrentUser.id
|
self.creator_id ||= CurrentUser.id
|
||||||
self.creator_ip_addr = CurrentUser.ip_addr
|
self.creator_ip_addr ||= CurrentUser.ip_addr
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve!
|
def resolve!
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ class PostApprovalTest < ActiveSupport::TestCase
|
|||||||
@post.approve!(@approver2)
|
@post.approve!(@approver2)
|
||||||
assert_not_equal(@approver.id, @post.approver_id)
|
assert_not_equal(@approver.id, @post.approver_id)
|
||||||
CurrentUser.user = @user3
|
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)
|
approval = @post.approve!(@approver)
|
||||||
assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")
|
assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class PostFlagTest < ActiveSupport::TestCase
|
|||||||
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
should "not be able to flag more than 10 posts in 24 hours" do
|
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)
|
assert_equal(["Post is deleted"], @post_flag.errors.full_messages)
|
||||||
end
|
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
|
should "initialize its creator" do
|
||||||
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||||
assert_equal(@alice.id, @post_flag.creator_id)
|
assert_equal(@alice.id, @post_flag.creator_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user