3.0.0 breaks `permit_action(:action)` matcher for policies with dynamic actions
icnagy opened this issue · 1 comments
icnagy commented
Hi there,
after upgrading to 3.0.0 I noticed that when a policy has a dynamic actions through method_missing
the newly introduced check_actions!
https://github.com/punditcommunity/pundit-matchers/blob/main/lib/pundit/matchers/actions_matcher.rb#L43-L51 fails to recognise them.
Looking at the changes between 2.3.0 and 3.0.0 it isn't clear if it is an actual bug, or the original behaviour is just a side-effect.
In any case, it looks to be relatively easy to get the pre 3.0.0 behaviour back:
def check_actions!
non_explicit_actions = (expected_actions - policy_info.actions)
missing_actions = non_explicit_actions.reject { |action| policy_info.policy.respond_to?("#{action}?".to_sym) }
return if missing_actions.empty?
raise ArgumentError, format(
ACTIONS_NOT_IMPLEMENTED_ERROR,
policy: policy_info, actions: missing_actions
)
end
Let me know what you think.
Cheers,
Csaba
chrisalley commented
I don't believe there was intention behind the original behaviour, but if it was used it would be sensible to add support for dynamic actions back.