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
Add spree current user to base cache key
v10110853926f62b97
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex 5152bfce06..00b0e0c75c 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -183,7 +183,8 @@ module Spreeenddef base_cache_key- [I18n.locale, current_currency]+ [I18n.locale, current_currency, defined?(try_spree_current_user) && try_spree_current_user.present?,+ defined?(try_spree_current_user) && try_spree_current_user.try(:has_spree_role?, 'admin')]enddef maximum_quantitydiff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rbindex b6c02d2e48..8f6f09292e 100644--- a/core/spec/helpers/base_helper_spec.rb+++ b/core/spec/helpers/base_helper_spec.rb@@ -128,6 +128,51 @@ describe Spree::BaseHelper, type: :helper doendend+ context 'base_cache_key' do+ let(:current_currency) { 'USD' }++ context 'when try_spree_current_user defined' do+ before do+ I18n.locale = I18n.default_locale+ allow_any_instance_of(described_class).to receive(:try_spree_current_user).and_return(user)+ end++ context 'when admin user' do+ let!(:user) { create(:admin_user) }++ it 'returns base cache key' do+ expect(base_cache_key).to eq [:en, 'USD', true, true]+ end+ end++ context 'when user without admin role' do+ let!(:user) { create(:user) }++ it 'returns base cache key' do+ expect(base_cache_key).to eq [:en, 'USD', true, false]+ end+ end++ context 'when spree_current_user is nil' do+ let!(:user) { nil }++ it 'returns base cache key' do+ expect(base_cache_key).to eq [:en, 'USD', false, nil]+ end+ end+ end++ context 'when try_spree_current_user is undefined' do+ let(:current_currency) { 'USD' }++ before { I18n.locale = I18n.default_locale }++ it 'returns base cache key' do+ expect(base_cache_key).to eq [:en, 'USD', nil, nil]+ end+ end+ end+# Regression test for #2396context 'meta_data_tags' doit 'truncates a product description to 160 characters' do