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.
76 77 78 79 |
# File 'lib/declarative_authorization/test/helpers.rb', line 76 def initialize(test_class, role) @test_class = test_class @role = role end |
Instance Method Details
#allowed(options) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/declarative_authorization/test/helpers.rb', line 91 def allowed() if [:when] privilege([:when]) { allowed() } else Blockenspiel.invoke(Proc.new {allowed()}, PrivilegeTestGenerator.new(@test_class, @role, nil)) end end |
#denied(options) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/declarative_authorization/test/helpers.rb', line 99 def denied() if [:when] privilege([:when]) { denied() } else Blockenspiel.invoke(Proc.new {denied()}, PrivilegeTestGenerator.new(@test_class, @role, nil)) end end |
#privilege(privilege, &block) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/declarative_authorization/test/helpers.rb', line 81 def privilege(privilege, &block) privileges = [privilege].flatten.uniq unless privileges.all? { |privilege| [:hidden, :read, :write, :write_without_delete].include?(privilege) } raise "Privilege (:when) must be :hidden, :read, :write_without_delete, or :write. Found #{privilege.inspect}." end Blockenspiel.invoke(block, PrivilegeTestGenerator.new(@test_class, @role, privileges)) end |