Skip to content

Instantly share code, notes, and snippets.

@jasonblanchard
Last active December 28, 2015 10:39
Show Gist options
  • Select an option

  • Save jasonblanchard/7487826 to your computer and use it in GitHub Desktop.

Select an option

Save jasonblanchard/7487826 to your computer and use it in GitHub Desktop.
Factory Girl Mongoid Associations
# 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