开发者

Factory_girls and ancestry

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜