From 22a051e720fad680c7d8daf25674b60c08fc1887 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 17 Mar 2019 10:19:50 +0000 Subject: [PATCH] Enable products cache by default only in staging and production We keep tests running by default without cache, keeping it as it was before 10a79d5a65f8d00808a5465d805b2c51900411a5 Additionally, cached_products_renderer no longer depends on Rails.env, so here we remove that dependency from it's spec. --- app/models/spree/app_configuration_decorator.rb | 2 +- .../cached_products_renderer_spec.rb | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/app/models/spree/app_configuration_decorator.rb b/app/models/spree/app_configuration_decorator.rb index 6259c84902..2df7c02ea7 100644 --- a/app/models/spree/app_configuration_decorator.rb +++ b/app/models/spree/app_configuration_decorator.rb @@ -39,5 +39,5 @@ Spree::AppConfiguration.class_eval do preference :enable_localized_number?, :boolean, default: false # Enable cache - preference :enable_products_cache?, :boolean, default: !Rails.env.development? + preference :enable_products_cache?, :boolean, default: (Rails.env.production? || Rails.env.staging?) end diff --git a/spec/lib/open_food_network/cached_products_renderer_spec.rb b/spec/lib/open_food_network/cached_products_renderer_spec.rb index 6bff04dad2..61de635f20 100644 --- a/spec/lib/open_food_network/cached_products_renderer_spec.rb +++ b/spec/lib/open_food_network/cached_products_renderer_spec.rb @@ -27,7 +27,6 @@ module OpenFoodNetwork context "products cache toggle" do before do - allow(Rails.env).to receive(:production?) { true } Rails.cache.write "products-json-#{distributor.id}-#{order_cycle.id}", 'products' end @@ -52,19 +51,9 @@ module OpenFoodNetwork end end - context "when in testing / development" do + context "products cache enabled" do before do - allow(Rails.env).to receive(:production?) { false } - end - - it "returns uncached products JSON" do - expect(cached_products_renderer.products_json).to eq 'uncached products' - end - end - - context "when in production / staging" do - before do - allow(Rails.env).to receive(:production?) { true } + Spree::Config[:enable_products_cache?] = true end describe "when the distribution is not set" do