mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
Remove DefaultStockLocation created in setup
This commit is contained in:
@@ -78,11 +78,6 @@ module VariantStock
|
||||
on_demand || total_on_hand >= quantity
|
||||
end
|
||||
|
||||
# Moving Spree::StockLocation.fill_status to the variant enables us
|
||||
# to override this behaviour for variant overrides
|
||||
# We can have this responsibility here in the variant because there is
|
||||
# only one stock item per variant
|
||||
#
|
||||
# Here we depend only on variant.total_on_hand and variant.on_demand.
|
||||
# This way, variant_overrides only need to override variant.total_on_hand and variant.on_demand.
|
||||
def fill_status(quantity)
|
||||
@@ -107,10 +102,6 @@ module VariantStock
|
||||
raise_error_if_no_stock_item_available
|
||||
|
||||
# Creates a stock movement: it updates stock_item.count_on_hand and fills backorders
|
||||
#
|
||||
# This is the original Spree::StockLocation#move,
|
||||
# except that we raise an error if the stock item is missing,
|
||||
# because, unlike Spree, we should always have exactly one stock item per variant.
|
||||
stock_item.stock_movements.create!(quantity:, originator:)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Encapsulates the concept of default stock location that OFN has, as explained
|
||||
# in https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-Upgrade%3A-Stock-locations
|
||||
class DefaultStockLocation
|
||||
NAME = 'default'
|
||||
|
||||
def self.find_or_create
|
||||
Spree::StockLocation.find_or_create_by(name: NAME)
|
||||
end
|
||||
end
|
||||
@@ -30,5 +30,4 @@ require File.join(File.dirname(__FILE__), 'default', 'zones')
|
||||
Rails.logger.info "[db:seed] Seeding Users"
|
||||
require File.join(File.dirname(__FILE__), 'default', 'users')
|
||||
|
||||
DefaultStockLocation.find_or_create
|
||||
DefaultShippingCategory.find_or_create
|
||||
|
||||
@@ -222,9 +222,6 @@ RSpec.describe SuppliedProductBuilder do
|
||||
}
|
||||
|
||||
it "creates a new Spree::Product and variant" do
|
||||
# We need this to save stock:
|
||||
DefaultStockLocation.find_or_create
|
||||
|
||||
create(:taxon)
|
||||
|
||||
expect(imported_variant).to be_a(Spree::Variant)
|
||||
|
||||
@@ -23,9 +23,6 @@ FactoryBot.define do
|
||||
variant_unit { 'weight' }
|
||||
variant_unit_scale { 1 }
|
||||
|
||||
# ensure stock item will be created for this products master
|
||||
before(:create) { DefaultStockLocation.find_or_create }
|
||||
|
||||
factory :product do
|
||||
transient do
|
||||
on_hand { 5 }
|
||||
|
||||
@@ -28,9 +28,6 @@ FactoryBot.define do
|
||||
# create a "standard variant"
|
||||
product { association :base_product }
|
||||
|
||||
# ensure stock item will be created for this variant
|
||||
before(:create) { DefaultStockLocation.find_or_create }
|
||||
|
||||
factory :variant do
|
||||
transient do
|
||||
on_demand { false }
|
||||
|
||||
@@ -12,7 +12,6 @@ RSpec.describe 'sample_data.rake' do
|
||||
before do
|
||||
# Create seed data required by the sample data.
|
||||
create(:user)
|
||||
DefaultStockLocation.find_or_create
|
||||
DefaultShippingCategory.find_or_create
|
||||
end
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe DefaultStockLocation do
|
||||
describe '.find_or_create' do
|
||||
context 'when a location named default already exists' do
|
||||
let!(:location) do
|
||||
country = create(:country)
|
||||
state = Spree::State.create(name: 'Alabama', country:)
|
||||
Spree::StockLocation.create!(
|
||||
name: 'default',
|
||||
country_id: country.id,
|
||||
state_id: state.id
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns the location' do
|
||||
expect(described_class.find_or_create).to eq(location)
|
||||
end
|
||||
|
||||
it 'does not create any other location' do
|
||||
expect { described_class.find_or_create }.not_to change { Spree::StockLocation.count }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a location named default does not exist' do
|
||||
it 'returns the location' do
|
||||
location = described_class.find_or_create
|
||||
expect(location.name).to eq('default')
|
||||
end
|
||||
|
||||
it 'does not create any other location' do
|
||||
expect { described_class.find_or_create }
|
||||
.to change { Spree::StockLocation.count }.from(0).to(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user