-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate FactoryBot helpers out of the TestingSupport module
- Loading branch information
Showing
67 changed files
with
197 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spree/testing_support/factory_bot' | ||
|
||
module Spree | ||
module TestingSupport | ||
SEQUENCES = ["#{::Spree::Core::Engine.root}/lib/spree/testing_support/sequences.rb"] | ||
FACTORIES = Dir["#{::Spree::Core::Engine.root}/lib/spree/testing_support/factories/**/*_factory.rb"] | ||
|
||
def self.factory_bot_paths | ||
@paths ||= (SEQUENCES + FACTORIES).sort.map { |path| path.sub(/.rb\z/, '') } | ||
end | ||
autoload :FactoryBot, "spree/testing_support/factory_bot" | ||
|
||
def self.deprecate_cherry_picking_factory_bot_files | ||
# All good if the factory is being loaded by FactoryBot. | ||
return if caller.find { |line| line.include? "/factory_bot/find_definitions.rb" } | ||
autoload :SEQUENCES, "spree/testing_support/factory_bot" | ||
autoload :FACTORIES, "spree/testing_support/factory_bot" | ||
|
||
Spree::Deprecation.warn( | ||
"Please do not cherry-pick factories, this is not well supported by FactoryBot. " \ | ||
'Use `require "spree/testing_support/factories"` instead.', caller(2) | ||
) | ||
def factory_bot_paths | ||
Spree::TestingSupport::FactoryBot.definition_file_paths | ||
end | ||
|
||
def self.check_factory_bot_version | ||
require 'factory_bot/version' | ||
|
||
requirement = Gem::Requirement.new("~> 4.8") | ||
version = Gem::Version.new(FactoryBot::VERSION) | ||
|
||
unless requirement.satisfied_by? version | ||
Spree::Deprecation.warn( | ||
"Please be aware that the supported version of FactoryBot is #{requirement}, " \ | ||
"using version #{version} could lead to factory loading issues.", caller(2) | ||
) | ||
end | ||
def check_factory_bot_version | ||
Spree::TestingSupport::FactoryBot.check_version | ||
end | ||
|
||
def self.load_all_factories | ||
require 'factory_bot' | ||
|
||
FactoryBot.definition_file_paths.unshift(*factory_bot_paths).uniq! | ||
FactoryBot.reload | ||
def load_all_factories | ||
Spree::TestingSupport::FactoryBot.add_paths_and_load! | ||
end | ||
|
||
deprecate( | ||
factory_bot_paths: "Spree::TestingSupport::FactoryBot.definition_file_paths", | ||
check_factory_bot_version: "Spree::TestingSupport::FactoryBot.check_version", | ||
load_all_factories: "Spree::TestingSupport::FactoryBot.add_paths_and_load!", | ||
deprecator: Spree::Deprecator | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spree/testing_support' | ||
require 'spree/testing_support/factory_bot' | ||
|
||
Spree::Deprecation.warn( | ||
"Please do not try to load factories directly. " \ | ||
'Use factory_bot_rails and rely on the default configuration instead.', caller(1) | ||
) | ||
|
||
Spree::TestingSupport.check_factory_bot_version | ||
Spree::TestingSupport.load_all_factories | ||
Spree::TestingSupport::FactoryBot.check_factory_bot_version | ||
Spree::TestingSupport::FactoryBot::PATHS.each { |path| require path } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/adjustment_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/adjustment_reason_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/calculator_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/credit_card_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/customer_return_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/inventory_unit_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/line_item_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/option_type_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/option_value_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/order_promotion_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/payment_method_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/product_option_type_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/product_property_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/promotion_category_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/promotion_code_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/promotion_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/lib/spree/testing_support/factories/refund_reason_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.