class Shoulda::Matchers::Pundit::PermitMatcher

Attributes

actions[R]
failed_actions[R]
policy[R]

Public Class Methods

new(*actions) click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 23
def initialize(*actions)
  @actions = actions
  @failed_actions = []
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 50
def description
  "permits #{@action}"
end
failure_message_for_should() click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 36
        def failure_message_for_should
          <<-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() click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 43
        def failure_message_for_should_not
          <<-message
            #{policy.class} does not #{failure_keyword_forbid} #{failed_actions.join('/')} on #{policy.record}
            for #{policy.user.inspect}.
          message
        end
matches?(policy) click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 28
def matches?(policy)
  @policy = policy

  actions.inject(true) do |pass, action|
    match?(action) && pass
  end
end

Private Instance Methods

append_failed(action) click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 66
def append_failed(action)
  @failed_actions << action
end
failure_keyword_forbid() click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 71
def failure_keyword_forbid; 'forbid'; end
failure_keyword_permit() click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 70
def failure_keyword_permit; 'permit'; end
match?(action) click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 56
def match?(action)
  p = permits? action
  append_failed(action) unless p
  p
end
permits?(action) click to toggle source
# File lib/shoulda/matchers/pundit.rb, line 62
def permits?(action)
  policy.public_send("#{action}?")
end