diff --git a/backend/spec/features/admin/products/edit/images_spec.rb b/backend/spec/features/admin/products/edit/images_spec.rb index 1ff20b4ab19..d885bacb37b 100644 --- a/backend/spec/features/admin/products/edit/images_spec.rb +++ b/backend/spec/features/admin/products/edit/images_spec.rb @@ -78,7 +78,7 @@ end click_button "Update" - Spree::Image.first.attachment.blob.update(key: 11) + invalidate_attachment(Spree::Image.first.attachment) visit current_path expect(page).to have_xpath("//img[contains(@src, 'assets/noimage/mini')]") end @@ -136,4 +136,12 @@ expect(page).to have_css("thead th", count: 4) end end + + def invalidate_attachment(attachment) + blob = attachment.blob + blob.variant_records.each do |variant_record| + variant_record.update(variation_digest: SecureRandom.uuid) + end + blob.update(key: SecureRandom.uuid) + end end diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 4443f97f9e8..72f7bc57d80 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -490,7 +490,10 @@ def create_proposed_shipments raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_shipments_not_pending')) else shipments.destroy_all - self.shipments = Spree::Config.stock.coordinator_class.new(self).shipments + # TODO: We can use `self.shipments#=` instead of `#push` when + # https://github.com/rails/rails/issues/42102 is fixed and we deprecate + # Rails versions with the bug + shipments.push(*Spree::Config.stock.coordinator_class.new(self).shipments) end end diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 6928b3f4af7..3a99482bced 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -45,7 +45,6 @@ class Product < Spree::Base has_many :variants, -> { where(is_master: false).order(:position) }, - inverse_of: :product, class_name: 'Spree::Variant' has_many :variants_including_master, diff --git a/core/app/models/spree/stock/simple_coordinator.rb b/core/app/models/spree/stock/simple_coordinator.rb index 6b0fe0d5786..e7fcce67236 100644 --- a/core/app/models/spree/stock/simple_coordinator.rb +++ b/core/app/models/spree/stock/simple_coordinator.rb @@ -73,11 +73,16 @@ def build_shipments packages = split_packages(packages) # Turn the Stock::Packages into a Shipment with rates - packages.map do |package| + shipments = packages.map do |package| shipment = package.shipment = package.to_shipment shipment.shipping_rates = Spree::Config.stock.estimator_class.new.shipping_rates(package) shipment end + + # Make sure we don't add the proposed shipments to the order + order.shipments = order.shipments - shipments + + shipments end def split_packages(initial_packages) diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb index 591239bc914..a51d408e4ef 100644 --- a/core/app/models/spree/variant.rb +++ b/core/app/models/spree/variant.rb @@ -30,7 +30,7 @@ class Variant < Spree::Base attr_writer :rebuild_vat_prices include Spree::DefaultPrice - belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants, optional: false + belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants_including_master, optional: false belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true delegate :name, :description, :slug, :available_on, :discontinue_on, :discontinued?, diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index b96ce9652c6..104139fe21e 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -46,6 +46,7 @@ def self.setup(gem_root:, lib_name:, auto_migrate: true) end class Application < ::Rails::Application + config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}") config.eager_load = false config.cache_classes = true config.cache_store = :memory_store diff --git a/core/spec/lib/search/variant_spec.rb b/core/spec/lib/search/variant_spec.rb index 5c778417bfb..8d210e1d81c 100644 --- a/core/spec/lib/search/variant_spec.rb +++ b/core/spec/lib/search/variant_spec.rb @@ -59,6 +59,7 @@ def refute_found(query_string, variant) described_class.new(variant.sku, scope: Spree::Variant.in_stock).results ).to include variant + variant.stock_items.reload # See https://github.com/rails/rails/issues/42094 variant.stock_items.each { |si| si.set_count_on_hand(0) } expect( described_class.new(variant.sku, scope: Spree::Variant.in_stock).results diff --git a/core/spec/lib/spree/core/testing_support/dummy_app_spec.rb b/core/spec/lib/spree/core/testing_support/dummy_app_spec.rb new file mode 100644 index 00000000000..953947ffa5e --- /dev/null +++ b/core/spec/lib/spree/core/testing_support/dummy_app_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe DummyApp do + it 'loads default from the Rails version in use' do + expect( + DummyApp::Application.config.loaded_config_version + ).to eq("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}") + end +end diff --git a/core/spec/models/spree/adjustment_spec.rb b/core/spec/models/spree/adjustment_spec.rb index 5720d053f38..b50af5ac879 100644 --- a/core/spec/models/spree/adjustment_spec.rb +++ b/core/spec/models/spree/adjustment_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Spree::Adjustment, type: :model do let!(:store) { create :store } - let(:order) { Spree::Order.new } + let(:order) { create :order } let(:line_item) { create :line_item, order: order } let(:adjustment) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: order, order: order, amount: 5) } @@ -43,7 +43,7 @@ end context '#currency' do - let(:order) { Spree::Order.new currency: 'JPY' } + let(:order) { create :order, currency: 'JPY' } it 'returns the adjustables currency' do expect(adjustment.currency).to eq 'JPY' @@ -67,7 +67,7 @@ end context "with currency set to JPY" do - let(:order) { Spree::Order.new currency: 'JPY' } + let(:order) { create :order, currency: 'JPY' } context "when adjustable is set to an order" do it "displays in JPY" do diff --git a/core/spec/models/spree/order_contents_spec.rb b/core/spec/models/spree/order_contents_spec.rb index 9bfa2e8b744..dc18f2030e0 100644 --- a/core/spec/models/spree/order_contents_spec.rb +++ b/core/spec/models/spree/order_contents_spec.rb @@ -25,7 +25,7 @@ it "ensure shipment calls update_amounts instead of order calling ensure_updated_shipments" do expect(subject.order).to_not receive(:ensure_updated_shipments) - expect(shipment).to receive(:update_amounts) + expect(shipment).to receive(:update_amounts).at_least(:once) subject.add(variant, 1, shipment: shipment) end diff --git a/core/spec/models/spree/payment_spec.rb b/core/spec/models/spree/payment_spec.rb index 2a5a2125425..e38a7a832ff 100644 --- a/core/spec/models/spree/payment_spec.rb +++ b/core/spec/models/spree/payment_spec.rb @@ -8,7 +8,7 @@ let(:refund_reason) { create(:refund_reason) } let(:gateway) do - gateway = Spree::PaymentMethod::BogusCreditCard.new(active: true, name: 'Bogus gateway') + gateway = Spree::PaymentMethod::BogusCreditCard.create!(active: true, name: 'Bogus gateway') allow(gateway).to receive_messages(source_required?: true) gateway end diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb index 6b66a753b4b..cac6c32b703 100644 --- a/core/spec/models/spree/product_spec.rb +++ b/core/spec/models/spree/product_spec.rb @@ -129,7 +129,7 @@ class Extension < Spree::Base it "should set deleted_at value" do product.discard expect(product.deleted_at).not_to be_nil - expect(product.variants_including_master).to all(be_discarded) + expect(product.variants_including_master.reload).to all(be_discarded) end end end diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb index 2e1e5a39a12..55ed9e45e89 100644 --- a/core/spec/models/spree/variant_spec.rb +++ b/core/spec/models/spree/variant_spec.rb @@ -616,7 +616,7 @@ variant.discard expect(variant.images).to be_empty - expect(variant.stock_items).to be_empty + expect(variant.stock_items.reload).to be_empty expect(variant.prices).to be_empty expect(variant.currently_valid_prices).to be_empty end diff --git a/frontend/spec/features/taxons_spec.rb b/frontend/spec/features/taxons_spec.rb index 53721ddf727..cd01d20db38 100644 --- a/frontend/spec/features/taxons_spec.rb +++ b/frontend/spec/features/taxons_spec.rb @@ -4,9 +4,9 @@ describe "viewing products", type: :feature, inaccessible: true do let!(:taxonomy) { create(:taxonomy, name: "Category") } - let!(:super_clothing) { taxonomy.root.children.create(name: "Super Clothing") } - let!(:t_shirts) { super_clothing.children.create(name: "T-Shirts") } - let!(:xxl) { t_shirts.children.create(name: "XXL") } + let!(:super_clothing) { taxonomy.root.children.create!(name: "Super Clothing", taxonomy: taxonomy) } + let!(:t_shirts) { super_clothing.children.create!(name: "T-Shirts", taxonomy: taxonomy) } + let!(:xxl) { t_shirts.children.create!(name: "XXL", taxonomy: taxonomy) } let!(:product) do product = create(:product, name: "Superman T-Shirt") product.taxons << t_shirts