pundit
pundit copied to clipboard
feat: Add customizable permit description
In this common example, the default description is noisy and doesn't add any information:
🔈 Default output:
ActionItemPolicy
show?
grants access to a customer manager member
when the user is a customer operations member
when there is no relationship to the action item
is expected not to permit #<User id: 2, email_address: "[email protected]", mobile_number: nil, created_at: "2023-02-18 14:3...ation_event_at: nil, release_note_feed_token: nil, opt_out_of_check_in_request_notifications: false> and #<ActionItem id: 2, title: "Fix all the things!", responsible_organization_type: "Customer", responsi...quires_xbe_feature: false, meeting_id: nil, created_by_id: nil, project_id: nil, root_cause_id: nil>
This PR enables you to customize the description.
Pundit::RSpec::Matchers.description do
"permit the user"
end
💆 Customized output:
ActionItemPolicy
show?
grants access to a customer manager member
when the user is a customer operations member
when there is no relationship to the action item
is expected not to permit the user
- closes #759
Thank you! I'm positive about this feature, but I'm not sure about the interface. I also need to borrow myself some time to test it out before I'm willing to merge it.
- I'm leaning to a regular module-level
attr_accessoris more than good enough, similar (but not exactly) like what's in #761
module Pundit
module RSpec
module Matchers
class << self
attr_accessor(:description)
end
end
end
end
- If we are to use a block, passing the
userandrecordmight be prudent to allow for this:
Pundit::RSpec::Matchers.description = ->(user, record) { "permit user with role #{user.role}" }
I merged my branch from https://github.com/varvet/pundit/pull/761 into this one
Hi! Merged in #806