Created
April 27, 2016 20:06
-
-
Save mfifth/77b45f25d2ed0904c1dab8bae626c63b to your computer and use it in GitHub Desktop.
Pundit Matcher for user roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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