Files
danbooru/test/unit/post_appeal_test.rb
evazion b4ce2d83a6 models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field
to the CurrentUser. This made tests complicated because it meant you had
to create and set the current user every time you wanted to create an
object, when lead to the current user being set over and over again. It
also meant you had to constantly be aware of what the CurrentUser was in
many different contexts, which was often confusing. Setting creators
explicitly simplifies everything greatly.
2020-01-21 00:09:38 -06:00

40 lines
1.4 KiB
Ruby

require 'test_helper'
class PostAppealTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = create(:user)
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
@post_appeal = create(:post_appeal, post: @post, creator: @alice)
@post_appeal = build(:post_appeal, post: @post, creator: @alice)
assert_equal(false, @post_appeal.valid?)
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 = create(:post_appeal, post: @post, creator: @alice)
@post_appeal = build(:post_appeal, post: create(:post, is_deleted: true), creator: @alice)
assert_equal(false, @post_appeal.valid?)
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)
@post_appeal = build(:post_appeal, post: @post, creator: @alice)
assert_equal(false, @post_appeal.valid?)
assert_equal(["Post is active"], @post_appeal.errors.full_messages)
end
end
end
end