diff --git a/spec/factories/stock_location_factory.rb b/spec/factories/stock_location_factory.rb index 48fc14d772..f348788700 100644 --- a/spec/factories/stock_location_factory.rb +++ b/spec/factories/stock_location_factory.rb @@ -18,5 +18,17 @@ 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 6dccf13665..9c9b233986 100644 --- a/spec/models/spree/stock_item_spec.rb +++ b/spec/models/spree/stock_item_spec.rb @@ -3,15 +3,7 @@ require 'spec_helper' RSpec.describe Spree::StockItem do - 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 + let(:stock_location) { create(:stock_location_with_items) } subject { stock_location.stock_items.order(:id).first }