solidusio / solidus_dev_support

A collection of tools for developing Solidus extensions.
MIT License
21 stars 27 forks source link

Add instruction on how to use the new factories in apps #172

Closed kennyadsl closed 3 years ago

kennyadsl commented 3 years ago

To load factories of extensions.

mergify[bot] commented 3 years ago

It looks like this PR is missing a label to determine the type of change it introduces. The maintainer should add one of the following labels:

Additionally, the maintainer may also want to add one of the following:

Once the correct labels have been set, simply remove the needs changelog label label from this PR so I can merge it.

kennyadsl commented 3 years ago

Yes, I know this could be confusing. It means that in the spec_helper of your host application you may have switched to the new FactoryBot automatic loading using FactoryBot.definition_file_paths. Right now we can't use that API directory to load extensions factory, unless we do something like:

FactoryBot.definition_file_paths = [
  Spree::TestingSupport::FactoryBot.definition_file_paths,
  SolidusSubscriptions::Engine.root.glob('lib/solidus_subscriptions/testing_support/factories/**/*_factory.rb').map { |path| path.sub(/.rb\z/, '') },
  Rails.root.join('spec/factories')
].flatten

So, we can take advantage of this method added into solidus_dev_support, which also loads core factories:

SolidusDevSupport::TestingSupport::Factories.load_for(SolidusSubscription::Engine, SolidusContent::Engine)

This is an intermediate step, I'd like the final API in a host application to be:

FactoryBot.definition_file_paths = [
  Spree::TestingSupport::FactoryBot.definition_file_paths,
  SolidusSubscriptions::FactoryBot.definition_file_paths,
  SoldiusContent::FactoryBot.definition_file_paths,
  Rails.root.join('spec/factories')
].flatten