pundit: convert bans to pundit.

This commit is contained in:
evazion
2020-03-17 22:47:49 -05:00
parent ff1d71af2e
commit 3d72e62c77
6 changed files with 121 additions and 152 deletions

View File

@@ -23,66 +23,7 @@ class BanTest < ActiveSupport::TestCase
assert(user.is_banned?)
end
should "not be valid against another admin" do
user = FactoryBot.create(:admin_user)
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
end
should "be valid against anyone who is not an admin" do
user = FactoryBot.create(:moderator_user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = FactoryBot.create(:contributor_user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = FactoryBot.create(:gold_user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = FactoryBot.create(:user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
end
end
context "created by a moderator" do
setup do
@banner = FactoryBot.create(:moderator_user)
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
@banner = nil
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "not be valid against an admin or moderator" do
user = FactoryBot.create(:admin_user)
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = FactoryBot.create(:moderator_user)
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
end
should "be valid against anyone who is not an admin or a moderator" do
user = FactoryBot.create(:contributor_user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = FactoryBot.create(:gold_user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
should "be valid" do
user = FactoryBot.create(:user)
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)