Skip to content

Commit

Permalink
add #skip_policy_scope helper
Browse files Browse the repository at this point in the history
  • Loading branch information
erickguan committed Apr 8, 2015
1 parent 73ec66b commit 9ba6123
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/pundit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def skip_authorization
@_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)
Expand Down
7 changes: 7 additions & 0 deletions spec/pundit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@
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
Expand Down

0 comments on commit 9ba6123

Please sign in to comment.