Skip to content

Instantly share code, notes, and snippets.

@smtlaissezfaire
Created February 8, 2009 20:32
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 smtlaissezfaire/60497 to your computer and use it in GitHub Desktop.
Save smtlaissezfaire/60497 to your computer and use it in GitHub Desktop.
## Fixjour
define_builder(Person) do |klass, overrides|
overrides.process(:child) do |is_child|
overrides[:dob] = is_child ? 2.years.ago : 42.years.ago
end
klass.new(:name => "Pat")
end
create_person
create_person(:child => true)
## FixtureReplacement
attributes_for :person do |p|
p.name = "Pat"
end
attributes_for :child, :from => :person, :class => Person do |c|
c.child = true
end
attributes_for :adult, :from => :person, :class => Person do |a|
a.child = false
end
create_person() #=> <Person#...>
create_child() #=> <Person# child = true>
create_adult() #=> <Person# child = false)
create_person(:child => true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment