Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Raise RecordNotFound it no `current_store` (#12893)
Damian Legawiec0a580af0b96f
diff --git a/core/lib/spree/core/controller_helpers/store.rb b/core/lib/spree/core/controller_helpers/store.rbindex ac0837d308..de35685f49 100644--- a/core/lib/spree/core/controller_helpers/store.rb+++ b/core/lib/spree/core/controller_helpers/store.rb@@ -9,6 +9,8 @@ module Spreehelper_method :current_storehelper_method :current_price_optionsend++ prepend_before_action :raise_record_not_found_if_store_is_not_foundenddef current_store@@ -16,7 +18,7 @@ module Spreeenddef store_locale- current_store.default_locale+ @store_locale ||= current_store.default_localeenddef ensure_current_store(object)@@ -64,6 +66,10 @@ module Spreedef current_store_finderSpree::Dependencies.current_store_finder.constantizeend++ def raise_record_not_found_if_store_is_not_found+ raise ActiveRecord::RecordNotFound if current_store.nil?+ endendendenddiff --git a/core/spec/lib/spree/core/controller_helpers/store_spec.rb b/core/spec/lib/spree/core/controller_helpers/store_spec.rbindex 89f9042d06..d7a8b08ed2 100644--- a/core/spec/lib/spree/core/controller_helpers/store_spec.rb+++ b/core/spec/lib/spree/core/controller_helpers/store_spec.rb@@ -189,4 +189,16 @@ describe Spree::Core::ControllerHelpers::Store, type: :controller doendendend++ describe '#raise_record_not_found_if_store_is_not_found' do+ context 'when the store is not found' do+ before do+ allow(controller).to receive(:current_store).and_return(nil)+ end++ it 'raises an exception' do+ expect { controller.send(:raise_record_not_found_if_store_is_not_found) }.to raise_error(ActiveRecord::RecordNotFound)+ end+ end+ endend