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
Fixed HTTP caching spec, simplify guest check
Damian Legawiec4bcd3030616e
diff --git a/api/app/controllers/concerns/spree/api/v3/http_caching.rb b/api/app/controllers/concerns/spree/api/v3/http_caching.rbindex d080002a71..98815d26f1 100644--- a/api/app/controllers/concerns/spree/api/v3/http_caching.rb+++ b/api/app/controllers/concerns/spree/api/v3/http_caching.rb@@ -19,7 +19,7 @@ module Spree# Check if the current user is a guest (no authentication)def guest_user?- current_user.nil? || current_user.try(:guest?)+ current_user.nil?end# Set Vary headers to ensure proper CDN caching by currency/localediff --git a/api/spec/controllers/spree/api/v3/http_caching_spec.rb b/api/spec/controllers/spree/api/v3/http_caching_spec.rbindex ceafe4aa7b..6534451e7a 100644--- a/api/spec/controllers/spree/api/v3/http_caching_spec.rb+++ b/api/spec/controllers/spree/api/v3/http_caching_spec.rb@@ -3,26 +3,34 @@ require 'spec_helper'class HttpCachingTestController < ActionController::APIinclude Spree::Api::V3::HttpCaching- attr_accessor :current_user+ attr_accessor :current_user, :_current_currency, :_current_localedef current_currency- 'USD'+ _current_currency || 'USD'enddef current_locale- 'en'+ _current_locale || 'en'endenddescribe Spree::Api::V3::HttpCaching, type: :controller dolet(:controller) { HttpCachingTestController.new }- let(:request) { instance_double(ActionDispatch::Request) }+ let(:request) { ActionDispatch::Request.new({}) }let(:response) { ActionDispatch::Response.new }before doallow(controller).to receive(:request).and_return(request)allow(controller).to receive(:response).and_return(response)allow(controller).to receive(:params).and_return(ActionController::Parameters.new(params))+ # Stub expires_in to set Cache-Control header directly+ allow(controller).to receive(:expires_in) do |duration, options = {}|+ parts = []+ parts << 'public' if options[:public]+ parts << "max-age=#{duration.to_i}"+ parts << "stale-while-revalidate=#{options[:stale_while_revalidate].to_i}" if options[:stale_while_revalidate]+ response.headers['Cache-Control'] = parts.join(', ')+ endendlet(:params) { {} }@@ -45,16 +53,6 @@ describe Spree::Api::V3::HttpCaching, type: :controller doexpect(controller.send(:guest_user?)).to be falseendend-- context 'when current_user responds to guest? and returns true' do- let(:user) { double('User', guest?: true) }-- before { controller.current_user = user }-- it 'returns true' do- expect(controller.send(:guest_user?)).to be true- end- endenddescribe '#set_vary_headers' do@@ -68,7 +66,8 @@ describe Spree::Api::V3::HttpCaching, type: :controller doit 'does not set Cache-Control to private' docontroller.send(:set_vary_headers)- expect(response.headers['Cache-Control']).not_to include('private')+ cache_control = response.headers['Cache-Control']+ expect(cache_control.nil? || !cache_control.include?('private')).to be trueendend@@ -159,7 +158,8 @@ describe Spree::Api::V3::HttpCaching, type: :controller doit 'does not set public Cache-Control' docontroller.send(:cache_collection, collection)- expect(response.headers['Cache-Control']).not_to include('public')+ cache_control = response.headers['Cache-Control']+ expect(cache_control.nil? || !cache_control.include?('public')).to be trueendendend@@ -274,7 +274,7 @@ describe Spree::Api::V3::HttpCaching, type: :controller docontext 'with different currencies' dobefore do- allow(controller).to receive(:current_currency).and_return('EUR')+ controller._current_currency = 'EUR'endit 'generates different cache keys for different currencies' do