Skip to content

Commit

Permalink
Manually require all factories if either Solidus or Alchemy old
Browse files Browse the repository at this point in the history
This stops us from having duplicate factories, and just works (tm).
  • Loading branch information
mamhoff committed May 11, 2021
1 parent eeed54f commit 59692df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gem "solidus_core", github: "solidusio/solidus", branch: solidus_branch
gem "solidus_frontend", github: "solidusio/solidus", branch: solidus_branch
gem "solidus_backend", github: "solidusio/solidus", branch: solidus_branch

alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "main")
alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "5.1-stable")
gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: alchemy_branch
gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: "main"

Expand Down
20 changes: 8 additions & 12 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@
end
end

if Spree.solidus_gem_version >= Gem::Version.new("2.11.0")
require 'spree/testing_support/factory_bot'

Spree::TestingSupport::FactoryBot.add_definitions!
else
require "spree/testing_support/factories"
end

require "alchemy/version"
if Alchemy.gem_version >= Gem::Version.new("5.2.0")
if Spree.solidus_gem_version >= Gem::Version.new("2.11.4") && Alchemy.gem_version >= Gem::Version.new("5.2.0")
require "alchemy/test_support"

require 'spree/testing_support/factory_bot'
FactoryBot.definition_file_paths.prepend(Alchemy::TestSupport.factories_path)
Spree::TestingSupport::FactoryBot.add_definitions!
FactoryBot.find_definitions
else
require "alchemy/test_support/factories"
SPREE_SEQUENCES = ["#{::Spree::Core::Engine.root}/lib/spree/testing_support/sequences.rb"]
SPREE_FACTORIES = Dir["#{::Spree::Core::Engine.root}/lib/spree/testing_support/factories/**/*_factory.rb"]
ALCHEMY_FACTORIES = Dir["#{Alchemy::Engine.root}/lib/alchemy/test_support/factories/*.rb"]
ALL_FACTORIES = (SPREE_SEQUENCES + SPREE_FACTORIES + ALCHEMY_FACTORIES).map { |path| path.sub(/.rb\z/, '') }.uniq
ALL_FACTORIES.each { |f| require f }
end

RSpec.configure do |config|
Expand Down

0 comments on commit 59692df

Please sign in to comment.