Prior to 6.0.0, one could have a factory with no associated class so long as the child factory specified a class. 6.0.0 and up try to reference the non-existent parent class despite the explicit child class.
We've fixed this by changing the factory to a trait, as it probably should be, but it is an undocumented regression and complicated our FactoryBot upgrade.
require 'factory_bot'
p Gem.loaded_specs["factory_bot"].version
class This
class Exists
def test
"ok"
end
end
end
FactoryBot.define do
factory :does_not_exist do
end
factory :this_exists, class: "This::Exists", parent: :does_not_exist do
end
end
p FactoryBot.build(:this_exists).test
It uses the explicit child class. It prints the Gem version and "ok"
It tries to reference the class implied by the parent factory.
/Users/schwern/.rvm/gems/ruby-2.6.5/gems/activesupport-6.1.1/lib/active_support/inflector/methods.rb:274:in `constantize': uninitialized constant DoesNotExist (NameError)
factory_bot version: 6.1.1
rails version: N/A
ruby version: 2.6.5
Glancing quickly, I think this is a duplicate of https://github.com/thoughtbot/factory_bot/issues/1409
@composerinteralia Yes, it is, and I agree it's not needed.
However, it isn't documented. Is there a place I can document its removal in 6.0.0, and the fix? Maybe the 6.0.0 tag can be bumped?
How about adding this to the 6.0.0 release?
Would you be willing to open a PR adding this to the NEWS.md file for the 6.0.0 release? Then I can update the relevant release notes to match.
We've merged #1463, which addresses this issue. Thank you @schwern! Closing.