Skip to content

Instantly share code, notes, and snippets.

@tagrudev
Last active December 16, 2015 00:09
Show Gist options
  • Save tagrudev/5345691 to your computer and use it in GitHub Desktop.
Save tagrudev/5345691 to your computer and use it in GitHub Desktop.
Singleton for a factory inside another's factory traits = No ideas
FactoryGirl.define do
factory :user do
first_name 'John Doe'
last_name 'Doe'
trait :yolo do
first_name 'Spinder'
last_name 'Man'
end
factory :spinder, traits: [:yolo]
end
factory :message do
# Here I want :spinder and :user to be the same it the both traits
# YOLO
trait :from_spinder do
association :from, factory: :spinder
association :to, factory: :user
end
trait :from_john do
association :from, factory: :user
association :to, factory: :spinder
end
factory :message_from_spinder, traits: [:from_spinder]
factory :message_from_john, traits: [:from_john]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment