Module: Pundit::Matchers
- Defined in:
- lib/pundit/matchers.rb,
lib/pundit/matchers/base_matcher.rb,
lib/pundit/matchers/actions_matcher.rb,
lib/pundit/matchers/utils/policy_info.rb,
lib/pundit/matchers/attributes_matcher.rb,
lib/pundit/matchers/permit_actions_matcher.rb,
lib/pundit/matchers/permit_attributes_matcher.rb,
lib/pundit/matchers/forbid_all_actions_matcher.rb,
lib/pundit/matchers/permit_all_actions_matcher.rb,
lib/pundit/matchers/forbid_only_actions_matcher.rb,
lib/pundit/matchers/permit_only_actions_matcher.rb
Overview
Matchers module provides a set of RSpec matchers for testing Pundit policies.
Defined Under Namespace
Modules: Utils Classes: ActionsMatcher, AttributesMatcher, BaseMatcher, Configuration, ForbidAllActionsMatcher, ForbidOnlyActionsMatcher, PermitActionsMatcher, PermitAllActionsMatcher, PermitAttributesMatcher, PermitOnlyActionsMatcher
Constant Summary collapse
- NEGATED_DESCRIPTION =
A Proc that negates the description of a matcher.
->(description) { description.gsub(/^permit/, 'forbid') }
Class Method Summary collapse
-
.configuration ⇒ Configuration
Returns the configuration object for Pundit Matchers.
-
.configure {|configuration| ... } ⇒ Object
Configures Pundit Matchers.
Instance Method Summary collapse
-
#forbid_action ⇒ Object
The negated matcher of #permit_action.
-
#forbid_actions ⇒ Object
The negated matcher of #permit_actions.
-
#forbid_all_actions ⇒ ForbidAllActionsMatcher
Creates a matcher that tests if the policy forbids all actions.
-
#forbid_attribute ⇒ Object
The negated matcher of #permit_attribute.
-
#forbid_attributes ⇒ Object
The negated matcher of #permit_attributes.
-
#forbid_edit_and_update_actions ⇒ Object
The negated matcher of #permit_edit_and_update_actions.
-
#forbid_mass_assignment_of ⇒ Object
An alias matcher for #forbid_attributes.
-
#forbid_new_and_create_actions ⇒ Object
The negated matcher of #permit_new_and_create_actions.
-
#forbid_only_actions(*actions) ⇒ ForbidOnlyActionsMatcher
Creates a matcher that tests if the policy forbids only a set of actions.
-
#permit_action(action) ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits a given action.
-
#permit_actions(*actions) ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits a set of actions.
-
#permit_all_actions ⇒ PermitAllActionsMatcher
Creates a matcher that tests if the policy permits all actions.
-
#permit_attribute(attribute) ⇒ PermitAttributesMatcher
Creates a matcher that tests if the policy permits mass assignment of an attribute.
-
#permit_attributes(*attributes) ⇒ PermitAttributesMatcher
Creates a matcher that tests if the policy permits mass assignment of a set of attributes.
-
#permit_edit_and_update_actions ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits the edit and update actions.
-
#permit_mass_assignment_of ⇒ Object
An alias matcher for #permit_attributes.
-
#permit_new_and_create_actions ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits the new and create actions.
-
#permit_only_actions(*actions) ⇒ PermitOnlyActionsMatcher
Creates a matcher that tests if the policy permits only a set of actions.
Class Method Details
.configuration ⇒ Configuration
Returns the configuration object for Pundit Matchers.
62 63 64 |
# File 'lib/pundit/matchers.rb', line 62 def configuration @configuration ||= Pundit::Matchers::Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configures Pundit Matchers.
55 56 57 |
# File 'lib/pundit/matchers.rb', line 55 def configure yield(configuration) end |
Instance Method Details
#forbid_action ⇒ Object
The negated matcher of #permit_action.
Same as expect(policy).not_to permit_action(*args).
81 |
# File 'lib/pundit/matchers.rb', line 81 RSpec::Matchers.define_negated_matcher :forbid_action, :permit_action, &NEGATED_DESCRIPTION |
#forbid_actions ⇒ Object
The negated matcher of #permit_actions.
Same as expect(policy).not_to permit_actions(*args).
91 |
# File 'lib/pundit/matchers.rb', line 91 RSpec::Matchers.define_negated_matcher :forbid_actions, :permit_actions, &NEGATED_DESCRIPTION |
#forbid_all_actions ⇒ ForbidAllActionsMatcher
The negative form not_to forbid_all_actions is not supported since it creates ambiguity. Instead use to permit_all_actions.
Creates a matcher that tests if the policy forbids all actions.
109 110 111 |
# File 'lib/pundit/matchers.rb', line 109 def forbid_all_actions ForbidAllActionsMatcher.new end |
#forbid_attribute ⇒ Object
The negated matcher of #permit_attribute.
Same as expect(policy).not_to permit_attribute(*args).
163 |
# File 'lib/pundit/matchers.rb', line 163 RSpec::Matchers.define_negated_matcher :forbid_attribute, :permit_attribute, &NEGATED_DESCRIPTION |
#forbid_attributes ⇒ Object
The negated matcher of #permit_attributes.
Same as expect(policy).not_to permit_attributes(*args).
173 |
# File 'lib/pundit/matchers.rb', line 173 RSpec::Matchers.define_negated_matcher :forbid_attributes, :permit_attributes, &NEGATED_DESCRIPTION |
#forbid_edit_and_update_actions ⇒ Object
The negated matcher of #permit_edit_and_update_actions.
Same as expect(policy).not_to permit_edit_and_update_actions(*args).
120 121 |
# File 'lib/pundit/matchers.rb', line 120 RSpec::Matchers.define_negated_matcher :forbid_edit_and_update_actions, :permit_edit_and_update_actions, &NEGATED_DESCRIPTION |
#forbid_mass_assignment_of ⇒ Object
An alias matcher for #forbid_attributes.
180 |
# File 'lib/pundit/matchers.rb', line 180 RSpec::Matchers.alias_matcher :forbid_mass_assignment_of, :forbid_attributes |
#forbid_new_and_create_actions ⇒ Object
The negated matcher of #permit_new_and_create_actions.
Same as expect(policy).not_to permit_new_and_create_actions(*args).
130 131 |
# File 'lib/pundit/matchers.rb', line 130 RSpec::Matchers.define_negated_matcher :forbid_new_and_create_actions, :permit_new_and_create_actions, &NEGATED_DESCRIPTION |
#forbid_only_actions(*actions) ⇒ ForbidOnlyActionsMatcher
The negative form not_to forbid_only_actions is not supported since it creates ambiguity. Instead use to permit_only_actions.
Creates a matcher that tests if the policy forbids only a set of actions.
151 152 153 |
# File 'lib/pundit/matchers.rb', line 151 def forbid_only_actions(*actions) ForbidOnlyActionsMatcher.new(*actions) end |
#permit_action(action) ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits a given action.
71 72 73 |
# File 'lib/pundit/matchers.rb', line 71 def permit_action(action) PermitActionsMatcher.new(action).ensure_single_action! end |
#permit_actions(*actions) ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits a set of actions.
87 88 89 |
# File 'lib/pundit/matchers.rb', line 87 def permit_actions(*actions) PermitActionsMatcher.new(*actions) end |
#permit_all_actions ⇒ PermitAllActionsMatcher
The negative form not_to permit_all_actions is not supported since it creates ambiguity. Instead use to forbid_all_actions.
Creates a matcher that tests if the policy permits all actions.
99 100 101 |
# File 'lib/pundit/matchers.rb', line 99 def permit_all_actions PermitAllActionsMatcher.new end |
#permit_attribute(attribute) ⇒ PermitAttributesMatcher
Creates a matcher that tests if the policy permits mass assignment of an attribute.
159 160 161 |
# File 'lib/pundit/matchers.rb', line 159 def permit_attribute(attribute) PermitAttributesMatcher.new(attribute).ensure_single_attribute! end |
#permit_attributes(*attributes) ⇒ PermitAttributesMatcher
Creates a matcher that tests if the policy permits mass assignment of a set of attributes.
169 170 171 |
# File 'lib/pundit/matchers.rb', line 169 def permit_attributes(*attributes) PermitAttributesMatcher.new(*attributes) end |
#permit_edit_and_update_actions ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits the edit and update actions.
116 117 118 |
# File 'lib/pundit/matchers.rb', line 116 def permit_edit_and_update_actions PermitActionsMatcher.new(:edit, :update) end |
#permit_mass_assignment_of ⇒ Object
An alias matcher for #permit_attributes.
179 |
# File 'lib/pundit/matchers.rb', line 179 RSpec::Matchers.alias_matcher :permit_mass_assignment_of, :permit_attributes |
#permit_new_and_create_actions ⇒ PermitActionsMatcher
Creates a matcher that tests if the policy permits the new and create actions.
126 127 128 |
# File 'lib/pundit/matchers.rb', line 126 def permit_new_and_create_actions PermitActionsMatcher.new(:new, :create) end |
#permit_only_actions(*actions) ⇒ PermitOnlyActionsMatcher
The negative form not_to permit_only_actions is not supported since it creates ambiguity. Instead use to forbid_only_actions.
Creates a matcher that tests if the policy permits only a set of actions.
140 141 142 |
# File 'lib/pundit/matchers.rb', line 140 def permit_only_actions(*actions) PermitOnlyActionsMatcher.new(*actions) end |