「Foo::Bar」のような名前空間を持つクラスの Fabricator を定義したいと思います。
うまくいく方法を教えてください。
ここに私のコード。
モデル/foo.rb
class Foo
include Mongoid::Document
embedded_in :foo_container, polymorphic: true
field :xxx ....
end
モデル/foo/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
'User' のような名前空間クラスではない別の Fabricator オブジェクトを作成しようとすると、うまくいきました。