[英]Factory not registered error due to to_s method in model
I created factories for the model ABCD and it's associated models including the model "another_model" which has a belongs_to relation to ABCD. 我为模型ABCD及其相关模型创建了工厂,包括模型“ another_model”,该模型与ABCD具有belongs_to关系。
The model ABCD has a to_s method that returns ABCD模型有一个to_s方法,该方法返回
def to_s
"Check: #{another_model.check_number} SSNUM: #{something_some_val}"
end
Now when I try to test an action in the ABCD_Controller class I get this error. 现在,当我尝试在ABCD_Controller类中测试操作时,出现此错误。
Failure/Error: get :document_save, {"abcd"=>attributes_for(FactoryGirl.create(:a_patpay)) }
失败/错误:获取:document_save,{“ abcd” => attributes_for(FactoryGirl.create(:a_patpay))}
ArgumentError:
ArgumentError:
Factory not registered: Check: 456465 SSNUM: 06122469
未注册工厂:检查:456465 SSNUM:06122469
Now Check and SSNUM are obviously not attributes of the ABCD Model they are just strings returned by the to_s method in the model. 现在Check和SSNUM显然不是ABCD模型的属性,它们只是模型中to_s方法返回的字符串。 Wondering why FactoryGIrl thinks they are attributes that are not registered...
想知道为什么FactoryGIrl认为它们是未注册的属性...
Any help is much appreciated! 任何帮助深表感谢!
据推测, FactoryGirl.create(:a_patpay)
的定义是返回ABCD
的实例,该实例不是FactoryGirl.attributes_for
的有效参数,并且由于to_s
的定义而按照您的指示进行打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.