Skip to content

Instantly share code, notes, and snippets.

@ilpoldo
Created February 20, 2010 17:04
Show Gist options
  • Save ilpoldo/309773 to your computer and use it in GitHub Desktop.
Save ilpoldo/309773 to your computer and use it in GitHub Desktop.
class Album < ActiveRecord::Base
has_one :feature, :as => :featured
end
Factory.define :album do |a|
a.author "A boring author name"
a.title "A boring title"
a.tracks {rand(20)}
end
Factory.define :feature do |f|
f.title 'A Dull Album'
f.description 'Read on for more info'
f.text 'blah blah blah'
f.featured {Factory :album}
end
# Is there a way to deal with factories like this using pickle?
Factory :feature, :title => 'Foo\'s out with a new album',
:description => 'Are they raising the bar?',
:featured => Factory(:album, :author => 'Foo and the Bars')
class Feature < ActiveRecord::Base
belongs_to :featured, :polymorphic => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment