Class: Hubbado::Policy::RspecMatchers::Permit::PermitMatcher
- Inherits:
-
Object
- Object
- Hubbado::Policy::RspecMatchers::Permit::PermitMatcher
- Defined in:
- lib/hubbado/policy/rspec_matchers/permit.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(action, *args, **kwargs) ⇒ PermitMatcher
constructor
A new instance of PermitMatcher.
- #matches?(policy) ⇒ Boolean
Constructor Details
#initialize(action, *args, **kwargs) ⇒ PermitMatcher
Returns a new instance of PermitMatcher.
10 11 12 13 14 |
# File 'lib/hubbado/policy/rspec_matchers/permit.rb', line 10 def initialize(action, *args, **kwargs) @action = action @args = args @kwargs = kwargs end |
Instance Method Details
#description ⇒ Object
29 30 31 |
# File 'lib/hubbado/policy/rspec_matchers/permit.rb', line 29 def description "#{@policy.class.name} permit #{@action}" end |
#failure_message ⇒ Object
33 34 35 36 |
# File 'lib/hubbado/policy/rspec_matchers/permit.rb', line 33 def "Expected #{@policy.class.name} to permit #{@action}, " \ "but it was revoked with #{@reason ? @result.reason : 'no reason'}" end |
#failure_message_when_negated ⇒ Object
38 39 40 |
# File 'lib/hubbado/policy/rspec_matchers/permit.rb', line 38 def "Expected #{@policy.class.name} to deny #{@action}, but it was permitted" end |
#matches?(policy) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hubbado/policy/rspec_matchers/permit.rb', line 16 def matches?(policy) @policy = policy if policy.respond_to?(@action) @result = policy.send @action, *@args, **@kwargs @result.permitted? else # TODO: Get rid of this branch once the Navigation policy uses the DSL policy.send "#{@action}?", *@args, **@kwargs end end |