thoughtbot / thoughtbot/factory_bot
create_list does not correctly override parameter
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Ive got a factory bot definition like this
FactoryBot.define do
factory :emails_message, class: 'Emails::Message' do
subject { Faker::Lorem.sentence }
thread_subject { Faker::Lorem.sentence }
from { Faker::Internet.unique.email }
from_display_name { "#{Faker::Name.name} <#{from}>" }
end
end
If I create a list like this:
email_address = "test@example.com"
emails = create_list(:emails_message, 10, from: email_address)
Its very weird because it uses the correct from in the from_display_name, but is incorrectly saved in the from attribute
If I print the emails: p emails.map { |r| [r.from, r.from_display_name] }
[["daniela.graham@jast.test", "Prof. Trudi Langosh <test@example.com>"], ["marlys@robel-schmeler.test", "Courtney Becker <test@example.com>"], ["antoine@metz.test", "Ollie Steuber <test@example.com>"], ["sue_harber@medhurst.example", "Johnathan Marvin <test@example.com>"], ["maximo@prosacco-grant.example", "Jacinto O'Reilly <test@example.com>"], ["lindsey@schulist.example", "Mrs. Thanh Schinner <test@example.com>"], ["dominique@kuvalis-wehner.test", "Stevie Larson <test@example.com>"], ["manda@thiel-ziemann.test", "Alena Abbott MD <test@example.com>"], ["fabian.grady@leffler-bechtelar.test", "Lavona Becker Ret. <test@example.com>"], ["gilberto_gleichner@rau.test", "Msgr. Vada Rolfson <test@example.com>"]]
System configuration
factory_bot version: 6.2.1
rails version: 7.0.8
ruby version: 3.2.2
Edit: Ive updated factory_bot to version 6.5.5 and factory_bot_rails to 6.5.1 and it still happens
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the create_list(:emails_message, 10, from: email_address) case from the issue using the shown factory definition and the listed FactoryBot, Rails, and Ruby versions. Trace how the list parameter is applied and how from_display_name reads from; done means every saved record uses the explicit from value while retaining the generated display name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100