我正在从Rails 4 in Action(列出8-12)中进行练习。我安装了pundit gem并写了测试,Rspec给了我奇怪的错误:
1) ProjectPolicy show? blocks anonymous users
Failure/Error:
def initialize(user, record)
@user = user
@record = record
ArgumentError:
wrong number of arguments (given 0, expected 2)
# ./app/policies/application_policy.rb:4:in `initialize'
# ./spec/policies/project_policy_spec.rb:10:in `block (3 levels) in <top (required)>'
我的项目规范
describe ProjectPolicy do
permissions :show? do
let(:user) { FactoryGirl.create :user }
let(:project) { FactoryGirl.create :project }
it "blocks anonymous users" do
expect(subject).not_to permit(nil, project)
end
end
end
应用程序策略(如果由gem自动生成,那里没有任何更改)
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
其余省略