Class: Shoulda::Matchers::Pundit::PermitMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/pundit.rb

Direct Known Subclasses

ForbidMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionsObject (readonly)

Returns the value of attribute actions.



20
21
22
# File 'lib/shoulda/matchers/pundit.rb', line 20

def actions
  @actions
end

#failed_actionsObject (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

#policyObject (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

#descriptionObject



50
51
52
# File 'lib/shoulda/matchers/pundit.rb', line 50

def description
  "permits #{@action}"
end

#failure_message_for_shouldObject



36
37
38
39
40
41
# 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_notObject



43
44
45
46
47
48
# 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) ⇒ Boolean

Returns:

  • (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