From 313e6e2b459a29ebcc4e020401f8ccb08f7f2b55 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sun, 23 Aug 2020 13:23:48 +0100 Subject: [PATCH] Bring stock_location factory from spree_core and merge with modification --- spec/factories.rb | 11 -------- spec/factories/stock_location_factory.rb | 36 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 spec/factories/stock_location_factory.rb diff --git a/spec/factories.rb b/spec/factories.rb index 8337e48a0c..de7cc38a07 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -162,17 +162,6 @@ FactoryBot.define do end FactoryBot.modify do - factory :stock_location, class: Spree::StockLocation do - # keeps the test stock_location unique - initialize_with { DefaultStockLocation.find_or_create } - - # Ensures the name attribute is not assigned after instantiating the default location - transient { name 'default' } - - # sets the default value for variant.on_demand - backorderable_default false - end - factory :shipping_category, class: Spree::ShippingCategory do initialize_with { DefaultShippingCategory.find_or_create } transient { name 'Default' } diff --git a/spec/factories/stock_location_factory.rb b/spec/factories/stock_location_factory.rb new file mode 100644 index 0000000000..4a37ff9a5d --- /dev/null +++ b/spec/factories/stock_location_factory.rb @@ -0,0 +1,36 @@ +FactoryGirl.define do + factory :stock_location, class: Spree::StockLocation do + # Ensures the name attribute is not assigned after instantiating the default location + transient { name 'default' } + + # keeps the test stock_location unique + initialize_with { DefaultStockLocation.find_or_create } + + name 'NY Warehouse' + address1 '1600 Pennsylvania Ave NW' + city 'Washington' + zipcode '20500' + phone '(202) 456-1111' + active true + + # sets the default value for variant.on_demand + backorderable_default false + + country { |stock_location| Spree::Country.first || stock_location.association(:country) } + state do |stock_location| + stock_location.country.states.first || stock_location.association(:state, :country => stock_location.country) + end + + factory :stock_location_with_items do + after(:create) do |stock_location, evaluator| + # variant will add itself to all stock_locations in an after_create + # creating a product will automatically create a master variant + product_1 = create(:product) + product_2 = create(:product) + + stock_location.stock_items.where(:variant_id => product_1.master.id).first.adjust_count_on_hand(10) + stock_location.stock_items.where(:variant_id => product_2.master.id).first.adjust_count_on_hand(20) + end + end + end +end