Last active
December 28, 2015 10:39
-
-
Save jasonblanchard/7487826 to your computer and use it in GitHub Desktop.
Factory Girl Mongoid Associations
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
| # This doesn't actually update the user.thing.user_id field. | |
| factory :user_with_a_thing, class User do | |
| association :thing, Factory :thing | |
| end | |
| # So later, a call to user.thing will return nil | |
| # of if you inspect Thing.last, its user_id field will be nil | |
| # This seems to persist it | |
| factory :user_with_a_thing, class User do | |
| association :thing, Factory :thing | |
| after :create do |user| | |
| user.thing.save | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment