2
FactoryGirlとの多形関連のファクトリを設定する際に問題があります。Rails 4.2.6多相関連を持つFactoryGirl
class Address < ActiveRecord::Base
belongs_to :addressable, polymorphic: true
end
class Customer < ActiveRecord::Base
has_one :address, as: :addressable
end
factory :address do
village Faker::Address.city
upazilla Faker::Address.street_name
ward Faker::Address.street_address
district Faker::Address.state
association :addressable
end
factory :customer ,class: Customer do
recharge_token 10
date_of_birth Faker::Date.backward(100)
manager
after(:create) do |customer|
customer.address = create(:address, addressable: customer)
#create(:address, addressable: customer)
end
end
次のエラーメッセージ
vendor/cache/ruby/2.2.0/gems/factory_girl-4.7.0/lib/factory_girl/linter.rb:12:in `lint!': The following factories are invalid: (FactoryGirl::InvalidFactoryError)
* address - Factory not registered: addressable (ArgumentError)
Thisとテストスイートの区切りが正確に私の問題ですが、残念ながら彼のソリューションは、私のために働いていない:私のモデルと工場出荷時の設定は次のようになります。あなたのすべての時間をありがとう!
をねえ、あなたのトップソリューションが素晴らしいです。これを配列にすることはできますか? factory:[:customer、:user、:client] –