« first day  last day (15 days later) » 

12:11 AM
before(:each) do
@user = create(:user)
@car = create(:car, user_id: @user.id)
@style = create(:style , stylable: @car)
end
Is what I have
 
Yah, but the factory automagically creates a car and a style for you when you create a user. You should just have to create a user and then pull the car and style from the @user variable.
 
Got it, so I don't need to create a Car either. will try
 
before(:each) do
@user = create(:user)
@car = @user.car
@style = @user.car.style
end
we getting close
 
 
2 hours later…
2:07 AM
I am getting Car must Exist. I noticed that we created a trait for the associations. According to the documentation.
Polymorphic associations can be handled with traits:

FactoryBot.define do
factory :video
factory :photo

factory :comment do
for_photo

trait :for_video do
association(:commentable, factory: :video)
end

trait :for_photo do
association(:commentable, factory: :photo)
end
end
end
This allows us to do:

create(:comment)
create(:comment, :for_video)
create(:comment, :for_photo)
I assume I need to call create(:style,:for_car)?
factory :car, class: Car do
name { "Holden" }
trait :for_style do
association :stylable, factory: :style
end
I meant create(:car, :for_style)
When I added the for_style, I now get: CarRegistration::Selling#initialize Validating with good data When it has all fields are good should be valid
Failure/Error: user.car ||= create(:car, :user_id => user.id)

ActiveRecord::RecordInvalid:
Validation failed: Stylable must exist, Car must exist
Are the association traits being called?
 
 
3 hours later…
4:50 AM
Sorry, had real life stuff. Can you paste a copy of all the factories in here, as you have them?
 

« first day  last day (15 days later) »