skill-assessment-app/test/policies/application_policy_test.rb
2016-09-20 14:22:20 -05:00

31 lines
964 B
Ruby

# frozen_string_literal: true
require 'test_helper'
class ApplicationPolicyTest < PolicyAssertions::Test
# Verify default policies are most restrictive
test 'should require a user' do
assert_raise Pundit::NotAuthorizedError do
ApplicationPolicy.new(nil, User.new)
end
end
test 'should not allow collections' do
assert_raise Pundit::NotAuthorizedError do
ApplicationPolicy::Scope.new(users(:admin), User).resolve
end
end
test 'should not permit by default' do
admin = users(:admin)
refute ApplicationPolicy.new(admin, User.new).view?
refute ApplicationPolicy.new(admin, User.new).show?
refute ApplicationPolicy.new(admin, nil).index?
refute ApplicationPolicy.new(admin, nil).create?
refute ApplicationPolicy.new(admin, nil).new?
refute ApplicationPolicy.new(admin, nil).update?
refute ApplicationPolicy.new(admin, nil).edit?
refute ApplicationPolicy.new(admin, nil).destroy?
end
end