Class: RSpec::Authorization::Matchers::HavePermissionFor::HavePermissionFor
- Inherits:
-
Object
- Object
- RSpec::Authorization::Matchers::HavePermissionFor::HavePermissionFor
- Includes:
- Adapters
- Defined in:
- lib/rspec/authorization/matchers/have_permission_for.rb
Overview
:nodoc: all
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#behave ⇒ Object
readonly
Returns the value of attribute behave.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
- #all_requests ⇒ Object
- #description ⇒ Object
- #does_not_match?(controller) ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(role) ⇒ HavePermissionFor
constructor
A new instance of HavePermissionFor.
- #matches?(controller) ⇒ Boolean
- #to(action) ⇒ Object
- #to_create ⇒ Object
- #to_delete ⇒ Object
- #to_manage ⇒ Object
- #to_read ⇒ Object
- #to_update ⇒ Object
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
#actions ⇒ Object (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 |
#behave ⇒ Object (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 |
#controller ⇒ Object (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 |
#results ⇒ Object (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 |
#role ⇒ Object (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_requests ⇒ Object
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 |
#description ⇒ Object
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
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_message ⇒ Object
146 147 148 |
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 146 def "Expected #{controller.class} to have permission for #{role} to #{behave}. #{results}" end |
#failure_message_when_negated ⇒ Object
150 151 152 |
# File 'lib/rspec/authorization/matchers/have_permission_for.rb', line 150 def "Did not expect #{controller.class} to have permission for #{role} to #{behave}. #{results}" end |
#matches?(controller) ⇒ 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_create ⇒ Object
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_delete ⇒ Object
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_manage ⇒ Object
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_read ⇒ Object
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_update ⇒ Object
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 |