post appeal test
This commit is contained in:
@@ -1,8 +1,57 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostAppealTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@alice = Factory.create(:user)
|
||||
CurrentUser.user = @alice
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "a user" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :tag_string => "aaa", :is_deleted => true)
|
||||
end
|
||||
|
||||
should "not be able to appeal a post more than twice" do
|
||||
assert_difference("PostAppeal.count", 1) do
|
||||
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
|
||||
end
|
||||
|
||||
assert_difference("PostAppeal.count", 0) do
|
||||
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
|
||||
end
|
||||
|
||||
assert_equal(["Creator has already appealed this post"], @post_appeal.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to appeal more than 5 posts in 24 hours" do
|
||||
@post_appeal = PostAppeal.new(:post => @post, :reason => "aaa")
|
||||
@post_appeal.expects(:appeal_count_for_creator).returns(5)
|
||||
assert_difference("PostAppeal.count", 0) do
|
||||
@post_appeal.save
|
||||
end
|
||||
assert_equal(["Creator can appeal 5 posts a day"], @post_appeal.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to appeal an active post" do
|
||||
@post.update_attribute(:is_deleted, false)
|
||||
assert_difference("PostAppeal.count", 0) do
|
||||
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
|
||||
end
|
||||
assert_equal(["Post is active"], @post_appeal.errors.full_messages)
|
||||
end
|
||||
|
||||
should "initialize its creator" do
|
||||
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
|
||||
assert_equal(@alice.id, @post_appeal.creator_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user