Simplify stock location factory and fix related issues in several factories

This commit is contained in:
Luis Ramos
2020-08-23 16:03:39 +01:00
parent 4de4cc642d
commit f6277416ce
5 changed files with 14 additions and 19 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 }