Skip to content

How do you do inline association attribute overrides when your association doesnt match the factory name? #1591

Open
@v2kovac

Description

@v2kovac

The docs here use the worst example where the association happens to match the factory:
https://github.com/thoughtbot/factory_bot/blob/main/GETTING_STARTED.md#overriding-attributes

factory :post do
  # ...
  author_last_name { "Writely" }
  author { association :author, last_name: author_last_name }
end

What if "author" is called "previous_author" on the model, I've tried every variation of explicitly specify the factory and it doesn't work.

eg: previous_author factory: :author { ... } doesn't work, previous_author { ... factory: :author } doesn't work etc. Is this just not possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions