im have model Category.
class Category < ActiveRecord::Base
has_ancestry 开发者_JAVA百科:cache_depth => true, :depth_cache_column => :depth
end
Category have field name. Im want to build a factory for category with depth level 2. When this factory will be invoked it must build category level 2 and have parent category with level 1. How to do this? Im trying various tricks, all dont work. Im stop at something like that
Factory.define :category do |f|
f.name { Faker::Lorem.word }
f.parent { Factory.create(:category) }
end
Thank you!
Maybe you can create another factory, which has no parent. And if you want to have you're 2 level category you do:
Factory(:category_level2)
The factory definition could be something like that:
Factory.define :category do |f|
f.name { Faker::Lorem.word }
end
Factory.define :category_level2, :parent => :category do |f|
f.parent { Factory.create(:category) }
end
Cheers
精彩评论