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
Do not use redis for tests (#12000)
Damian Legawiec0cde924e3262
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 40f48a51da..48d3f62ec6 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -4,8 +4,6 @@ defaults: &defaultsparameters: &default_parametersruby_image:type: string- redis_image:- type: stringrestore_cache_key_1:type: stringdefault: 'spree-bundle-v10-ruby-3-3-{{ .Branch }}'@@ -33,7 +31,6 @@ defaults: &defaultsworking_directory: ~/spreedocker:- image: &ruby_image << parameters.ruby_image >>- - image: &redis_image << parameters.redis_image >>jobs:@@ -95,7 +92,6 @@ jobs:- image: << parameters.postgres_image >>environment:POSTGRES_USER: postgres- - image: *redis_imagetests_mysql:<<: *run_test@@ -116,7 +112,6 @@ jobs:COVERAGE_DIR: /tmp/workspace/simplecovdocker:- image: *ruby_image- - image: *redis_image- image: << parameters.mysql_image >>command: [--default-authentication-plugin=mysql_native_password]@@ -146,13 +141,11 @@ workflows:- run_test:name: bundle_ruby_3_3ruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpinesave_cache_key: spree-bundle-v10-ruby-3-1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}run_file_path: ./bin/bundle_ruby.sh- run_test:name: brakemanruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpinerestore_cache_key_1: spree-brakeman-{{ .Branch }}restore_cache_key_2: spree-brakemansave_cache_key: spree-brakeman-{{ .Branch }}-{{ checksum "Gemfile.lock" }}@@ -163,8 +156,7 @@ workflows:name: tests_ruby_3_3_rails_7_0_postgresrails_version: '~> 7.0.0'ruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpine- postgres_image: circleci/postgres:12-alpine+ postgres_image: cimg/postgres:16.2store_artefacts: truerun_file_path: ./bin/tests_database_ci.shrequires:@@ -173,8 +165,7 @@ workflows:name: tests_ruby_3_3_rails_7_1_postgresrails_version: '~> 7.1.0'ruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpine- postgres_image: circleci/postgres:12-alpine+ postgres_image: cimg/postgres:16.2store_artefacts: truerun_file_path: ./bin/tests_database_ci.shrequires:@@ -183,8 +174,7 @@ workflows:name: tests_ruby_3_3_rails_6_1_postgresrails_version: '~> 6.1.0'ruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpine- postgres_image: circleci/postgres:12-alpine+ postgres_image: cimg/postgres:16.2store_artefacts: truerun_file_path: ./bin/tests_database_ci.shrequires:@@ -193,8 +183,7 @@ workflows:name: tests_ruby_3_3_rails_7_0_mysqlrails_version: '~> 7.0.0'ruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpine- mysql_image: circleci/mysql:8-ram+ mysql_image: cimg/mysql:8.0store_artefacts: truerun_file_path: ./bin/tests_database_ci.shpost-steps:@@ -208,7 +197,6 @@ workflows:name: send_test_coveragerails_version: '~> 7.0.0'ruby_image: cimg/ruby:3.3.0-browsers- redis_image: circleci/redis:6.2-alpinerun_file_path: ./bin/tests_coverage.shrequires:- tests_ruby_3_3_rails_7_0_mysqldiff --git a/api/spec/requests/spree/api/v2/caching_spec.rb b/api/spec/requests/spree/api/v2/caching_spec.rbdeleted file mode 100644index 64d264ea52..0000000000--- a/api/spec/requests/spree/api/v2/caching_spec.rb+++ /dev/null@@ -1,159 +0,0 @@-require 'spec_helper'--describe 'API v2 Caching spec', type: :request do- include_context 'API v2 tokens'-- let!(:product) { create(:product, name: 'Some name', stores: [store]) }- let(:store) { Spree::Store.default }-- before(:all) { ActionController::Base.perform_caching = true }- after(:all) { ActionController::Base.perform_caching = false }-- before do- store.update!(supported_currencies: 'USD,CAD')- Rails.cache.clear- end-- after do- Rails.cache.clear- end-- context 'collections caching' do- let(:cache_namespace) { 'api_v2_collection_cache' }- let!(:products) { create_list(:product_in_stock, 5, stores: [store]) }- let(:user) { create(:user) }-- before do- products.each { |product| product.update_columns(updated_at: 1.day.ago, created_at: 1.day.ago) }- products.last.update(name: 'Updated name')- end-- def cache_entries- Rails.cache.redis.with do |redis|- redis.keys.find_all { |k| k.start_with?(cache_namespace) }- end- end-- it 'caches collection' do- expect(cache_entries).to be_empty-- get '/api/v2/storefront/products'-- expect(cache_entries).not_to be_empty- expect(cache_entries.size).to eq(1)-- get '/api/v2/storefront/products?include=variants'- expect(cache_entries.size).to eq(2)-- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(2)-- get '/api/v2/storefront/products?page=2'- expect(cache_entries.size).to eq(3)-- get '/api/v2/storefront/products?page=2'- expect(cache_entries.size).to eq(3)-- get '/api/v2/storefront/products?per_page=1'- expect(cache_entries.size).to eq(4)-- get '/api/v2/storefront/products?per_page=1'- expect(cache_entries.size).to eq(4)-- get '/api/v2/storefront/products?currency=CAD'- expect(cache_entries.size).to eq(5)-- get '/api/v2/storefront/products?currency=CAD'- expect(cache_entries.size).to eq(5)-- get '/api/v2/storefront/products?filter[name]=Updated'- expect(cache_entries.size).to eq(6)-- get '/api/v2/storefront/products', headers: headers_bearer- expect(cache_entries.size).to eq(7)- end-- it 'auto expires cache when store is updated' do- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(1)-- # expire all cache when store is updates- store.update_column(:updated_at, 1.day.ago)-- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(2)- end-- it 'auto expires when new record is added to collection' do- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(1)-- create(:product, name: 'Updated name', stores: [store])-- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(2)- end-- it 'auto expires when record is updated' do- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(1)-- Timecop.travel Time.current + 1.day do- products.last.touch- end-- get '/api/v2/storefront/products'- expect(cache_entries.size).to eq(2)- end- end-- context 'serializers caching' do- let!(:zone) { create(:zone, default_tax: true) }- let(:cache_store) { Spree::V2::Storefront::ProductSerializer.cache_store_instance }- let(:cache_entry) { cache_store.read(product, namespace: cache_namespace) }-- context 'auto expiration' do- let(:cache_namespace) do- "jsonapi-serializer-usd-en-#{zone.cache_key_with_version}-#{store.cache_key_with_version}"- end-- it 'auto expire cache after record being updated' do- get "/api/v2/storefront/products/#{product.id}"-- expect(json_response['data']).to have_attribute('name').with_value('Some name')-- expect(cache_entry).not_to be_nil- expect(cache_entry[:attributes].as_json).to eq(json_response[:data][:attributes])-- product.update(name: 'Something else')- expect(cache_store.read(product, namespace: cache_namespace)).to be_nil-- get "/api/v2/storefront/products/#{product.id}"- expect(cache_store.read(product, namespace: cache_namespace)).not_to be_nil- expect(json_response['data']).to have_attribute('name').with_value('Something else')- end- end-- context 'currency and user' do- include_context 'API v2 tokens'-- before { store.update!(supported_currencies: 'USD,EUR', supported_locales: 'en,de') }-- let!(:user) { create(:user) }- let(:currency) { 'EUR' }- let(:locale) { 'de' }- let(:cache_namespace) do- "jsonapi-serializer-eur-de" \- "-#{zone.cache_key_with_version}" \- "-#{store.cache_key_with_version}" \- "-#{user.cache_key_with_version}"- end-- it 'includes currency and signed user in the cache key' do- get "/api/v2/storefront/products/#{product.id}?currency=#{currency}&locale=#{locale}", headers: headers_bearer-- expect(cache_entry).not_to be_nil- end- end- end-enddiff --git a/cli/lib/spree_cli/templates/extension/.circleci/config.yml b/cli/lib/spree_cli/templates/extension/.circleci/config.ymlindex 3214361bb8..0e35b5a983 100644--- a/cli/lib/spree_cli/templates/extension/.circleci/config.yml+++ b/cli/lib/spree_cli/templates/extension/.circleci/config.yml@@ -4,8 +4,6 @@ defaults: &defaultsparameters: &default_parametersruby_image:type: string- redis_image:- type: stringrestore_cache_key_1:type: stringdefault: 'spree-bundle-v10-ruby-3-3-{{ .Branch }}'@@ -33,7 +31,6 @@ defaults: &defaultsworking_directory: ~/spreedocker:- image: &ruby_image << parameters.ruby_image >>- - image: &redis_image << parameters.redis_image >>jobs:@@ -95,7 +92,6 @@ jobs:- image: << parameters.postgres_image >>environment:POSTGRES_USER: postgres- - image: *redis_imagetests_mysql:<<: *run_test@@ -116,7 +112,6 @@ jobs:COVERAGE_DIR: /tmp/workspace/simplecovdocker:- image: *ruby_image- - image: *redis_image- image: << parameters.mysql_image >>command: [--default-authentication-plugin=mysql_native_password]diff --git a/common_spree_dependencies.rb b/common_spree_dependencies.rbindex e50582ecff..e4fd1667b6 100644--- a/common_spree_dependencies.rb+++ b/common_spree_dependencies.rb@@ -51,7 +51,6 @@ group :test, :development dogem 'brakeman'gem 'gem-release'gem 'i18n-tasks'- gem 'redis'gem 'rubocop', '~> 1.0', require: falsegem 'rubocop-rspec', require: falsegem 'pry-byebug'diff --git a/core/lib/generators/spree/dummy/templates/rails/test.rb b/core/lib/generators/spree/dummy/templates/rails/test.rbindex 6008f39279..143dc0d987 100644--- a/core/lib/generators/spree/dummy/templates/rails/test.rb+++ b/core/lib/generators/spree/dummy/templates/rails/test.rb@@ -36,7 +36,7 @@ Dummy::Application.configure doconfig.active_job.queue_adapter = :test- config.cache_store = :redis_cache_store+ config.cache_store = :memory_store # we need to use memory store for Spree preferencesroutes.default_url_options = { host: 'localhost', port: 3000 }end