-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support different cache keys for signed/not-signed/admin users when v…
…iewing Storefront cached pages
- Loading branch information
1 parent
24152ef
commit f7fffbf
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::StoreController, type: :controller do | ||
describe '#store_etag' do | ||
let!(:store) { create(:store, default: true, default_locale: 'es', default_currency: 'EUR') } | ||
|
||
before { controller.send(:set_locale) } | ||
|
||
context 'guest visitor' do | ||
it do | ||
expect(controller.send(:store_etag)).to eq [ | ||
store, | ||
'EUR', | ||
:es, | ||
false | ||
] | ||
end | ||
end | ||
|
||
context 'with signed in user' do | ||
let(:user) { stub_model(Spree::LegacyUser) } | ||
|
||
before do | ||
allow(controller).to receive_messages try_spree_current_user: user | ||
allow(controller).to receive_messages spree_current_user: user | ||
end | ||
|
||
context 'regular user' do | ||
it do | ||
expect(controller.send(:store_etag)).to eq [ | ||
store, | ||
'EUR', | ||
:es, | ||
true, | ||
false | ||
] | ||
end | ||
end | ||
|
||
context 'admin user' do | ||
before { user.spree_roles << Spree::Role.find_or_create_by(name: :admin) } | ||
|
||
it do | ||
expect(controller.send(:store_etag)).to eq [ | ||
store, | ||
'EUR', | ||
:es, | ||
true, | ||
true | ||
] | ||
end | ||
end | ||
end | ||
end | ||
end |