Class: Shoulda::Matchers::Pundit::PermittedToMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::Pundit::PermittedToMatcher
- Defined in:
- lib/shoulda/matchers/pundit.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#by(policy) ⇒ Object
alias_method :on_a, :on alias_method :a, :on alias_method :to, :on.
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(action) ⇒ PermittedToMatcher
constructor
A new instance of PermittedToMatcher.
- #matches?(user) ⇒ Boolean
- #on(record) ⇒ Object
Constructor Details
#initialize(action) ⇒ PermittedToMatcher
Returns a new instance of PermittedToMatcher.
97 98 99 |
# File 'lib/shoulda/matchers/pundit.rb', line 97 def initialize(action) @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
95 96 97 |
# File 'lib/shoulda/matchers/pundit.rb', line 95 def action @action end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
95 96 97 |
# File 'lib/shoulda/matchers/pundit.rb', line 95 def policy @policy end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
95 96 97 |
# File 'lib/shoulda/matchers/pundit.rb', line 95 def record @record end |
Instance Method Details
#by(policy) ⇒ Object
alias_method :on_a, :on alias_method :a, :on alias_method :to, :on
116 117 118 119 120 121 122 |
# File 'lib/shoulda/matchers/pundit.rb', line 116 def by(policy) @policy = case policy when Class then lambda { |user, record| policy.new(user, record) } else policy end self end |
#description ⇒ Object
138 139 140 |
# File 'lib/shoulda/matchers/pundit.rb', line 138 def description "permits #{action} on #{record}" end |
#failure_message_for_should ⇒ Object
124 125 126 127 128 129 |
# File 'lib/shoulda/matchers/pundit.rb', line 124 def <<-message User is not permitted to #{action} a #{policy.record} by #{policy.class}. #{policy.user.inspect}. message end |
#failure_message_for_should_not ⇒ Object
131 132 133 134 135 136 |
# File 'lib/shoulda/matchers/pundit.rb', line 131 def <<-message User is not forbidden to #{action} a #{policy.record} by #{policy.class}. #{policy.user.inspect}. message end |
#matches?(user) ⇒ Boolean
101 102 103 104 105 |
# File 'lib/shoulda/matchers/pundit.rb', line 101 def matches?(user) @policy ||= infer_policy(user) @policy = policy.call(user, record) if @policy.is_a? Proc policy.public_send("#{action}?") end |
#on(record) ⇒ Object
107 108 109 110 |
# File 'lib/shoulda/matchers/pundit.rb', line 107 def on(record) @record = record self end |