I have a Restaurant
model that has_many
Dishes
. The problems occur when trying to create this association in my restaurant factory. Following some related posts here on SO I created the necessary association between the two and a before_save
callback to add a dish to the restaurant. Unfortunately when I run my tests I get:
NoMethodError:
undefined method `create_dish' for FactoryGirl:Module
What do I need to fix in order for my tests to run correctly?
Restaurants.rb
FactoryGirl.define do
factory :restaurant do
association :dish, factory: :dish
name "Dinosaur Bar-B-Que"
address "700 W 125th St, New York, NY 10027"
end
after(:create) do |restaurant|
FactoryGirl.create_dish(:dish, 1, restaurant: restaurant)
end
end
Dishes.rb
FactoryGirl.define do
factory :dish do
name "Bar-B-Que Pork Ribs"
description "our st. louis ribs are dry rubbed and slow pit-smoked, then lightly glazed with our original bbq sauce."
end
end
Aucun commentaire:
Enregistrer un commentaire