From ab99175bb401effc9f7ec8c7615a6db8f804f871 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 20 Nov 2017 22:35:08 -0800 Subject: [PATCH] Move factories into factories.rb --- lib/solidus_stock_transfers/factories.rb | 40 +++++++++++++++++-- .../factories/stock_transfer_factory.rb | 31 -------------- .../factories_spec.rb} | 1 - spec/spec_helper.rb | 4 +- 4 files changed, 38 insertions(+), 38 deletions(-) delete mode 100644 lib/spree/testing_support/factories/stock_transfer_factory.rb rename spec/lib/{spree/core/testing_support/factories/stock_transfer_factory_spec.rb => solidus_stock_transfers/factories_spec.rb} (78%) diff --git a/lib/solidus_stock_transfers/factories.rb b/lib/solidus_stock_transfers/factories.rb index 6e7ead5..67abff6 100644 --- a/lib/solidus_stock_transfers/factories.rb +++ b/lib/solidus_stock_transfers/factories.rb @@ -1,6 +1,38 @@ +require 'spree/testing_support/factories' + +# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them. +# +# Example adding this to your spec_helper will load these Factories for use: +# require 'solidus_stock_transfers/factories' + FactoryBot.define do - # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them. - # - # Example adding this to your spec_helper will load these Factories for use: - # require 'solidus_stock_transfers/factories' + sequence(:source_code) { |n| "SRC#{n}" } + sequence(:destination_code) { |n| "DEST#{n}" } + + factory :stock_transfer, class: 'Spree::StockTransfer' do + source_location { Spree::StockLocation.create!(name: "Source Location", code: generate(:source_code), admin_name: "Source") } + + factory :stock_transfer_with_items do + destination_location { Spree::StockLocation.create!(name: "Destination Location", code: generate(:destination_code), admin_name: "Destination") } + + after(:create) do |stock_transfer, _evaluator| + variant_1 = create(:variant) + variant_2 = create(:variant) + + variant_1.stock_items.find_by(stock_location: stock_transfer.source_location).set_count_on_hand(10) + variant_2.stock_items.find_by(stock_location: stock_transfer.source_location).set_count_on_hand(10) + + stock_transfer.transfer_items.create(variant: variant_1, expected_quantity: 5) + stock_transfer.transfer_items.create(variant: variant_2, expected_quantity: 5) + + stock_transfer.created_by = create(:admin_user) + stock_transfer.save! + end + + factory :receivable_stock_transfer_with_items do + finalized_at { Time.current } + shipped_at { Time.current } + end + end + end end diff --git a/lib/spree/testing_support/factories/stock_transfer_factory.rb b/lib/spree/testing_support/factories/stock_transfer_factory.rb deleted file mode 100644 index 6c3723a..0000000 --- a/lib/spree/testing_support/factories/stock_transfer_factory.rb +++ /dev/null @@ -1,31 +0,0 @@ -FactoryBot.define do - sequence(:source_code) { |n| "SRC#{n}" } - sequence(:destination_code) { |n| "DEST#{n}" } - - factory :stock_transfer, class: 'Spree::StockTransfer' do - source_location { Spree::StockLocation.create!(name: "Source Location", code: generate(:source_code), admin_name: "Source") } - - factory :stock_transfer_with_items do - destination_location { Spree::StockLocation.create!(name: "Destination Location", code: generate(:destination_code), admin_name: "Destination") } - - after(:create) do |stock_transfer, _evaluator| - variant_1 = create(:variant) - variant_2 = create(:variant) - - variant_1.stock_items.find_by(stock_location: stock_transfer.source_location).set_count_on_hand(10) - variant_2.stock_items.find_by(stock_location: stock_transfer.source_location).set_count_on_hand(10) - - stock_transfer.transfer_items.create(variant: variant_1, expected_quantity: 5) - stock_transfer.transfer_items.create(variant: variant_2, expected_quantity: 5) - - stock_transfer.created_by = create(:admin_user) - stock_transfer.save! - end - - factory :receivable_stock_transfer_with_items do - finalized_at { Time.current } - shipped_at { Time.current } - end - end - end -end diff --git a/spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb b/spec/lib/solidus_stock_transfers/factories_spec.rb similarity index 78% rename from spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb rename to spec/lib/solidus_stock_transfers/factories_spec.rb index 8a7e466..cc9882d 100644 --- a/spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb +++ b/spec/lib/solidus_stock_transfers/factories_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'spree/testing_support/factories/stock_transfer_factory' RSpec.describe 'stock transfer factory' do let(:factory_class) { Spree::StockTransfer } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ae62348..5739675 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,10 +14,10 @@ require 'cancan/matchers' require 'rspec/active_model/mocks' +require 'solidus_stock_transfers/factories' + Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f } RSpec.configure do |config| config.infer_spec_type_from_file_location! - - FactoryBot.find_definitions end