Skip to content

Instantly share code, notes, and snippets.

@mfifth
Created April 27, 2016 20:06
Show Gist options
  • Save mfifth/77b45f25d2ed0904c1dab8bae626c63b to your computer and use it in GitHub Desktop.
Save mfifth/77b45f25d2ed0904c1dab8bae626c63b to your computer and use it in GitHub Desktop.
Pundit Matcher for user roles
RSpec::Matchers.define :permit_action do |action|
match do |policy|
policy.public_send("#{action}?")
end
failure_message do |policy|
"#{policy.class} does not allow #{policy.user || "nil"} to " +
"perform :#{action}? on #{policy.record}."
end
failure_message_when_negated do |policy|
"#{policy.class} does not forbid #{policy.user || "nil"} from " +
"performing :#{action}? on #{policy.record}."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment