mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Simplify stock location factory and fix related issues in several factories
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user