Created
April 30, 2011 21:53
-
-
Save rafarubert/950028 to your computer and use it in GitHub Desktop.
accepts_nested_attributes_for + factoryGirl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#antes: | |
Factory.define :bunch , :class => Bunch do |f| | |
f.ribbon_color_id 1 | |
f.production_unit_id 1 | |
f.release "2011-01-12 22:37:49" | |
f.user_id 1 | |
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.association :lot | |
f.association :bunch | |
end | |
#Depois: | |
Factory.define :bunch , :class => Bunch do |f| | |
f.ribbon_color_id 1 | |
f.production_unit_id 1 | |
f.release "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.association :lot | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment