Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add customizable permit description #760

Closed
wants to merge 4 commits into from
Closed

Conversation

barelyknown
Copy link
Contributor

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

@Burgestrand
Copy link
Member

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.

module Pundit
  module RSpec
    module Matchers
      class << self
        attr_accessor(:description)
      end
    end
  end
end
  • If we are to use a block, passing the user and record might be prudent to allow for this:
Pundit::RSpec::Matchers.description = ->(user, record) { "permit user with role #{user.role}" }

@bf4
Copy link
Contributor

bf4 commented Jul 12, 2023

I merged my branch from #761 into this one

@Burgestrand
Copy link
Member

Hi! Merged in #806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable custom description for permit matcher
3 participants