action_policy
action_policy copied to clipboard
Improve rule aliases support
- Make testing utils work with aliases (so, we can do more black-box-like testing).
- Consider adding testing utils to test aliases (
expect(:index?).to be_an_alias_of(:show?)).
Closes #165. Closes #188.
Hello, @palkan !
I was thinking about separating this feature (bugfix?) into two PRs: one for the actual bugfix and one for adding testing utils. WDYT?
Hey, @palkan, @Lokideos! Thank you for this awesome library and all your work!
I just bumped into the alias testing myself. Spend some time figuring out why be_an_alias_of doesn't work according to documentation until I realized that this feature isn't present in the current 0.6 release 🤦♂️
I tried to install it from the master branch with gem 'action_policy', github: 'palkan/action_policy', but it failed to run this way because of unmet ruby-next dependency (Ruby 3.1, Rails 7.0.1, Bundle 2.3.3).
Nonetheless, I just wanted to suggest "embedding" alias testing into current DSL, something like this:
# alias_rule :show?, to: :index?
describe_rule :show? do
is_an_alias_of :index?
end
# - or -
describe_rule_alias :show?, to: :index?
Or something similar. Because the current implementation looks a bit out of place:
describe_rule :index? do
succeed 'for all admins'
end
describe '#show?' do
it "is an alias of :index? authorization rule" do
expect(:show?).to be_an_alias_of(policy, :index?)
end
end
# even when shortened
describe '#show?' do
it { expect(:show?).to be_an_alias_of(policy, :index?) }
end
Is it something you considered or are planning to add? I might help with PR if we agree on the exact syntax.
Hey @svyatov!
I like the idea of adding a DSL method to check aliases; I'd suggest using something less verbose, e.g., alias_rule :index? (similarly to the policy class API). I will be glad to merge a PR)