ruby – 如何为命名空间类定义Fabricator
发布时间:2020-12-16 23:11:38 所属栏目:百科 来源:网络整理
导读:我想定义Fabricator for class有’Foo :: Bar’这样的命名空间. 告诉我它的工作方式. 在这里我的代码. 车型/ foo.rb class Foo include Mongoid::Document embedded_in :foo_container,polymorphic: true field :xxx ....end 车型/富/ bar.rb class Foo::Bar
我想定义Fabricator for class有’Foo :: Bar’这样的命名空间.
告诉我它的工作方式. 在这里我的代码. 车型/ foo.rb class Foo include Mongoid::Document embedded_in :foo_container,polymorphic: true field :xxx .... end 车型/富/ bar.rb class Foo::Bar < Foo field :yyy .... field :zzz .... end 数据/制造者/ foo_bar_fabricator.rb Fabricator(:foo_bar,class_name: 'Foo::Bar') do yyy 'MyString' zzz 'MyString' end 当我尝试在parino控制台上创建Fabricatior对象但发生错误. > Fabricate(:foo_bar) > NoMethodError: undefined method `new?' for nil:NilClass .... stack messages 当我尝试创建其他Fabricator对象时不是像’User’这样的命名空间类,它就是正确的. 解决方法
根据Fabrication在
creating objects上的文档:
所以以下应该有效: Fabricator(:foo_bar,from: 'Foo::Bar') do yyy 'MyString' zzz 'MyString' end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |