Skip to content

Instantly share code, notes, and snippets.

@rafarubert
Created April 30, 2011 21:53
Show Gist options
  • Save rafarubert/950028 to your computer and use it in GitHub Desktop.
Save rafarubert/950028 to your computer and use it in GitHub Desktop.
accepts_nested_attributes_for + factoryGirl
#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