Skip to content

Instantly share code, notes, and snippets.

@dougalcorn
Created December 30, 2010 20:34
Show Gist options
  • Select an option

  • Save dougalcorn/760269 to your computer and use it in GitHub Desktop.

Select an option

Save dougalcorn/760269 to your computer and use it in GitHub Desktop.
Non-trivial factory_girl with associations
Factory.define(:kit) do |f|
f.association :primary_palette, :factory => :palette # association doesn't match class name
f.association :secondary_palette, :factory => :palette
f.association :user, :factory => :user
f.sequence(:name) { |i| "Kit#{i}" }
f.bg_images { |images| [images.association(:attachment)] } # has_many assoc
f.default false
f.display_fonts { [Factory(:font), Factory(:font)] }
f.body_font { Factory(:font) }
end
Factory.define(:default_kit, :parent => :kit) do |f|
f.sequence(:name) { |i| "default #{i}" }
f.default true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment