Sha256: cdfb1c0e51d3212700ceb42ad6d374bb1355c9ec05f54ec5f52580ec20fa6189
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
require 'test_helper' class LawTest < ActiveSupport::TestCase def setup @law = Robotnik::Authorization::Law.new end test "it has rules" do rules = @law.send :rules assert_instance_of ActiveSupport::HashWithIndifferentAccess, rules end test "it initiates rules for role" do @law.send :init_role_for, :role rules = @law.instance_variable_get('@rules') assert rules.has_key? :role assert_instance_of Robotnik::Authorization::Status, rules[:role] end test "it yields status for authorization definition" do @law.status :admin do can :read, :book end assert @law.instance_variable_get('@rules')[:admin].can? :read, :book, nil end test "it has statuses" do @law.status :admin do end assert_equal ['admin'], @law.statuses end test "it tests status on given object" do object = Object.new class << object def admin true end def not_admin false end end @law.status :admin do can :read, :book end @law.status :not_admin do cannot :read, :book end assert @law.can? object, :read, :book, nil class << object def admin false end def not_admin true end end refute @law.can? object, :read, :book, nil end test "it returns false if no status returns true" do object = Object.new class << object def admin false end end @law.status :admin do end refute @law.can? object, :do, :something, nil end test "it defines a new law at class level" do Robotnik::Authorization::Law.define do status :admin do end end assert_equal ['admin'], Robotnik::Authorization::Law.law.statuses end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stasi-0.0.1.alpha | test/law_test.rb |