Files
danbooru/test/unit/post_appeal_test.rb
evazion bab656a873 config: remove more obsolete or unneeded config options.
Remove more config options that were either unused or that shouldn't
need to be configured by downstream users.
2020-01-11 01:31:29 -06:00

57 lines
1.8 KiB
Ruby

require 'test_helper'
class PostAppealTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = FactoryBot.create(:user)
CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a user" do
setup do
@post = FactoryBot.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_includes(@post_appeal.errors.full_messages, "You have already appealed this post")
end
should "not be able to appeal more than 1 post in 24 hours" do
@post_appeal = PostAppeal.new(:post => @post, :reason => "aaa")
@post_appeal.expects(:appeal_count_for_creator).returns(1)
assert_difference("PostAppeal.count", 0) do
@post_appeal.save
end
assert_equal(["You can appeal at most 1 post 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