Skip to content

Instantly share code, notes, and snippets.

@lifo
Created August 29, 2009 00:22
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 lifo/177340 to your computer and use it in GitHub Desktop.
Save lifo/177340 to your computer and use it in GitHub Desktop.
class User
has_many :items
end
class Items
belongs_to :user
validates_presence_of :user_id
end
Factory.define(:user) do |u|
u.name "foo"
end
Factory.define(:user_with_items, :parent => :user) do |u|
u.items {|items| [items.association(:item), items.association(:item)]}
end
Factory.define(:item) do |i|
i.color "red"
end
Factory.define(:item_with_user, :parent => :user) do |i|
i.association(:user)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment