Association overrides

Attribute overrides can be used to link associated objects:

FactoryBot.define do
  factory :author do
    name { 'Taylor' }
  end

  factory :post do
    author
  end
end

eunji = build(:author, name: 'Eunji')
post = build(:post, author: eunji)

Ruby 3.1's support for omitting values from Hash literals dovetails with attribute overrides, and provides an opportunity to limit the repetition of variable names:

author = build(:author, name: 'Eunji')

post = build(:post, author:)