eBooru/test/unit/post_approval_test.rb

47 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
require "test_helper"
class PostApprovalTest < ActiveSupport::TestCase
2017-04-03 16:15:06 -04:00
context "a pending post" do
setup do
@user = create(:user)
2017-04-03 16:15:06 -04:00
CurrentUser.user = @user
@post = create(:post, uploader_id: @user.id, tag_string: "touhou", is_pending: true)
2017-04-03 16:15:06 -04:00
@approver = create(:user)
2017-04-03 16:15:06 -04:00
@approver.can_approve_posts = true
@approver.save
CurrentUser.user = @approver
end
should "allow approval" do
2017-04-03 16:18:42 -04:00
assert_equal(false, @post.approved_by?(@approver))
2017-04-03 16:15:06 -04:00
end
context "That is approved" do
should "not create a postapproval record when approved by the uploader" do
assert_no_difference("PostApproval.count") do
@post.approve!(@post.uploader)
end
end
should "create a postapproval record when approved by someone else" do
2017-04-03 16:15:06 -04:00
assert_difference("PostApproval.count") do
@post.approve!(create(:janitor_user))
2017-04-03 16:15:06 -04:00
end
end
end
context "#search method" do
should "work" do
@post.approve!(@approver)
@approvals = PostApproval.search(user_name: @approver.name, post_tags_match: "touhou", post_id: @post.id.to_s)
assert_equal([@post.id], @approvals.map(&:post_id))
end
end
2017-04-03 16:15:06 -04:00
end
end