Class: DeclarativeAuthorization::Test::Helpers::RoleTestGenerator

Inherits:
Object
  • Object
show all
Includes:
Blockenspiel::DSL
Defined in:
lib/declarative_authorization/test/helpers.rb

Instance Method Summary collapse

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(options)
  if options[:when]
    privilege(options[:when]) { allowed(options) }
  else
    Blockenspiel.invoke(Proc.new {allowed(options)}, 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(options)
  if options[:when]
    privilege(options[:when]) { denied(options) }
  else
    Blockenspiel.invoke(Proc.new {denied(options)}, 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