Skip to content

Add for_all_actions composite matcher to permit/forbid_mass_assignment_of #24

@chrisalley

Description

@chrisalley

The readme current states the following:

Warning: Currently, Pundit Matchers does not automatically check if the attribute is permitted by a permitted_attributes_for_#{action} method, so even if you include a forbid_mass_assignment_of(:attribute) expectation in the policy spec, it's entirely possible that the attribute is being permitted through a permitted_attributes_for_#{action} method that is tested separately. For this reason, you should always explicitly test all implemented permitted_attributes_for_#{action} methods, as demonstrated in the example.

However if an attribute is permitted or forbidden in all permitted_attributes methods in the policy, the spec code can become quite long winded. Here's an example from the readme:

 it { is_expected.to permit_mass_assignment_of(:slug) }
 it { is_expected.to permit_mass_assignment_of(:slug).for_action(:create) }
 it { is_expected.to permit_mass_assignment_of(:slug).for_action(:update) }

It would be useful to check do this test in a single statement. I propose that we add a for_all_actions compose matcher to do just that:

 it { is_expected.to permit_mass_assignment_of(:slug).for_all_actions }

This would also work for forbid_mass_assignment_of.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions