Given this state machine:
steady_state :status do
state 'active', default: true
state 'inactive', from: 'active'
end
We discovered that a factory will be invalid if it explicitly sets the "active" state in the default factory:
# factory
status { "active" }
# usage
FactoryBot.create(:my_factory)
#!> ActiveRecord::RecordInvalid: Validation failed: Status is invalid
FactoryBot.create(:my_factory, status: 'active')
#!> ActiveRecord::RecordInvalid: Validation failed: Status is invalid
FactoryBot.create(:my_factory, status: 'inactive')
#!> works
The fix is to remove the status { "active" } from the factory
Given this state machine:
We discovered that a factory will be invalid if it explicitly sets the "active" state in the default factory:
The fix is to remove the
status { "active" }from the factory