Skip to content

Add for_actions composite matcher to permit/forbid_mass_assignment_of #23

@chrisalley

Description

@chrisalley

Currently, to check that the mass assignment of one or more attributes is permitted or forbidden for different actions, we have to declare this as two seperate statements:

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

But it would be nicer to check that the attribute is permitted with a single statement.

My proposal is that we add a new composite matcher to permit_mass_assignment_of and forbid_mass_assignment_of called for_actions which accepts an array of actions to permit/forbid the atttibute(s) in. E.g.

it { is_expected.to permit_mass_assignment_of(:publish).for_actions(%i[create update]) }

or another example:

it { is_expected.to forbid_mass_assignment_of(%i[foo bar]).for_actions(%i[destroy]) }

The spec should pass if and only if all of the listed attributes are permitted for all of the listed actions, or all of the listed attributes are forbidden for all of the listed actions, for the permit_mass_assignment_of and forbid_mass_assignment_of matchers respectively.

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