You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When i make a trait B that implies A and build with B and A traits the after(:build) in A runs twice
Reproduction Steps
require"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}gem"factory_bot","~> 6.0"gem"activerecord"gem"sqlite3"endrequire"active_record"require"factory_bot"require"minitest/autorun"require"logger"ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:posts,force: truedo |t|
t.string:bodyendend# TODO: Add any application specific code necessary to reproduce the bugclassPost < ActiveRecord::BaseendFactoryBot.definedofactory:postdobody{"Post body"}trait:implies_foodofooendtrait:foodoafter(:build)do |post|
post.body += " with foo"endendendendclassFactoryBotTest < Minitest::Testdeftest_factory_bot_stuffpost=FactoryBot.build(:post,:foo,:implies_foo)assert_equalpost.body,"Post body with foo"endend# Run the tests with `ruby <filename>`
The aggregate callbacks get a flatten.compact but maybe the context is making them dissimilar?
We could wrap them in a registry like the decorators, but then we would need to have a name/identifier for each callback, otherwise how distinguish between one after_save and another, right?
Description
When i make a trait B that implies A and build with B and A traits the after(:build) in A runs twice
Reproduction Steps
Expected behavior
I expect the after(:build) block to be run once
Actual behavior
It runs twice instead
System configuration
factory_bot version: 6.4.5
rails version: 7.2.1
ruby version: 3.3.5
The text was updated successfully, but these errors were encountered: