How to specify the association with factory_bot?

You should use explicit associations instead of implicit ones:

#spec/factories/post.rb
FactoryBot.define do
  factory :post do
    association :user    # <<<--- here the change
    body Faker::Movie.quote
    posted_at "2018-04-03 13:33:05"
  end
end

#spec/factories/user.rb
FactoryBot.define do 
  factory :user do 
    first_name 'Jake'
  end
end

https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)