Pundit政策没有正确初始化

时间:2016-05-01 21:02:18

标签: ruby-on-rails rspec pundit

我正在从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

其余省略

0 个答案:

没有答案