Extend custom CSS cache time with digest paths (#33207)
This commit is contained in:
parent
b3243ef41c
commit
c0264c8013
11 changed files with 142 additions and 6 deletions
|
@ -79,6 +79,26 @@ RSpec.describe ThemeHelper do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#custom_stylesheet' do
|
||||
context 'when custom css setting value digest is present' do
|
||||
before { Rails.cache.write(:setting_digest_custom_css, '1a2s3d4f1a2s3d4f') }
|
||||
|
||||
it 'returns value from settings' do
|
||||
expect(custom_stylesheet)
|
||||
.to match('/css/custom-1a2s3d4f.css')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when custom css setting value digest is not present' do
|
||||
before { Rails.cache.delete(:setting_digest_custom_css) }
|
||||
|
||||
it 'returns default value' do
|
||||
expect(custom_stylesheet)
|
||||
.to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def html_links
|
||||
|
|
|
@ -17,4 +17,40 @@ RSpec.describe Form::AdminSettings do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#save' do
|
||||
describe 'updating digest values' do
|
||||
context 'when updating custom css to real value' do
|
||||
subject { described_class.new(custom_css: css) }
|
||||
|
||||
let(:css) { 'body { color: red; }' }
|
||||
let(:digested) { Digest::SHA256.hexdigest(css) }
|
||||
|
||||
it 'changes relevant digest value' do
|
||||
expect { subject.save }
|
||||
.to(change { Rails.cache.read(:setting_digest_custom_css) }.to(digested))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when updating custom css to empty value' do
|
||||
subject { described_class.new(custom_css: '') }
|
||||
|
||||
before { Rails.cache.write(:setting_digest_custom_css, 'previous-value') }
|
||||
|
||||
it 'changes relevant digest value' do
|
||||
expect { subject.save }
|
||||
.to(change { Rails.cache.read(:setting_digest_custom_css) }.to(be_blank))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when updating other fields' do
|
||||
subject { described_class.new(site_contact_email: 'test@example.host') }
|
||||
|
||||
it 'does not update digests' do
|
||||
expect { subject.save }
|
||||
.to(not_change { Rails.cache.read(:setting_digest_custom_css) })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,7 @@ module TestEndpoints
|
|||
/.well-known/nodeinfo
|
||||
/nodeinfo/2.0
|
||||
/manifest
|
||||
/css/custom-1a2s3d4f.css
|
||||
/custom.css
|
||||
/actor
|
||||
/api/v1/instance/extended_description
|
||||
|
|
|
@ -5,10 +5,10 @@ require 'rails_helper'
|
|||
RSpec.describe 'Custom CSS' do
|
||||
include RoutingHelper
|
||||
|
||||
describe 'GET /custom.css' do
|
||||
describe 'GET /css/:id.css' do
|
||||
context 'without any CSS or User Roles' do
|
||||
it 'returns empty stylesheet' do
|
||||
get '/custom.css'
|
||||
get '/css/custom-123.css'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
|
@ -27,7 +27,7 @@ RSpec.describe 'Custom CSS' do
|
|||
end
|
||||
|
||||
it 'returns stylesheet from settings' do
|
||||
get '/custom.css'
|
||||
get '/css/custom-456.css'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
|
|
19
spec/routing/custom_css_routing_spec.rb
Normal file
19
spec/routing/custom_css_routing_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Custom CSS routes' do
|
||||
describe 'the legacy route' do
|
||||
it 'routes to correct place' do
|
||||
expect(get('/custom.css'))
|
||||
.to route_to('custom_css#show')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the custom digest route' do
|
||||
it 'routes to correct place' do
|
||||
expect(get('/css/custom-1a2s3d4f.css'))
|
||||
.to route_to('custom_css#show', id: 'custom-1a2s3d4f', format: 'css')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue