Created
August 5, 2011 20:24
-
-
Save coryschires/1128430 to your computer and use it in GitHub Desktop.
factory_girl_question.rb
This file contains hidden or 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
| # Having trouble getting nested factories working. Is this not supported? Seems like it would be. | |
| # | |
| # The associations are definitely setup correctly in the models: | |
| # A campaign has_many :placements and a placement has_many :deliveries | |
| # | |
| @campaign = Factory(:campaign, :placements => [ | |
| Factory(:placement, :agency_rate => 3.00, :deliveries => [ | |
| Factory(:delivery, :quantity => 600), | |
| Factory(:delivery, :quantity => 100) | |
| ]), | |
| Factory(:placement, :agency_rate => 2.00, :deliveries => [ | |
| Factory(:delivery, :quantity => 150), | |
| Factory(:delivery, :quantity => 200) | |
| ]) | |
| ]) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And this works but it's lame:
@campaign = Factory(:campaign)
placement_1 = Factory(:placement, :agency_rate => 3.00, :campaign => @campaign)
placement_2 = Factory(:placement, :agency_rate => 2.00, :campaign => @campaign)
Factory(:delivery, :placement => placement_1, :quantity => 600)
Factory(:delivery, :placement => placement_1, :quantity => 100)
Factory(:delivery, :placement => placement_2, :quantity => 150)
Factory(:delivery, :placement => placement_2, :quantity => 200)