mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
FIX: correctly resets user_themes template
This commit adds tests for this behaviour and also adds support for reseting cache when updating a theme name and destroying a theme.
This commit is contained in:
parent
3b7128102c
commit
caedefd675
@ -28,7 +28,7 @@ class Theme < ActiveRecord::Base
|
||||
changed_fields.each(&:save!)
|
||||
changed_fields.clear
|
||||
|
||||
Theme.expire_site_cache! if user_selectable_changed?
|
||||
Theme.expire_site_cache! if user_selectable_changed? || name_changed?
|
||||
|
||||
@dependant_themes = nil
|
||||
@included_themes = nil
|
||||
@ -46,7 +46,6 @@ class Theme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if self.id
|
||||
|
||||
ColorScheme
|
||||
.where(theme_id: self.id)
|
||||
.where("id NOT IN (SELECT color_scheme_id FROM themes where color_scheme_id IS NOT NULL)")
|
||||
@ -56,6 +55,8 @@ class Theme < ActiveRecord::Base
|
||||
.where(theme_id: self.id)
|
||||
.update_all(theme_id: nil)
|
||||
end
|
||||
|
||||
Theme.expire_site_cache!
|
||||
end
|
||||
|
||||
after_commit ->(theme) do
|
||||
|
@ -10,6 +10,10 @@ describe Theme do
|
||||
Fabricate(:user)
|
||||
end
|
||||
|
||||
let(:guardian) do
|
||||
Guardian.new(user)
|
||||
end
|
||||
|
||||
let :customization_params do
|
||||
{ name: 'my name', user_id: user.id, header: "my awesome header" }
|
||||
end
|
||||
@ -214,4 +218,32 @@ HTML
|
||||
expect(Theme.user_theme_keys).to eq(Set.new([]))
|
||||
end
|
||||
|
||||
it 'correctly caches user_themes template' do
|
||||
Theme.destroy_all
|
||||
|
||||
json = Site.json_for(guardian)
|
||||
user_themes = JSON.parse(json)["user_themes"]
|
||||
expect(user_themes).to eq([])
|
||||
|
||||
theme = Theme.create!(name: "bob", user_id: -1, user_selectable: true)
|
||||
theme.save!
|
||||
|
||||
json = Site.json_for(guardian)
|
||||
user_themes = JSON.parse(json)["user_themes"].map { |t| t["name"] }
|
||||
expect(user_themes).to eq(["bob"])
|
||||
|
||||
theme.name = "sam"
|
||||
theme.save!
|
||||
|
||||
json = Site.json_for(guardian)
|
||||
user_themes = JSON.parse(json)["user_themes"].map { |t| t["name"] }
|
||||
expect(user_themes).to eq(["sam"])
|
||||
|
||||
Theme.destroy_all
|
||||
|
||||
json = Site.json_for(guardian)
|
||||
user_themes = JSON.parse(json)["user_themes"]
|
||||
expect(user_themes).to eq([])
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user