I am trying to change attributes which are set when saving associations
Factories:
Factory.define :course do |course|
course.title "Course 1"
end
Factory.define :user do |user|
user.name "Alex"
end
Execution
Factory(:course, :user => Factory(:user, name: 'Tim'))
The saved value will be 'Alex' not 'Tim'. Any ideas?
First you need to add the association to your factory:
Factory.define :course do |course|
course.title "Course 1"
course.association :user
end
Then you should do it as a 2-step process:
user = Factory.create :user, :name => "Tim"
course = Factory.create :course, :user => user # or :user_id => user.id
And assuming your model associations and such are set up fine, this will work no problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With