From 640d52d93211e986732c5db4254674936364819e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 5 Feb 2021 18:45:57 +0100 Subject: [PATCH] Migrate FactoryBot helpers out of the TestingSupport module --- api/spec/spec_helper.rb | 4 +- backend/spec/spec_helper.rb | 4 +- core/lib/spree/core/engine.rb | 8 ++-- core/lib/spree/testing_support.rb | 48 +++++++------------ core/lib/spree/testing_support/factories.rb | 6 +-- .../factories/address_factory.rb | 4 +- .../factories/adjustment_factory.rb | 4 +- .../factories/adjustment_reason_factory.rb | 4 +- .../factories/calculator_factory.rb | 4 +- .../factories/carton_factory.rb | 4 +- .../factories/country_factory.rb | 4 +- .../factories/credit_card_factory.rb | 4 +- .../factories/customer_return_factory.rb | 4 +- .../factories/image_factory.rb | 4 +- .../factories/inventory_unit_factory.rb | 4 +- .../factories/line_item_factory.rb | 4 +- .../factories/option_type_factory.rb | 4 +- .../factories/option_value_factory.rb | 4 +- .../factories/order_factory.rb | 4 +- .../factories/order_promotion_factory.rb | 4 +- .../factories/payment_factory.rb | 4 +- .../factories/payment_method_factory.rb | 4 +- .../factories/price_factory.rb | 4 +- .../factories/product_factory.rb | 4 +- .../factories/product_option_type_factory.rb | 4 +- .../factories/product_property_factory.rb | 4 +- .../factories/promotion_category_factory.rb | 4 +- .../factories/promotion_code_factory.rb | 4 +- .../factories/promotion_factory.rb | 4 +- .../factories/property_factory.rb | 4 +- .../factories/refund_factory.rb | 4 +- .../factories/refund_reason_factory.rb | 4 +- .../factories/reimbursement_factory.rb | 4 +- .../factories/reimbursement_type_factory.rb | 4 +- .../factories/return_authorization_factory.rb | 4 +- .../factories/return_item_factory.rb | 4 +- .../factories/return_reason_factory.rb | 4 +- .../testing_support/factories/role_factory.rb | 4 +- .../factories/shipment_factory.rb | 4 +- .../factories/shipping_category_factory.rb | 4 +- .../factories/shipping_method_factory.rb | 4 +- .../factories/shipping_rate_factory.rb | 4 +- .../factories/state_factory.rb | 4 +- .../factories/stock_item_factory.rb | 4 +- .../factories/stock_location_factory.rb | 4 +- .../factories/stock_movement_factory.rb | 4 +- .../factories/stock_package_factory.rb | 4 +- .../store_credit_category_factory.rb | 4 +- .../factories/store_credit_event_factory.rb | 4 +- .../factories/store_credit_factory.rb | 4 +- .../factories/store_credit_reason_factory.rb | 4 +- .../factories/store_credit_type_factory.rb | 4 +- .../factories/store_factory.rb | 4 +- .../factories/tax_category_factory.rb | 4 +- .../factories/tax_rate_factory.rb | 4 +- .../factories/taxon_factory.rb | 4 +- .../factories/taxonomy_factory.rb | 4 +- .../testing_support/factories/user_factory.rb | 4 +- .../factories/variant_factory.rb | 4 +- ...variant_property_rule_condition_factory.rb | 4 +- .../variant_property_rule_factory.rb | 4 +- .../variant_property_rule_value_factory.rb | 4 +- .../testing_support/factories/zone_factory.rb | 4 +- core/lib/spree/testing_support/factory_bot.rb | 48 +++++++++++++++++++ core/lib/spree/testing_support/sequences.rb | 3 +- core/spec/rails_helper.rb | 2 +- frontend/spec/spec_helper.rb | 2 +- 67 files changed, 197 insertions(+), 160 deletions(-) create mode 100644 core/lib/spree/testing_support/factory_bot.rb diff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rb index 293f99cc607..522be24cda0 100644 --- a/api/spec/spec_helper.rb +++ b/api/spec/spec_helper.rb @@ -26,7 +26,7 @@ # in spec/support/ and its subdirectories. Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f } -require 'spree/testing_support' +require 'spree/testing_support/factory_bot' require 'spree/testing_support/partial_double_verification' require 'spree/testing_support/preferences' require 'spree/testing_support/authorization_helpers' @@ -38,7 +38,7 @@ ActiveJob::Base.queue_adapter = :test -Spree::TestingSupport.load_all_factories +Spree::TestingSupport::FactoryBot.add_paths_and_load! RSpec.configure do |config| config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/] diff --git a/backend/spec/spec_helper.rb b/backend/spec/spec_helper.rb index d5f140d4cc2..b6707569806 100644 --- a/backend/spec/spec_helper.rb +++ b/backend/spec/spec_helper.rb @@ -27,7 +27,7 @@ require 'database_cleaner' require 'with_model' -require 'spree/testing_support' +require 'spree/testing_support/factory_bot' require 'spree/testing_support/partial_double_verification' require 'spree/testing_support/authorization_helpers' require 'spree/testing_support/preferences' @@ -63,7 +63,7 @@ ActiveJob::Base.queue_adapter = :test -Spree::TestingSupport.load_all_factories +Spree::TestingSupport::FactoryBot.add_paths_and_load! RSpec.configure do |config| config.color = true diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb index c7b2ea11275..acf1e3f188e 100644 --- a/core/lib/spree/core/engine.rb +++ b/core/lib/spree/core/engine.rb @@ -70,10 +70,10 @@ class Engine < ::Rails::Engine end if defined?(FactoryBotRails) - initializer after: "factory_bot.set_factory_paths" do - require "spree/testing_support" - Spree::TestingSupport.check_factory_bot_version - FactoryBot.definition_file_paths.unshift(*Spree::TestingSupport.factory_bot_paths) + initializer "spree.factory_bot.set_factory_paths", after: "factory_bot.set_factory_paths" do + require "spree/testing_support/factory_bot" + Spree::TestingSupport::FactoryBot.check_factory_bot_version + FactoryBot.definition_file_paths.unshift(*Spree::TestingSupport::FactoryBot.definition_file_paths) end end end diff --git a/core/lib/spree/testing_support.rb b/core/lib/spree/testing_support.rb index 7252d2c8f93..cff1e49238f 100644 --- a/core/lib/spree/testing_support.rb +++ b/core/lib/spree/testing_support.rb @@ -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 diff --git a/core/lib/spree/testing_support/factories.rb b/core/lib/spree/testing_support/factories.rb index 106985a73a4..8e99fd27b28 100644 --- a/core/lib/spree/testing_support/factories.rb +++ b/core/lib/spree/testing_support/factories.rb @@ -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 } diff --git a/core/lib/spree/testing_support/factories/address_factory.rb b/core/lib/spree/testing_support/factories/address_factory.rb index b04a08f5e20..5ad9c13f4e9 100644 --- a/core/lib/spree/testing_support/factories/address_factory.rb +++ b/core/lib/spree/testing_support/factories/address_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :address, class: 'Spree::Address' do diff --git a/core/lib/spree/testing_support/factories/adjustment_factory.rb b/core/lib/spree/testing_support/factories/adjustment_factory.rb index 4fccb8e3061..cd1a82f249c 100644 --- a/core/lib/spree/testing_support/factories/adjustment_factory.rb +++ b/core/lib/spree/testing_support/factories/adjustment_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :adjustment, class: 'Spree::Adjustment' do diff --git a/core/lib/spree/testing_support/factories/adjustment_reason_factory.rb b/core/lib/spree/testing_support/factories/adjustment_reason_factory.rb index ad2effaa0e8..1391a078126 100644 --- a/core/lib/spree/testing_support/factories/adjustment_reason_factory.rb +++ b/core/lib/spree/testing_support/factories/adjustment_reason_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :adjustment_reason, class: 'Spree::AdjustmentReason' do diff --git a/core/lib/spree/testing_support/factories/calculator_factory.rb b/core/lib/spree/testing_support/factories/calculator_factory.rb index de28fb57055..ef499d51661 100644 --- a/core/lib/spree/testing_support/factories/calculator_factory.rb +++ b/core/lib/spree/testing_support/factories/calculator_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :calculator, aliases: [:flat_rate_calculator], class: 'Spree::Calculator::FlatRate' do diff --git a/core/lib/spree/testing_support/factories/carton_factory.rb b/core/lib/spree/testing_support/factories/carton_factory.rb index a839c6b0d57..637b3e295e3 100644 --- a/core/lib/spree/testing_support/factories/carton_factory.rb +++ b/core/lib/spree/testing_support/factories/carton_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :carton, class: 'Spree::Carton' do diff --git a/core/lib/spree/testing_support/factories/country_factory.rb b/core/lib/spree/testing_support/factories/country_factory.rb index 4271be90a02..8e20df798ba 100644 --- a/core/lib/spree/testing_support/factories/country_factory.rb +++ b/core/lib/spree/testing_support/factories/country_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking require 'carmen' diff --git a/core/lib/spree/testing_support/factories/credit_card_factory.rb b/core/lib/spree/testing_support/factories/credit_card_factory.rb index 2f10fdfb5d9..c72ce8afc17 100644 --- a/core/lib/spree/testing_support/factories/credit_card_factory.rb +++ b/core/lib/spree/testing_support/factories/credit_card_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :credit_card, class: 'Spree::CreditCard' do diff --git a/core/lib/spree/testing_support/factories/customer_return_factory.rb b/core/lib/spree/testing_support/factories/customer_return_factory.rb index 7009b5d51de..e5729175ddd 100644 --- a/core/lib/spree/testing_support/factories/customer_return_factory.rb +++ b/core/lib/spree/testing_support/factories/customer_return_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :customer_return, class: 'Spree::CustomerReturn' do diff --git a/core/lib/spree/testing_support/factories/image_factory.rb b/core/lib/spree/testing_support/factories/image_factory.rb index 24d0ebd90c5..9e4b173bc60 100644 --- a/core/lib/spree/testing_support/factories/image_factory.rb +++ b/core/lib/spree/testing_support/factories/image_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :image, class: 'Spree::Image' do diff --git a/core/lib/spree/testing_support/factories/inventory_unit_factory.rb b/core/lib/spree/testing_support/factories/inventory_unit_factory.rb index 877e08a4487..8e8f5223e29 100644 --- a/core/lib/spree/testing_support/factories/inventory_unit_factory.rb +++ b/core/lib/spree/testing_support/factories/inventory_unit_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :inventory_unit, class: 'Spree::InventoryUnit' do diff --git a/core/lib/spree/testing_support/factories/line_item_factory.rb b/core/lib/spree/testing_support/factories/line_item_factory.rb index 17f6d019175..a8adf1a7435 100644 --- a/core/lib/spree/testing_support/factories/line_item_factory.rb +++ b/core/lib/spree/testing_support/factories/line_item_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :line_item, class: 'Spree::LineItem' do diff --git a/core/lib/spree/testing_support/factories/option_type_factory.rb b/core/lib/spree/testing_support/factories/option_type_factory.rb index 4e11be85956..cbfe97ae6d7 100644 --- a/core/lib/spree/testing_support/factories/option_type_factory.rb +++ b/core/lib/spree/testing_support/factories/option_type_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :option_type, class: 'Spree::OptionType' do diff --git a/core/lib/spree/testing_support/factories/option_value_factory.rb b/core/lib/spree/testing_support/factories/option_value_factory.rb index cbd0298a870..d868d00cbba 100644 --- a/core/lib/spree/testing_support/factories/option_value_factory.rb +++ b/core/lib/spree/testing_support/factories/option_value_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :option_value, class: 'Spree::OptionValue' do diff --git a/core/lib/spree/testing_support/factories/order_factory.rb b/core/lib/spree/testing_support/factories/order_factory.rb index 3df4f1a685a..45cea38f873 100644 --- a/core/lib/spree/testing_support/factories/order_factory.rb +++ b/core/lib/spree/testing_support/factories/order_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :order, class: 'Spree::Order' do diff --git a/core/lib/spree/testing_support/factories/order_promotion_factory.rb b/core/lib/spree/testing_support/factories/order_promotion_factory.rb index 6ada95ed73b..12b0fcb746b 100644 --- a/core/lib/spree/testing_support/factories/order_promotion_factory.rb +++ b/core/lib/spree/testing_support/factories/order_promotion_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :order_promotion, class: 'Spree::OrderPromotion' do diff --git a/core/lib/spree/testing_support/factories/payment_factory.rb b/core/lib/spree/testing_support/factories/payment_factory.rb index 22acaad87f6..9dd24c01757 100644 --- a/core/lib/spree/testing_support/factories/payment_factory.rb +++ b/core/lib/spree/testing_support/factories/payment_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :payment, aliases: [:credit_card_payment], class: 'Spree::Payment' do diff --git a/core/lib/spree/testing_support/factories/payment_method_factory.rb b/core/lib/spree/testing_support/factories/payment_method_factory.rb index dcf6d96cd8e..8c417926a8d 100644 --- a/core/lib/spree/testing_support/factories/payment_method_factory.rb +++ b/core/lib/spree/testing_support/factories/payment_method_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :payment_method, aliases: [:credit_card_payment_method], class: 'Spree::PaymentMethod::BogusCreditCard' do diff --git a/core/lib/spree/testing_support/factories/price_factory.rb b/core/lib/spree/testing_support/factories/price_factory.rb index 526dc64d415..2ef935d9b6f 100644 --- a/core/lib/spree/testing_support/factories/price_factory.rb +++ b/core/lib/spree/testing_support/factories/price_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :price, class: 'Spree::Price' do diff --git a/core/lib/spree/testing_support/factories/product_factory.rb b/core/lib/spree/testing_support/factories/product_factory.rb index c5862b71327..2c36fdbca60 100644 --- a/core/lib/spree/testing_support/factories/product_factory.rb +++ b/core/lib/spree/testing_support/factories/product_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :base_product, class: 'Spree::Product' do diff --git a/core/lib/spree/testing_support/factories/product_option_type_factory.rb b/core/lib/spree/testing_support/factories/product_option_type_factory.rb index 680b47840de..62403d7d358 100644 --- a/core/lib/spree/testing_support/factories/product_option_type_factory.rb +++ b/core/lib/spree/testing_support/factories/product_option_type_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :product_option_type, class: 'Spree::ProductOptionType' do diff --git a/core/lib/spree/testing_support/factories/product_property_factory.rb b/core/lib/spree/testing_support/factories/product_property_factory.rb index d551f0405ea..729f6b2efe7 100644 --- a/core/lib/spree/testing_support/factories/product_property_factory.rb +++ b/core/lib/spree/testing_support/factories/product_property_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :product_property, class: 'Spree::ProductProperty' do diff --git a/core/lib/spree/testing_support/factories/promotion_category_factory.rb b/core/lib/spree/testing_support/factories/promotion_category_factory.rb index 332cbd8c106..ea1a8d03115 100644 --- a/core/lib/spree/testing_support/factories/promotion_category_factory.rb +++ b/core/lib/spree/testing_support/factories/promotion_category_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :promotion_category, class: 'Spree::PromotionCategory' do diff --git a/core/lib/spree/testing_support/factories/promotion_code_factory.rb b/core/lib/spree/testing_support/factories/promotion_code_factory.rb index c35a0b646bd..16a55b972c7 100644 --- a/core/lib/spree/testing_support/factories/promotion_code_factory.rb +++ b/core/lib/spree/testing_support/factories/promotion_code_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :promotion_code, class: 'Spree::PromotionCode' do diff --git a/core/lib/spree/testing_support/factories/promotion_factory.rb b/core/lib/spree/testing_support/factories/promotion_factory.rb index c0122462193..d6268e6b140 100644 --- a/core/lib/spree/testing_support/factories/promotion_factory.rb +++ b/core/lib/spree/testing_support/factories/promotion_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :promotion, class: 'Spree::Promotion' do diff --git a/core/lib/spree/testing_support/factories/property_factory.rb b/core/lib/spree/testing_support/factories/property_factory.rb index 5f0a1875e4b..0fbbe7ad2df 100644 --- a/core/lib/spree/testing_support/factories/property_factory.rb +++ b/core/lib/spree/testing_support/factories/property_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :property, class: 'Spree::Property' do diff --git a/core/lib/spree/testing_support/factories/refund_factory.rb b/core/lib/spree/testing_support/factories/refund_factory.rb index 244225e2d51..0e5b22adefa 100644 --- a/core/lib/spree/testing_support/factories/refund_factory.rb +++ b/core/lib/spree/testing_support/factories/refund_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do sequence(:refund_transaction_id) { |n| "fake-refund-transaction-#{n}" } diff --git a/core/lib/spree/testing_support/factories/refund_reason_factory.rb b/core/lib/spree/testing_support/factories/refund_reason_factory.rb index 2b2afa02ca8..897ab24526b 100644 --- a/core/lib/spree/testing_support/factories/refund_reason_factory.rb +++ b/core/lib/spree/testing_support/factories/refund_reason_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :refund_reason, class: 'Spree::RefundReason' do diff --git a/core/lib/spree/testing_support/factories/reimbursement_factory.rb b/core/lib/spree/testing_support/factories/reimbursement_factory.rb index 564ea38a2af..551d9056e8a 100644 --- a/core/lib/spree/testing_support/factories/reimbursement_factory.rb +++ b/core/lib/spree/testing_support/factories/reimbursement_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :reimbursement, class: 'Spree::Reimbursement' do diff --git a/core/lib/spree/testing_support/factories/reimbursement_type_factory.rb b/core/lib/spree/testing_support/factories/reimbursement_type_factory.rb index 2c7a886e11d..97392c9ec64 100644 --- a/core/lib/spree/testing_support/factories/reimbursement_type_factory.rb +++ b/core/lib/spree/testing_support/factories/reimbursement_type_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :reimbursement_type, class: 'Spree::ReimbursementType' do diff --git a/core/lib/spree/testing_support/factories/return_authorization_factory.rb b/core/lib/spree/testing_support/factories/return_authorization_factory.rb index c1b7ca99a64..ae72203e08b 100644 --- a/core/lib/spree/testing_support/factories/return_authorization_factory.rb +++ b/core/lib/spree/testing_support/factories/return_authorization_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :return_authorization, class: 'Spree::ReturnAuthorization' do diff --git a/core/lib/spree/testing_support/factories/return_item_factory.rb b/core/lib/spree/testing_support/factories/return_item_factory.rb index a3fa75c3595..2fa40cee2f0 100644 --- a/core/lib/spree/testing_support/factories/return_item_factory.rb +++ b/core/lib/spree/testing_support/factories/return_item_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :return_item, class: 'Spree::ReturnItem' do diff --git a/core/lib/spree/testing_support/factories/return_reason_factory.rb b/core/lib/spree/testing_support/factories/return_reason_factory.rb index 2d02d4fe517..42a2c2a8ba8 100644 --- a/core/lib/spree/testing_support/factories/return_reason_factory.rb +++ b/core/lib/spree/testing_support/factories/return_reason_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :return_reason, class: 'Spree::ReturnReason' do diff --git a/core/lib/spree/testing_support/factories/role_factory.rb b/core/lib/spree/testing_support/factories/role_factory.rb index f0300f4d25f..d74596b859f 100644 --- a/core/lib/spree/testing_support/factories/role_factory.rb +++ b/core/lib/spree/testing_support/factories/role_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :role, class: 'Spree::Role' do diff --git a/core/lib/spree/testing_support/factories/shipment_factory.rb b/core/lib/spree/testing_support/factories/shipment_factory.rb index 92dd24c4230..4c64cd757a0 100644 --- a/core/lib/spree/testing_support/factories/shipment_factory.rb +++ b/core/lib/spree/testing_support/factories/shipment_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :shipment, class: 'Spree::Shipment' do diff --git a/core/lib/spree/testing_support/factories/shipping_category_factory.rb b/core/lib/spree/testing_support/factories/shipping_category_factory.rb index 7be4b6488ad..832f0ff78e9 100644 --- a/core/lib/spree/testing_support/factories/shipping_category_factory.rb +++ b/core/lib/spree/testing_support/factories/shipping_category_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :shipping_category, class: 'Spree::ShippingCategory' do diff --git a/core/lib/spree/testing_support/factories/shipping_method_factory.rb b/core/lib/spree/testing_support/factories/shipping_method_factory.rb index c4129f88605..4accd0bcdbf 100644 --- a/core/lib/spree/testing_support/factories/shipping_method_factory.rb +++ b/core/lib/spree/testing_support/factories/shipping_method_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory( diff --git a/core/lib/spree/testing_support/factories/shipping_rate_factory.rb b/core/lib/spree/testing_support/factories/shipping_rate_factory.rb index 8d024c47b99..42210137a1c 100644 --- a/core/lib/spree/testing_support/factories/shipping_rate_factory.rb +++ b/core/lib/spree/testing_support/factories/shipping_rate_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :shipping_rate, class: 'Spree::ShippingRate' do diff --git a/core/lib/spree/testing_support/factories/state_factory.rb b/core/lib/spree/testing_support/factories/state_factory.rb index 4bde1c3d1dd..ab62855edd1 100644 --- a/core/lib/spree/testing_support/factories/state_factory.rb +++ b/core/lib/spree/testing_support/factories/state_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :state, class: 'Spree::State' do diff --git a/core/lib/spree/testing_support/factories/stock_item_factory.rb b/core/lib/spree/testing_support/factories/stock_item_factory.rb index 96028fdbb4b..94a8d82fbf8 100644 --- a/core/lib/spree/testing_support/factories/stock_item_factory.rb +++ b/core/lib/spree/testing_support/factories/stock_item_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :stock_item, class: 'Spree::StockItem' do diff --git a/core/lib/spree/testing_support/factories/stock_location_factory.rb b/core/lib/spree/testing_support/factories/stock_location_factory.rb index 08eae8e970d..70e37b12c67 100644 --- a/core/lib/spree/testing_support/factories/stock_location_factory.rb +++ b/core/lib/spree/testing_support/factories/stock_location_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :stock_location, class: 'Spree::StockLocation' do diff --git a/core/lib/spree/testing_support/factories/stock_movement_factory.rb b/core/lib/spree/testing_support/factories/stock_movement_factory.rb index 83a974fcb70..e152d6efa43 100644 --- a/core/lib/spree/testing_support/factories/stock_movement_factory.rb +++ b/core/lib/spree/testing_support/factories/stock_movement_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :stock_movement, class: 'Spree::StockMovement' do diff --git a/core/lib/spree/testing_support/factories/stock_package_factory.rb b/core/lib/spree/testing_support/factories/stock_package_factory.rb index a9d09aceafa..e82ae97517e 100644 --- a/core/lib/spree/testing_support/factories/stock_package_factory.rb +++ b/core/lib/spree/testing_support/factories/stock_package_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :stock_package, class: 'Spree::Stock::Package' do diff --git a/core/lib/spree/testing_support/factories/store_credit_category_factory.rb b/core/lib/spree/testing_support/factories/store_credit_category_factory.rb index 4f74f12c0a6..760d1d62c43 100644 --- a/core/lib/spree/testing_support/factories/store_credit_category_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_category_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :store_credit_category, class: 'Spree::StoreCreditCategory' do diff --git a/core/lib/spree/testing_support/factories/store_credit_event_factory.rb b/core/lib/spree/testing_support/factories/store_credit_event_factory.rb index 6f1ee32ce42..ece410eb37c 100644 --- a/core/lib/spree/testing_support/factories/store_credit_event_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_event_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :store_credit_event, class: 'Spree::StoreCreditEvent' do diff --git a/core/lib/spree/testing_support/factories/store_credit_factory.rb b/core/lib/spree/testing_support/factories/store_credit_factory.rb index 3a0558b121c..d13ae95708f 100644 --- a/core/lib/spree/testing_support/factories/store_credit_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :store_credit, class: 'Spree::StoreCredit' do diff --git a/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb b/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb index af8160f1bb6..f5ae5c3b5d0 100644 --- a/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :store_credit_reason, class: 'Spree::StoreCreditReason' do diff --git a/core/lib/spree/testing_support/factories/store_credit_type_factory.rb b/core/lib/spree/testing_support/factories/store_credit_type_factory.rb index 9c2a685e375..e8e4eca3522 100644 --- a/core/lib/spree/testing_support/factories/store_credit_type_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_type_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :primary_credit_type, class: 'Spree::StoreCreditType' do diff --git a/core/lib/spree/testing_support/factories/store_factory.rb b/core/lib/spree/testing_support/factories/store_factory.rb index 29f44e79ed6..da2e8d4d89f 100644 --- a/core/lib/spree/testing_support/factories/store_factory.rb +++ b/core/lib/spree/testing_support/factories/store_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :store, class: 'Spree::Store' do diff --git a/core/lib/spree/testing_support/factories/tax_category_factory.rb b/core/lib/spree/testing_support/factories/tax_category_factory.rb index f537cfe95f6..c3146cc9057 100644 --- a/core/lib/spree/testing_support/factories/tax_category_factory.rb +++ b/core/lib/spree/testing_support/factories/tax_category_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :tax_category, class: 'Spree::TaxCategory' do diff --git a/core/lib/spree/testing_support/factories/tax_rate_factory.rb b/core/lib/spree/testing_support/factories/tax_rate_factory.rb index b98ff49e404..ebe9745b85c 100644 --- a/core/lib/spree/testing_support/factories/tax_rate_factory.rb +++ b/core/lib/spree/testing_support/factories/tax_rate_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :tax_rate, class: 'Spree::TaxRate' do diff --git a/core/lib/spree/testing_support/factories/taxon_factory.rb b/core/lib/spree/testing_support/factories/taxon_factory.rb index c8bb9440c89..6afe86a144f 100644 --- a/core/lib/spree/testing_support/factories/taxon_factory.rb +++ b/core/lib/spree/testing_support/factories/taxon_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :taxon, class: 'Spree::Taxon' do diff --git a/core/lib/spree/testing_support/factories/taxonomy_factory.rb b/core/lib/spree/testing_support/factories/taxonomy_factory.rb index aaccf84cb71..8563cfb8a41 100644 --- a/core/lib/spree/testing_support/factories/taxonomy_factory.rb +++ b/core/lib/spree/testing_support/factories/taxonomy_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :taxonomy, class: 'Spree::Taxonomy' do diff --git a/core/lib/spree/testing_support/factories/user_factory.rb b/core/lib/spree/testing_support/factories/user_factory.rb index 6f8de31b5a9..3d18f62e263 100644 --- a/core/lib/spree/testing_support/factories/user_factory.rb +++ b/core/lib/spree/testing_support/factories/user_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :user, class: Spree::UserClassHandle.new do diff --git a/core/lib/spree/testing_support/factories/variant_factory.rb b/core/lib/spree/testing_support/factories/variant_factory.rb index a982c3019dd..24005667199 100644 --- a/core/lib/spree/testing_support/factories/variant_factory.rb +++ b/core/lib/spree/testing_support/factories/variant_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do sequence(:random_float) { BigDecimal("#{rand(200)}.#{rand(99)}") } diff --git a/core/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb b/core/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb index 76f37386a88..93c81df2b4e 100644 --- a/core/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +++ b/core/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :variant_property_rule_condition, class: 'Spree::VariantPropertyRuleCondition' do diff --git a/core/lib/spree/testing_support/factories/variant_property_rule_factory.rb b/core/lib/spree/testing_support/factories/variant_property_rule_factory.rb index cfa4ef0e031..3f1f21b5719 100644 --- a/core/lib/spree/testing_support/factories/variant_property_rule_factory.rb +++ b/core/lib/spree/testing_support/factories/variant_property_rule_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :variant_property_rule, class: 'Spree::VariantPropertyRule' do diff --git a/core/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb b/core/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb index 90f1b845ed7..0718ceb0b54 100644 --- a/core/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +++ b/core/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :variant_property_rule_value, class: 'Spree::VariantPropertyRuleValue' do diff --git a/core/lib/spree/testing_support/factories/zone_factory.rb b/core/lib/spree/testing_support/factories/zone_factory.rb index caadc1cf6a1..0818d5568ee 100644 --- a/core/lib/spree/testing_support/factories/zone_factory.rb +++ b/core/lib/spree/testing_support/factories/zone_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/testing_support' -Spree::TestingSupport.deprecate_cherry_picking_factory_bot_files +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do factory :global_zone, class: 'Spree::Zone' do diff --git a/core/lib/spree/testing_support/factory_bot.rb b/core/lib/spree/testing_support/factory_bot.rb new file mode 100644 index 00000000000..9ec99721c0c --- /dev/null +++ b/core/lib/spree/testing_support/factory_bot.rb @@ -0,0 +1,48 @@ +require 'factory_bot' +begin + require 'factory_bot_rails' +rescue LoadError +end + +module Spree + module TestingSupport + module FactoryBot + SEQUENCES = ["#{::Spree::Core::Engine.root}/lib/spree/testing_support/sequences.rb"] + FACTORIES = Dir["#{::Spree::Core::Engine.root}/lib/spree/testing_support/factories/**/*_factory.rb"].sort + PATHS = SEQUENCES + FACTORIES + + def self.definition_file_paths + @paths ||= PATHS.map { |path| path.sub(/.rb\z/, '') } + end + + def self.deprecate_cherry_picking + # All good if the factory is being loaded by FactoryBot. + return if caller.find { |line| line.include? "/factory_bot/find_definitions.rb" } + + 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) + ) + end + + def self.check_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 + end + + def self.add_paths_and_load! + ::FactoryBot.definition_file_paths.unshift(*definition_file_paths).uniq! + ::FactoryBot.reload + end + end + end +end diff --git a/core/lib/spree/testing_support/sequences.rb b/core/lib/spree/testing_support/sequences.rb index f13c5f6cde5..db957b0ae23 100644 --- a/core/lib/spree/testing_support/sequences.rb +++ b/core/lib/spree/testing_support/sequences.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require 'factory_bot' +require 'spree/testing_support/factory_bot' +Spree::TestingSupport::FactoryBot.deprecate_cherry_picking FactoryBot.define do sequence(:sku) { |n| "SKU-#{n}" } diff --git a/core/spec/rails_helper.rb b/core/spec/rails_helper.rb index 8d7ce0a9e9e..f3b7fb5c1f8 100644 --- a/core/spec/rails_helper.rb +++ b/core/spec/rails_helper.rb @@ -24,7 +24,7 @@ ActiveJob::Base.queue_adapter = :test -Spree::TestingSupport.load_all_factories +Spree::TestingSupport::FactoryBot.add_paths_and_load! RSpec.configure do |config| config.fixture_path = File.join(__dir__, "fixtures") diff --git a/frontend/spec/spec_helper.rb b/frontend/spec/spec_helper.rb index b24397bdc7d..542301d56e1 100644 --- a/frontend/spec/spec_helper.rb +++ b/frontend/spec/spec_helper.rb @@ -49,7 +49,7 @@ ActiveJob::Base.queue_adapter = :test -Spree::TestingSupport.load_all_factories +Spree::TestingSupport::FactoryBot.add_paths_and_load! RSpec.configure do |config| config.color = true