From 64608beaa8b093e005418bde3f85f695354d046f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 22 Jan 2025 12:01:57 +1100 Subject: [PATCH] Remove DefaultStockLocation created in setup --- app/models/concerns/variant_stock.rb | 9 ----- app/services/default_stock_location.rb | 11 ------ db/seeds.rb | 1 - .../services/supplied_product_builder_spec.rb | 3 -- spec/factories/product_factory.rb | 3 -- spec/factories/variant_factory.rb | 3 -- spec/lib/tasks/sample_data_rake_spec.rb | 1 - spec/services/default_stock_location_spec.rb | 39 ------------------- 8 files changed, 70 deletions(-) delete mode 100644 app/services/default_stock_location.rb delete mode 100644 spec/services/default_stock_location_spec.rb diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb index d3837a1ce5..7489aa5893 100644 --- a/app/models/concerns/variant_stock.rb +++ b/app/models/concerns/variant_stock.rb @@ -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 diff --git a/app/services/default_stock_location.rb b/app/services/default_stock_location.rb deleted file mode 100644 index fb58f537d1..0000000000 --- a/app/services/default_stock_location.rb +++ /dev/null @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 9192a35e61..70512b1463 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 diff --git a/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb b/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb index 8c307fe5a5..bd222af048 100644 --- a/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb +++ b/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb @@ -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) diff --git a/spec/factories/product_factory.rb b/spec/factories/product_factory.rb index 453a442be4..3d3dafeb53 100644 --- a/spec/factories/product_factory.rb +++ b/spec/factories/product_factory.rb @@ -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 } diff --git a/spec/factories/variant_factory.rb b/spec/factories/variant_factory.rb index 1aed03f183..38560acd81 100644 --- a/spec/factories/variant_factory.rb +++ b/spec/factories/variant_factory.rb @@ -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 } diff --git a/spec/lib/tasks/sample_data_rake_spec.rb b/spec/lib/tasks/sample_data_rake_spec.rb index 4fa798e53a..f16a1e3be0 100644 --- a/spec/lib/tasks/sample_data_rake_spec.rb +++ b/spec/lib/tasks/sample_data_rake_spec.rb @@ -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 diff --git a/spec/services/default_stock_location_spec.rb b/spec/services/default_stock_location_spec.rb deleted file mode 100644 index 93b0a053f7..0000000000 --- a/spec/services/default_stock_location_spec.rb +++ /dev/null @@ -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