Class: Aegis::Spec::Matchers::CheckPermissions

Inherits:
Object
  • Object
show all
Defined in:
lib/aegis/spec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_resource, expected_options = {}) ⇒ CheckPermissions

Returns a new instance of CheckPermissions.



7
8
9
10
# File 'lib/aegis/spec/matchers.rb', line 7

def initialize(expected_resource, expected_options = {})
  @expected_resource = expected_resource
  @expected_options = expected_options
end

Instance Method Details

#descriptionObject



35
36
37
38
39
# File 'lib/aegis/spec/matchers.rb', line 35

def description
  description = "check permissions against resource #{@expected_resource.inspect}"
  description << " with options #{@expected_options.inspect}" if @expected_options.any?
  description
end

#failure_messageObject



19
20
21
22
23
24
25
# File 'lib/aegis/spec/matchers.rb', line 19

def failure_message
  if @actual_resource != @expected_resource
    "expected #{@controller_class} to check permissions against resource #{@expected_resource.inspect}, but it checked against #{@actual_resource.inspect}"
  else
    "expected #{@controller_class} to check permissions with options #{@expected_options.inspect}, but options were #{@actual_options.inspect}"
  end
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/aegis/spec/matchers.rb', line 12

def matches?(controller)
  @controller_class = controller.class
  @actual_resource = @controller_class.instance_variable_get('@aegis_permissions_resource')
  @actual_options = @controller_class.instance_variable_get('@aegis_permissions_options')
  @actual_resource == @expected_resource && @actual_options == @expected_options
end

#negative_failure_messageObject



27
28
29
30
31
32
33
# File 'lib/aegis/spec/matchers.rb', line 27

def negative_failure_message
  if @actual_resource == @expected_resource
    "expected #{@controller_class} to not check permissions against resource #{@expected_resource.inspect}"
  else
    "expected #{@controller_class} to not check permissions with options #{@expected_options.inspect}"
  end
end