pundit: RSpec + Pundit; Undefined method all? and none?
This may be something really simple, but I was unable to find any answer after extensive googling.
I’m trying to run the following RSpec test:
require "spec_helper"
describe ReportPolicy do
subject { ReportPolicy.new(user, report) }
let(:user) { FactoryGirl.create(:user) }
let(:report) { FactoryGirl.create(:report, organization_id: user.organization_id) }
context "for a user" do
it { should permit(:show) }
it { should_not permit(:edit) }
end
end
It is failing with the errors:
1) ReportPolicy for a user should permit :show
Failure/Error: it { should permit(:show) }
NoMethodError:
undefined method `all?' for nil:NilClass
# ./spec/policies/report_policy_spec.rb:10:in `block (3 levels) in <top (required)>'
2) ReportPolicy for a user should not permit :edit
Failure/Error: it { should_not permit(:edit) }
NoMethodError:
undefined method `none?' for nil:NilClass
# ./spec/policies/report_policy_spec.rb:11:in `block (3 levels) in <top (required)>'
Can anyone explain what is going on here?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 17
You’re not using the matchers the right way. I admit they’re kinda weird. Essentially you need to wrap them in a
permissionsblock, as demonstrated in the README. https://github.com/elabs/pundit#policy-specs