Class: DeclarativeAuthorization::Test::Helpers::RoleTestGenerator
- Inherits:
-
Object
- Object
- DeclarativeAuthorization::Test::Helpers::RoleTestGenerator
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/declarative_authorization/test/helpers.rb
Instance Method Summary collapse
- #allowed(options) ⇒ Object
- #denied(options) ⇒ Object
-
#initialize(test_class, role) ⇒ RoleTestGenerator
constructor
A new instance of RoleTestGenerator.
- #privilege(privilege, &block) ⇒ Object
Constructor Details
#initialize(test_class, role) ⇒ RoleTestGenerator
Returns a new instance of RoleTestGenerator.
80 81 82 83 |
# File 'lib/declarative_authorization/test/helpers.rb', line 80 def initialize(test_class, role) @test_class = test_class @role = role end |
Instance Method Details
#allowed(options) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/declarative_authorization/test/helpers.rb', line 95 def allowed() return unless @test_class.run_assertion?() if [:when] privilege([:when]) { allowed() } else Blockenspiel.invoke(Proc.new {allowed()}, PrivilegeTestGenerator.new(@test_class, @role, nil)) end end |
#denied(options) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/declarative_authorization/test/helpers.rb', line 105 def denied() return unless @test_class.run_assertion?() if [:when] privilege([:when]) { denied() } else Blockenspiel.invoke(Proc.new {denied()}, PrivilegeTestGenerator.new(@test_class, @role, nil)) end end |
#privilege(privilege, &block) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/declarative_authorization/test/helpers.rb', line 85 def privilege(privilege, &block) privileges = [privilege].flatten.uniq unless privileges.all? { |privilege| [:granted, :hidden, :read, :write, :write_without_delete].include?(privilege) } raise "Privilege (:when) must be :granted, :hidden, :read, :write_without_delete, or :write. Found #{privilege.inspect}." end Blockenspiel.invoke(block, PrivilegeTestGenerator.new(@test_class, @role, privileges)) end |