2016-08-21 34 views
0

我想通过与Rspec和Shoulda匹配器的关系来测试has_many。Shoulda匹配器和has_many通过:undefined方法`class_name'为零:NilClass

# student.rb 
has_many :presences 
has_many :calls, through: :presences 

# student_spec.rb 
it { should have_many(:presences) } 
it { should have_many(:calls).through(:presences) } 

#presence.rb 
belongs_to :call 
belongs_to :student 

#presence_spec.rb 
it { should belong_to(:call) } 
it { should belong_to(:student) } 

#call.rb 
has_many :presences 
has_many :students, through: :presences 

#call_spec.rb 
it { should have_many(:presences) } 
it { should have_many(:students).through(:presences) } 

只有最后这些试验的失败,返回:

NoMethodError: 
undefined method `class_name' for nil:NilClass 
Did you mean? class_eval 

我发现this issue,但提出的解决方案不帮我。

回答

0

发现这是一个拐点问题。在我的例子中,我的模型并没有被完全调用,他们使用的是另一种语言。

我不得不为我的一个模型的复数指定一个变形器,所以我的关联会起作用。

rspec或shoulda最终没有问题。

相关问题