Closed cedvw closed 1 month ago
The factory's before(:create) callback is called AFTER the model's after_create.
before(:create)
after_create
Given a simple model, let's call it Account, with an after_create callback:
Account
class Account < ApplicationRecord after_create :do_something def do_something puts 'Model after_create callback' end end
And a factory for it:
FactoryBot.define do factory :account do before(:create) do puts 'Factory before_create callback' end end end
When running a test to create an account using the above factory, the following is printed:
Model after_create callback Factory before_create callback
The order of the callbacks should be before_create followed by after_create.
before_create
Callbacks are called out of order.
factory_bot version: 5.2 rails version: 5.0 ruby version: 2.4
Turned out to be a bug in my application. Closing.
Description
The factory's
before(:create)
callback is called AFTER the model'safter_create
.Reproduction Steps
Given a simple model, let's call it
Account
, with anafter_create
callback:And a factory for it:
When running a test to create an account using the above factory, the following is printed:
Expected behavior
The order of the callbacks should be
before_create
followed byafter_create
.Actual behavior
Callbacks are called out of order.
System configuration
factory_bot version: 5.2 rails version: 5.0 ruby version: 2.4