blog.robotex.de

FactoryGirl: Defining associations

Assume you have projects that belongs to a customer. You can define a factory like that:

Factory.define(:customer) do |customer|
  customer.email    "customer@example.com"
  customer.password "foobar"
end

Factory.define(:project do |project|
  project.name "Example project"
  project.description "This is an example project"
  project.targeted_at DateTime.now.advance(:days => 7)
  project.association :customer, :factory => :customer
end

Back