2016-08-21 44 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最終沒有問題。

相關問題