Skip to content

Commit

Permalink
Add spree current user to base cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
v10110 authored and damianlegawiec committed May 26, 2021
1 parent 27f69ed commit cb54344
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/app/helpers/spree/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def default_image_for_product_or_variant(product_or_variant)
end

def 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')]
end

def maximum_quantity
Expand Down
45 changes: 45 additions & 0 deletions core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,51 @@ def link_to_tracking_html(options = {})
end
end

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 #2396
context 'meta_data_tags' do
it 'truncates a product description to 160 characters' do
Expand Down

0 comments on commit cb54344

Please sign in to comment.