NoMethodError:未定义的方法“ may_approve?”对于nil:NilClass与pundit和Aasm gem,rspec

时间:2018-11-20 00:14:15

标签: rspec-rails pundit aasm

嗨,我使用机器状态aassm gem运行我的测试专家,但出现此错误, @record为null,但是在带有此变量的pundit文档中,我获得了对象模型。

NoMethodError:        未定义的方法“ may_approve?”为nil:NilClass

这是我的规格文件syllabus_program_policy_spec.rb

需要“ rails_helper”

RSpec.describe SyllabusProgramPolicy do
  subject { SyllabusProgramPolicy }
  include RolesUserConcern 

  permissions :approve? do
    it "approver role can"  do
     expect(subject).to permit(approver)
    end
    it "creator role, cannot approve a silabus" do 
     expect(subject).not_to permit(creator)
    end  
  end 

end

这是我的政策文件

class SyllabusProgramPolicy < ApplicationPolicy
  def approve?
   true if ( @user.is_approver? && @record.may_approve? ) 
  end

  def send_to_approve?
    true if ( @user.is_creator? && @record.may_send_to_approve? )
  end

  def refuse?
   true if ( @user.is_approver? && @record.may_observe? )
  end

  def show?
   true if ( @user.is_approver? || @user.is_creator? )
  end

  def update?
    @user.is_creator?
  end  
end

这是我的文件ApplicationPolicy

class ApplicationPolicy
  attr_reader :user, :record

  def initialize(user, record)
    @user = user
    @record = record
  end
end

可以帮助我

0 个答案:

没有答案