1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

add #skip_policy_scope helper

This commit is contained in:
Erick Guan 2015-04-08 09:17:32 +08:00
parent 73ec66be01
commit 9ba61236b3
3 changed files with 14 additions and 2 deletions

View file

@ -189,8 +189,9 @@ end
```
If you're using `verify_authorized` in your controllers but need to
conditionally bypass verification, you can use `skip_authorization`. This is
useful in circumstances where you don't want to disable verification for the
conditionally bypass verification, you can use `skip_authorization`. For
bypassing `verify_policy_scoped`, use `skip_policy_scope`. These are useful
in circumstances where you don't want to disable verification for the
entire action, but have some cases where you intend to not authorize.
```ruby

View file

@ -117,6 +117,10 @@ module Pundit
@_pundit_policy_authorized = true
end
def skip_policy_scope
@_pundit_policy_scoped = true
end
def policy_scope(scope)
@_pundit_policy_scoped = true
pundit_policy_scope(scope)

View file

@ -287,6 +287,13 @@ describe Pundit do
end
end
describe "#skip_policy_scope" do
it "disables policy scope verification" do
controller.skip_policy_scope
expect { controller.verify_policy_scoped }.not_to raise_error
end
end
describe "#pundit_user" do
it 'returns the same thing as current_user' do
expect(controller.pundit_user).to eq controller.current_user