I have some doubt with rails 5.2.8 and rspec
To create the object and trait with array associated the rspec code is
let!(:transfer) { Transfer.last }
let!(:transfer_method_type) { create(:transfer_method_type, :with_transfer_methods, transfer: transfer) }
And the factory as:
FactoryBot.define do
factory :transfer_method_type, class: "TransferMethodType" do
association :transfer_methods, transfer
transfer_method_type_name { 'Other' }
trait :with_transfer_methods do
association :transfer,
transfer_methods {
[
create(:transfer_method, transfer: transfer),
create(:transfer_method, transfer: transfer, option: 'Other 2')
]
}
end
end
end
But have an error testing it
Transfer Method Type Tests Show, Update, Delete Deletes a Transfer Method Type
Failure/Error: let!(:transfer_method_type) { create(:transfer_method_type, :with_transfer_methods, transfer: transfer) }
ArgumentError:
Trait not registered: transfer
Not sure how to fix it
The code
association :transfer_methods, transferis basically short for:Ie. the
transferargument is being seen as the trait of thetransfer_methodfactory. Unsurprisingly, there's no trait matching theTransferobject you're passing in as thetransferattribute.