mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-17 15:47:15 +01:00
Fix custom css cache miss (#33583)
This commit is contained in:
parent
77a44e61a8
commit
74da9e9281
@ -45,7 +45,9 @@ module ThemeHelper
|
||||
end
|
||||
|
||||
def cached_custom_css_digest
|
||||
Rails.cache.read(:setting_digest_custom_css)
|
||||
Rails.cache.fetch(:setting_digest_custom_css) do
|
||||
Setting.custom_css&.then { |content| Digest::SHA256.hexdigest(content) }
|
||||
end
|
||||
end
|
||||
|
||||
def theme_color_for(theme)
|
||||
|
@ -80,18 +80,37 @@ RSpec.describe ThemeHelper do
|
||||
end
|
||||
|
||||
describe '#custom_stylesheet' do
|
||||
let(:custom_css) { 'body {}' }
|
||||
let(:custom_digest) { Digest::SHA256.hexdigest(custom_css) }
|
||||
|
||||
before do
|
||||
Setting.custom_css = custom_css
|
||||
end
|
||||
|
||||
context 'when custom css setting value digest is present' do
|
||||
before { Rails.cache.write(:setting_digest_custom_css, '1a2s3d4f1a2s3d4f') }
|
||||
before { Rails.cache.write(:setting_digest_custom_css, custom_digest) }
|
||||
|
||||
it 'returns value from settings' do
|
||||
expect(custom_stylesheet)
|
||||
.to match('/css/custom-1a2s3d4f.css')
|
||||
.to match("/css/custom-#{custom_digest[...8]}.css")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when custom css setting value digest is not present' do
|
||||
context 'when custom css setting value digest is expired' do
|
||||
before { Rails.cache.delete(:setting_digest_custom_css) }
|
||||
|
||||
it 'returns value from settings' do
|
||||
expect(custom_stylesheet)
|
||||
.to match("/css/custom-#{custom_digest[...8]}.css")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when custom css setting is not present' do
|
||||
before do
|
||||
Setting.custom_css = nil
|
||||
Rails.cache.delete(:setting_digest_custom_css)
|
||||
end
|
||||
|
||||
it 'returns default value' do
|
||||
expect(custom_stylesheet)
|
||||
.to be_blank
|
||||
|
Loading…
x
Reference in New Issue
Block a user