Files
danbooru/test/unit/approver_pruner_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

32 lines
997 B
Ruby

require 'test_helper'
class ApproverPrunerTest < ActiveSupport::TestCase
context "ApproverPruner" do
setup do
@approver = create(:user, can_approve_posts: true)
end
should "demote inactive approvers" do
assert_equal([@approver.id], ApproverPruner.inactive_approvers.map(&:id))
assert_nothing_raised { ApproverPruner.prune! }
assert_equal(false, @approver.reload.can_approve_posts)
end
should "not demote active approvers" do
posts = create_list(:post, ApproverPruner::MINIMUM_APPROVALS + 1, is_pending: true)
posts.each { |post| post.approve!(@approver) }
assert_equal([], ApproverPruner.inactive_approvers.map(&:id))
end
should "not demote recently promoted approvers" do
as(create(:admin_user)) do
@user = create(:user)
@user.promote_to!(User::Levels::BUILDER, can_approve_posts: true)
end
assert_not_includes(ApproverPruner.inactive_approvers.map(&:id), @user.id)
end
end
end