1
0

custom_css_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Custom CSS' do
  4. include RoutingHelper
  5. describe 'GET /custom.css' do
  6. context 'without any CSS or User Roles' do
  7. it 'returns empty stylesheet' do
  8. get '/custom.css'
  9. expect(response.content_type).to include('text/css')
  10. expect(response.body.presence).to be_nil
  11. end
  12. end
  13. context 'with CSS settings' do
  14. before do
  15. Setting.custom_css = expected_css
  16. end
  17. it 'returns stylesheet from settings' do
  18. get '/custom.css'
  19. expect(response.content_type).to include('text/css')
  20. expect(response.body.strip).to eq(expected_css)
  21. end
  22. def expected_css
  23. <<~CSS.strip
  24. body { background-color: red; }
  25. CSS
  26. end
  27. end
  28. context 'with highlighted colored UserRole records' do
  29. before do
  30. _highlighted_colored = Fabricate :user_role, highlighted: true, color: '#336699', id: '123_123_123'
  31. _highlighted_no_color = Fabricate :user_role, highlighted: true, color: ''
  32. _no_highlight_with_color = Fabricate :user_role, highlighted: false, color: ''
  33. end
  34. it 'returns stylesheet from settings' do
  35. get '/custom.css'
  36. expect(response.content_type).to include('text/css')
  37. expect(response.body.strip).to eq(expected_css)
  38. end
  39. def expected_css
  40. <<~CSS.strip
  41. .user-role-123123123 {
  42. --user-role-accent: #336699;
  43. }
  44. CSS
  45. end
  46. end
  47. end
  48. end