我有三个彼此关联的工厂:Country
类具有States类,而States
具有City
类。
countries.rb
FactoryBot.define do
factory :country do
name { Faker::Address.unique.country }
end
end
states.rb
FactoryBot.define do
factory :state do
association :country
name { Faker::Address.state }
end
end
cities.rb
FactoryBot.define do
factory :city do
association :state
name { Faker::Address.city }
end
end
在我的规范中,我想实例化特定的对象。
before(:each) do
create(:city,name:"Buffalo")
create(:state,name:"New York")
create(:country,name:"United States")
end
我如何将美国和纽约州,布法罗联系起来?