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

Remove README section about view specs

This really isn't the place for this kind of thing. If someone wants to write a blog post about this, I'd be happy to link it in external resources.
This commit is contained in:
Jonas Nicklas 2015-03-27 10:48:49 +01:00
parent 8c121c73d3
commit ecddb76ec0

View file

@ -546,31 +546,6 @@ end
An alternative approach to Pundit policy specs is scoping them to a user context as outlined in this
[excellent post](http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/).
### View Specs
When writing view specs, you'll notice that the policy helper is not available
and views under test that use it will fail. Thankfully, it's very easy to stub
out the policy to have it return whatever is appropriate for the spec.
``` ruby
describe "users/show" do
before(:each) do
user = assign(:user, build_stubbed(:user))
controller.stub(:current_user).and_return user
end
it "renders the destroy action" do
allow(view).to receive(:policy).and_return double(edit?: false, destroy?: true)
render
expect(rendered).to match 'Destroy'
end
end
```
This technique enables easy unit testing of tricky conditionaly view logic
based on what is or is not authorized.
# External Resources
- [RailsApps Example Application: Pundit and Devise](https://github.com/RailsApps/rails-devise-pundit)