Class: RSpec::Authorization::Matchers::HavePermissionFor::HavePermissionFor

Inherits:
Object
  • Object
show all
Includes:
Adapters
Defined in:
lib/rspec/authorization/matchers/have_permission_for.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role) ⇒ HavePermissionFor

Returns a new instance of HavePermissionFor


106
107
108
109
110
111
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 106

def initialize(role)
  @role = role

  @actions = [:index]
  @negated_actions = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object


121
122
123
124
125
126
127
128
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 121

def method_missing(method_name, *args, &block)
  @restful_helper_method = RestfulHelperMethod.new(method_name)

  @actions = restful_helper_method.actions
  @negated_actions = restful_helper_method.negated_actions

  self
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action


102
103
104
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 102

def action
  @action
end

#actionsObject (readonly)

Returns the value of attribute actions


104
105
106
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 104

def actions
  @actions
end

#negated_actionsObject (readonly)

Returns the value of attribute negated_actions


104
105
106
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 104

def negated_actions
  @negated_actions
end

#prefixObject (readonly)

Returns the value of attribute prefix


102
103
104
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 102

def prefix
  @prefix
end

#privilegeObject (readonly)

Returns the value of attribute privilege


103
104
105
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 103

def privilege
  @privilege
end

#resourceObject (readonly)

Returns the value of attribute resource


103
104
105
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 103

def resource
  @resource
end

#restful_helper_methodObject (readonly)

Returns the value of attribute restful_helper_method


103
104
105
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 103

def restful_helper_method
  @restful_helper_method
end

#roleObject (readonly)

Returns the value of attribute role


102
103
104
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 102

def role
  @role
end

Instance Method Details

#descriptionObject


152
153
154
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 152

def description
  "have permission for #{role} #{humanized_behavior}"
end

#does_not_match?(controller) ⇒ Boolean

Returns:

  • (Boolean)

137
138
139
140
141
142
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 137

def does_not_match?(controller)
  build_resource(controller)

  resource.run_all
  resource.forbidden?
end

#failure_messageObject


144
145
146
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 144

def failure_message
  "Expected #{common_failure_message}"
end

#failure_message_when_negatedObject


148
149
150
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 148

def failure_message_when_negated
  "Did not expect #{common_failure_message}"
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)

130
131
132
133
134
135
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 130

def matches?(controller)
  build_resource(controller)

  resource.run_all
  resource.permitted?
end

#to(action) ⇒ Object


113
114
115
116
117
118
119
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 113

def to(action)
  @prefix  = :to
  @action  = action
  @actions = [action]

  self
end