From 19d7543004b5bc77902b0be0e2b7148879a20654 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 16 Oct 2018 12:00:33 +1100 Subject: [PATCH] FIX: clear color scheme cache when clearing theme cache --- app/models/theme.rb | 1 + spec/models/theme_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/theme.rb b/app/models/theme.rb index ee6c3188cc5..f3b90ff6f0b 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -109,6 +109,7 @@ class Theme < ActiveRecord::Base Site.clear_anon_cache! clear_cache! ApplicationSerializer.expire_cache_fragment!("user_themes") + ColorScheme.hex_cache.clear end def self.clear_default! diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb index 9b7211de7ad..859421ce044 100644 --- a/spec/models/theme_spec.rb +++ b/spec/models/theme_spec.rb @@ -417,6 +417,30 @@ HTML Theme.find_by(id: id).included_settings.to_json end + it 'clears color scheme cache correctly' do + Theme.destroy_all + + cs = Fabricate(:color_scheme, name: 'Fancy', color_scheme_colors: [ + Fabricate(:color_scheme_color, name: 'header_primary', hex: 'F0F0F0'), + Fabricate(:color_scheme_color, name: 'header_background', hex: '1E1E1E'), + Fabricate(:color_scheme_color, name: 'tertiary', hex: '858585') + ]) + + theme = Fabricate(:theme, + user_selectable: true, + user: Fabricate(:admin), + color_scheme_id: cs.id + ) + + theme.set_default! + + expect(ColorScheme.hex_for_name('header_primary')).to eq('F0F0F0') + + Theme.clear_default! + + expect(ColorScheme.hex_for_name('header_primary')).to eq('333333') + end + it 'handles settings cache correctly' do Theme.destroy_all