From 70ebe7b964f273c6070991e2c4ffdf1a319ce0e3 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 22 Jan 2025 11:51:42 +1100 Subject: [PATCH] Remove stock location from specs --- .rubocop_todo.yml | 1 - .../spree/admin/products_controller_spec.rb | 1 - spec/factories/stock_location_factory.rb | 33 ------------------- spec/models/spree/inventory_unit_spec.rb | 6 ++-- spec/models/spree/product_spec.rb | 4 --- spec/models/spree/stock_item_spec.rb | 4 +-- spec/models/spree/stock_movement_spec.rb | 3 +- spec/services/sets/product_set_spec.rb | 1 - spec/system/admin/products_spec.rb | 1 - spec/system/admin/products_v3/create_spec.rb | 1 - spec/system/admin/unit_price_spec.rb | 2 -- 11 files changed, 4 insertions(+), 53 deletions(-) delete mode 100644 spec/factories/stock_location_factory.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 92432aae32..cacc26fc1c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -339,7 +339,6 @@ Naming/VariableNumber: - 'app/models/preference_sections/main_links_section.rb' - 'lib/spree/core/controller_helpers/common.rb' - 'spec/controllers/spree/admin/search_controller_spec.rb' - - 'spec/factories/stock_location_factory.rb' - 'spec/models/spree/stock_item_spec.rb' - 'spec/models/spree/tax_rate_spec.rb' - 'spec/requests/api/orders_spec.rb' diff --git a/spec/controllers/spree/admin/products_controller_spec.rb b/spec/controllers/spree/admin/products_controller_spec.rb index deae56bd80..f6f14206ab 100644 --- a/spec/controllers/spree/admin/products_controller_spec.rb +++ b/spec/controllers/spree/admin/products_controller_spec.rb @@ -142,7 +142,6 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do before do controller_login_as_admin - create(:stock_location) end it "redirects to products when the user hits 'create'" do diff --git a/spec/factories/stock_location_factory.rb b/spec/factories/stock_location_factory.rb deleted file mode 100644 index 37d43d7237..0000000000 --- a/spec/factories/stock_location_factory.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :stock_location, class: Spree::StockLocation do - # keeps the test stock_location unique - initialize_with { Spree::StockLocation.first || DefaultStockLocation.find_or_create } - - address1 { '1600 Pennsylvania Ave NW' } - city { 'Washington' } - zipcode { '20500' } - phone { '(202) 456-1111' } - - country { |stock_location| Spree::Country.first || stock_location.association(:country) } - 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) - - Spree::StockItem.where(variant_id: product_1.variants.first.id) - .first.adjust_count_on_hand(10) - Spree::StockItem.where(variant_id: product_2.variants.first.id) - .first.adjust_count_on_hand(20) - end - end - end -end diff --git a/spec/models/spree/inventory_unit_spec.rb b/spec/models/spree/inventory_unit_spec.rb index 9d4053ad18..8a755fa6d6 100644 --- a/spec/models/spree/inventory_unit_spec.rb +++ b/spec/models/spree/inventory_unit_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' RSpec.describe Spree::InventoryUnit do - let!(:stock_location) { create(:stock_location_with_items) } - let(:stock_item) { Spree::StockItem.order(:id).first } + let(:variant) { create(:variant) } + let(:stock_item) { variant.stock_item } context "variants deleted" do let!(:unit) do @@ -18,8 +18,6 @@ RSpec.describe Spree::InventoryUnit do end context "#finalize_units!" do - let!(:stock_location) { create(:stock_location) } - let(:variant) { create(:variant) } let(:inventory_units) { [ create(:inventory_unit, variant:), diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 26fef88569..9f9937f897 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -130,10 +130,6 @@ module Spree let!(:taxon){ create(:taxon) } let(:supplier){ create(:enterprise) } - before do - create(:stock_location) - end - it "copies properties to the first standard variant" do product.primary_taxon_id = taxon.id product.name = "Product1" diff --git a/spec/models/spree/stock_item_spec.rb b/spec/models/spree/stock_item_spec.rb index fd3f74965f..9268c04b18 100644 --- a/spec/models/spree/stock_item_spec.rb +++ b/spec/models/spree/stock_item_spec.rb @@ -3,9 +3,7 @@ require 'spec_helper' RSpec.describe Spree::StockItem do - let!(:stock_location) { create(:stock_location_with_items) } - - subject(:stock_item) { Spree::StockItem.order(:id).first } + subject(:stock_item) { create(:variant, on_hand: 15).stock_item } describe "validation" do it "requires count_on_hand to be positive if not backorderable" do diff --git a/spec/models/spree/stock_movement_spec.rb b/spec/models/spree/stock_movement_spec.rb index 235f542db2..02f4f4c543 100644 --- a/spec/models/spree/stock_movement_spec.rb +++ b/spec/models/spree/stock_movement_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' RSpec.describe Spree::StockMovement do - let!(:stock_location) { create(:stock_location_with_items) } - let(:stock_item) { Spree::StockItem.order(:id).first } + let(:stock_item) { create(:variant, on_hand: 15).stock_item } subject { build(:stock_movement, stock_item:) } it 'should belong to a stock item' do diff --git a/spec/services/sets/product_set_spec.rb b/spec/services/sets/product_set_spec.rb index d415f7096d..f6b28a5fc1 100644 --- a/spec/services/sets/product_set_spec.rb +++ b/spec/services/sets/product_set_spec.rb @@ -10,7 +10,6 @@ RSpec.describe Sets::ProductSet do subject{ product_set.save } context 'when the product does not exist yet' do - let!(:stock_location) { create(:stock_location) } let(:collection_hash) do { 0 => { diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index f2a1c322f3..8f10416261 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -11,7 +11,6 @@ RSpec.describe ' include FileHelper let!(:taxon) { create(:taxon) } - let!(:stock_location) { create(:stock_location) } let!(:shipping_category) { DefaultShippingCategory.find_or_create } let!(:supplier) { create(:supplier_enterprise, name: 'New supplier') } diff --git a/spec/system/admin/products_v3/create_spec.rb b/spec/system/admin/products_v3/create_spec.rb index e767ab3891..d2af1c8899 100644 --- a/spec/system/admin/products_v3/create_spec.rb +++ b/spec/system/admin/products_v3/create_spec.rb @@ -13,7 +13,6 @@ RSpec.describe 'As an enterprise user, I can manage my products' do let!(:taxon) { create(:taxon) } describe "creating a new product" do - let!(:stock_location) { create(:stock_location) } let!(:distributor) { create(:distributor_enterprise) } let!(:shipping_category) { create(:shipping_category) } diff --git a/spec/system/admin/unit_price_spec.rb b/spec/system/admin/unit_price_spec.rb index eb64b11172..5ad5b4fc7c 100644 --- a/spec/system/admin/unit_price_spec.rb +++ b/spec/system/admin/unit_price_spec.rb @@ -9,8 +9,6 @@ RSpec.describe ' include AuthenticationHelper include WebHelper - let!(:stock_location) { create(:stock_location) } - describe "product" do it "creating a new product" do login_as_admin