Class: Shoulda::Matchers::Pundit::PermitMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::Pundit::PermitMatcher
- Defined in:
- lib/shoulda/matchers/pundit.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#failed_actions ⇒ Object
readonly
Returns the value of attribute failed_actions.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(*actions) ⇒ PermitMatcher
constructor
A new instance of PermitMatcher.
- #matches?(policy) ⇒ Boolean
Constructor Details
#initialize(*actions) ⇒ PermitMatcher
Returns a new instance of PermitMatcher.
23 24 25 26 |
# File 'lib/shoulda/matchers/pundit.rb', line 23 def initialize(*actions) @actions = actions @failed_actions = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
20 21 22 |
# File 'lib/shoulda/matchers/pundit.rb', line 20 def actions @actions end |
#failed_actions ⇒ Object (readonly)
Returns the value of attribute failed_actions.
21 22 23 |
# File 'lib/shoulda/matchers/pundit.rb', line 21 def failed_actions @failed_actions end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
20 21 22 |
# File 'lib/shoulda/matchers/pundit.rb', line 20 def policy @policy end |
Instance Method Details
#description ⇒ Object
50 51 52 |
# File 'lib/shoulda/matchers/pundit.rb', line 50 def description "permits #{@action}" end |
#failure_message_for_should ⇒ Object
36 37 38 39 40 41 |
# File 'lib/shoulda/matchers/pundit.rb', line 36 def <<-message #{policy.class} does not #{failure_keyword_permit} #{failed_actions.join('/')} on #{policy.record} for #{policy.user.inspect}. message end |
#failure_message_for_should_not ⇒ Object
43 44 45 46 47 48 |
# File 'lib/shoulda/matchers/pundit.rb', line 43 def <<-message #{policy.class} does not #{failure_keyword_forbid} #{failed_actions.join('/')} on #{policy.record} for #{policy.user.inspect}. message end |
#matches?(policy) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/shoulda/matchers/pundit.rb', line 28 def matches?(policy) @policy = policy actions.inject(true) do |pass, action| match?(action) && pass end end |