Class: LogicalAuthz::Matcher::Authorized

Inherits:
Object
  • Object
show all
Defined in:
lib/logical_authz/spec_helper.rb

Direct Known Subclasses

Forbidden

Instance Method Summary collapse

Constructor Details

#initializeAuthorized

Returns a new instance of Authorized.



4
5
6
# File 'lib/logical_authz/spec_helper.rb', line 4

def initialize
  @controller = nil
end

Instance Method Details

#check_authorization_flagObject



12
13
14
15
16
# File 'lib/logical_authz/spec_helper.rb', line 12

def check_authorization_flag
  return false unless @flash.has_key? :logical_authz_record
  return true if @flash[:logical_authz_record][:result] == true
  return false
end

#failure_message(match_text) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logical_authz/spec_helper.rb', line 25

def failure_message(match_text)
  if @flash.has_key? :logical_authz_record
    laz_rec = @flash[:logical_authz_record]
    "Expected #{@controller.class.name}(#{@controller.params.inspect})" + 
      " #{match_text} #{match_state}, but flash[:logical_authz_record][:result] " + 
        "is <#{laz_rec[:result].inspect}> (reason: #{laz_rec[:reason].inspect}, " +
      "rule: #{laz_rec[:determining_rule].try(:name)})"
  else
    "Expected #{@controller.class.name}(#{@controller.params.inspect}) #{match_text} #{match_state}, but flash did not have key :logical_authz_record"
  end
end

#failure_message_for_shouldObject



37
38
39
# File 'lib/logical_authz/spec_helper.rb', line 37

def failure_message_for_should
  failure_message("to be")
end

#failure_message_for_should_notObject



41
42
43
# File 'lib/logical_authz/spec_helper.rb', line 41

def failure_message_for_should_not
  failure_message("not to be")
end

#match_stateObject



8
9
10
# File 'lib/logical_authz/spec_helper.rb', line 8

def match_state
  "authorized"
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/logical_authz/spec_helper.rb', line 18

def matches?(controller)
  @controller = controller
  @flash = controller.__send__(:flash)
  #controller should be a controller
  return check_authorization_flag
end