Skip to content

Instantly share code, notes, and snippets.

@rafarubert
Created May 17, 2011 22:22
Show Gist options
  • Save rafarubert/977551 to your computer and use it in GitHub Desktop.
Save rafarubert/977551 to your computer and use it in GitHub Desktop.
Factory Exemplo
#bunch.rb
Factory.define :bunch , :class => Bunch do |f|
f.ribbon_color {|ribbon_color|ribbon_color.association(:ribbon_color) }
f.date "2011-01-12 22:37:49"
f.user_id 1
f.after_build { |f|
f.bunch_lots << Factory.build(:bunch_lot)
}
end
Factory.define :lot, :class => Lot do |f|
f.production_unit_id 1
f.name "Lote 1"
end
Factory.define :bunch_lot, :class => BunchLot do |f|
f.bunch_amount 10
f.lot {|lot|lot.association(:lot) }
end
Factory.define :ribbon_color, :class => RibbonColor do |f|
f.name "Azul"
end
#harvest.rb
Factory.define :harvest , :class => Harvest do |f|
f.ribbon_color {|ribbon_color| RibbonColor.first}
f.lot{|lot| Lot.first}
f.harvest_date "2011-04-22"
f.user_id 1
f.bunch_amount 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment