diff --git a/spec/controllers/api/shipments_controller_spec.rb b/spec/controllers/api/shipments_controller_spec.rb index f4dba19f11..7c13fe3318 100644 --- a/spec/controllers/api/shipments_controller_spec.rb +++ b/spec/controllers/api/shipments_controller_spec.rb @@ -29,7 +29,7 @@ describe Api::ShipmentsController, type: :controller do let(:current_api_user) { build(:admin_user) } let!(:order) { shipment.order } let(:order_ship_address) { create(:address) } - let!(:stock_location) { create(:stock_location_with_items) } + let!(:stock_location) { Spree::StockLocation.first || create(:stock_location) } let!(:variant) { create(:variant) } let(:params) do { quantity: 2, diff --git a/spec/factories/product_factory.rb b/spec/factories/product_factory.rb index bf19b0717a..f13cad00ba 100644 --- a/spec/factories/product_factory.rb +++ b/spec/factories/product_factory.rb @@ -21,7 +21,7 @@ FactoryBot.define do shipping_category { DefaultShippingCategory.find_or_create } # ensure stock item will be created for this products master - before(:create) { DefaultStockLocation.find_or_create } + before(:create) { create(:stock_location) if Spree::StockLocation.count == 0 } factory :product do transient do diff --git a/spec/factories/shipment_factory.rb b/spec/factories/shipment_factory.rb index 64f84dfe3e..17d465ced1 100644 --- a/spec/factories/shipment_factory.rb +++ b/spec/factories/shipment_factory.rb @@ -9,7 +9,7 @@ FactoryBot.define do state 'pending' order address - stock_location { DefaultStockLocation.find_or_create } + stock_location { Spree::StockLocation.first || create(:stock_location) } after(:create) do |shipment, evalulator| shipment.add_shipping_method(create(:shipping_method), true) @@ -27,7 +27,7 @@ FactoryBot.define do state 'pending' order address - stock_location { DefaultStockLocation.find_or_create } + stock_location { Spree::StockLocation.first || create(:stock_location) } trait :shipping_method do transient do diff --git a/spec/factories/stock_location_factory.rb b/spec/factories/stock_location_factory.rb index 452176fae1..393baa1e7b 100644 --- a/spec/factories/stock_location_factory.rb +++ b/spec/factories/stock_location_factory.rb @@ -1,9 +1,8 @@ FactoryBot.define do factory :stock_location, class: Spree::StockLocation do # keeps the test stock_location unique - initialize_with { DefaultStockLocation.find_or_create } + initialize_with { Spree::StockLocation.first || DefaultStockLocation.find_or_create } - name 'NY Warehouse' address1 '1600 Pennsylvania Ave NW' city 'Washington' zipcode '20500' @@ -17,17 +16,5 @@ FactoryBot.define do 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 diff --git a/spec/models/spree/stock_item_spec.rb b/spec/models/spree/stock_item_spec.rb index 9c9b233986..ed634e854f 100644 --- a/spec/models/spree/stock_item_spec.rb +++ b/spec/models/spree/stock_item_spec.rb @@ -3,7 +3,15 @@ require 'spec_helper' RSpec.describe Spree::StockItem do - let(:stock_location) { create(:stock_location_with_items) } + let(:stock_location) { create(:stock_location) } + + before do + 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 subject { stock_location.stock_items.order(:id).first }