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.



79
80
81
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 79

def initialize(role)
  @role = role
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



77
78
79
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 77

def actions
  @actions
end

#behaveObject (readonly)

Returns the value of attribute behave.



77
78
79
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 77

def behave
  @behave
end

#controllerObject (readonly)

Returns the value of attribute controller.



77
78
79
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 77

def controller
  @controller
end

#resultsObject (readonly)

Returns the value of attribute results.



77
78
79
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 77

def results
  @results
end

#roleObject (readonly)

Returns the value of attribute role.



77
78
79
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 77

def role
  @role
end

Instance Method Details

#all_requestsObject



125
126
127
128
129
130
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 125

def all_requests
  actions.map do |action|
    request = Request.new(controller.class, action, role)
    [action, request.response.status != 403]
  end
end

#descriptionObject



154
155
156
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 154

def description
  "have permission for #{role} to #{behave}"
end

#does_not_match?(controller) ⇒ Boolean

Returns:

  • (Boolean)


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

def does_not_match?(controller)
  @controller = controller
  @results    = Hash[all_requests]

  true unless results.value? true
end

#failure_messageObject



146
147
148
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 146

def failure_message
  "Expected #{controller.class} to have permission for #{role} to #{behave}. #{results}"
end

#failure_message_when_negatedObject



150
151
152
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 150

def failure_message_when_negated
  "Did not expect #{controller.class} to have permission for #{role} to #{behave}. #{results}"
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(controller)
  @controller = controller
  @results    = Hash[all_requests]

  true unless results.value? false
end

#to(action) ⇒ Object



83
84
85
86
87
88
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 83

def to(action)
  @behave  = action
  @actions = [behave]

  self
end

#to_createObject



97
98
99
100
101
102
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 97

def to_create
  @behave  = :create
  @actions = %i(new create)

  self
end

#to_deleteObject



111
112
113
114
115
116
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 111

def to_delete
  @behave  = :delete
  @actions = %i(destroy)

  self
end

#to_manageObject



118
119
120
121
122
123
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 118

def to_manage
  @behave  = :manage
  @actions = %i(index show new create edit update destroy)

  self
end

#to_readObject



90
91
92
93
94
95
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 90

def to_read
  @behave  = :read
  @actions = %i(index show)

  self
end

#to_updateObject



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

def to_update
  @behave  = :update
  @actions = %i(edit update)

  self
end