2024-01-12 04:19:25 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe 'Custom CSS' do
|
2024-01-12 04:19:25 -05:00
|
|
|
include RoutingHelper
|
|
|
|
|
2025-01-08 03:48:45 -05:00
|
|
|
describe 'GET /css/:id.css' do
|
2024-01-12 04:19:25 -05:00
|
|
|
context 'without any CSS or User Roles' do
|
|
|
|
it 'returns empty stylesheet' do
|
2025-01-08 03:48:45 -05:00
|
|
|
get '/css/custom-123.css'
|
2024-01-12 04:19:25 -05:00
|
|
|
|
2024-12-06 13:55:47 -05:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_cacheable_headers
|
|
|
|
.and have_attributes(
|
|
|
|
content_type: match('text/css')
|
|
|
|
)
|
|
|
|
expect(response.body.presence)
|
|
|
|
.to be_nil
|
2024-01-12 04:19:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with CSS settings' do
|
|
|
|
before do
|
|
|
|
Setting.custom_css = expected_css
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns stylesheet from settings' do
|
2025-01-08 03:48:45 -05:00
|
|
|
get '/css/custom-456.css'
|
2024-01-12 04:19:25 -05:00
|
|
|
|
2024-12-06 13:55:47 -05:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_cacheable_headers
|
|
|
|
.and have_attributes(
|
|
|
|
content_type: match('text/css')
|
|
|
|
)
|
|
|
|
expect(response.body.strip)
|
|
|
|
.to eq(expected_css)
|
2024-01-12 04:19:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def expected_css
|
|
|
|
<<~CSS.strip
|
|
|
|
body { background-color: red; }
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|