Ruby on rails 授权策略未正确初始化
我正在练习Rails 4中的动作(清单8-12)。我安装了pundit gem并编写了测试,Rspec给了我奇怪的错误:Ruby on rails 授权策略未正确初始化,ruby-on-rails,rspec,pundit,Ruby On Rails,Rspec,Pundit,我正在练习Rails 4中的动作(清单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 (give
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)>'
应用程序策略(如果是由gem自动生成的,则没有任何更改)
其余部分省略了您是否遵循权威文档中的指导原则@Zettetic我根据文档更新了规范,它成功了,谢谢!我不得不添加一行
subject{descripted_class}
,这在书中并没有说明。
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
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end