Skip to content

Instantly share code, notes, and snippets.

@jeffrydegrande
Created June 8, 2012 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrydegrande/2898729 to your computer and use it in GitHub Desktop.
Save jeffrydegrande/2898729 to your computer and use it in GitHub Desktop.
# So .. if I really need to have different behavior
# based on gender ...
class Male < Person
end
class Female < Person
end
FactoryGirl.define do
factory :john, :class => Male do
name "john"
end
factory "joe", :class => Male do
end
# or even
factory :dude, :class => Male do
end
factory :john, :parent => :dude do
end
end
# I usually don't so I probably end up with
class Person
attr_accessor :gender
end
Person.new.gender = :male # I like to use symbols in code and convert them to string
Person.new.gender = :female
FactoryGirl.define do
factory :john, :class => Person do
name 'John Doe'
gender :male
end
factory :joe, :class => Person do
name 'John Roe'
gender :male
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment