2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-05-21 21:21:16 -04:00
|
|
|
|
|
|
|
describe StylesheetsController do
|
|
|
|
it 'can survive cache miss' do
|
|
|
|
StylesheetCache.destroy_all
|
2017-04-12 10:52:52 -04:00
|
|
|
builder = Stylesheet::Manager.new('desktop_rtl', nil)
|
2015-05-23 01:25:05 -04:00
|
|
|
builder.compile
|
|
|
|
|
|
|
|
digest = StylesheetCache.first.digest
|
|
|
|
StylesheetCache.destroy_all
|
2015-05-21 21:21:16 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
get "/stylesheets/desktop_rtl_#{digest}.css"
|
|
|
|
expect(response.status).to eq(200)
|
2015-05-23 01:25:05 -04:00
|
|
|
|
|
|
|
cached = StylesheetCache.first
|
|
|
|
expect(cached.target).to eq 'desktop_rtl'
|
|
|
|
expect(cached.digest).to eq digest
|
|
|
|
|
2015-05-21 21:21:16 -04:00
|
|
|
# tmp folder destruction and cached
|
2017-04-12 10:52:52 -04:00
|
|
|
`rm #{Stylesheet::Manager.cache_fullpath}/*`
|
2015-05-21 21:21:16 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
get "/stylesheets/desktop_rtl_#{digest}.css"
|
|
|
|
expect(response.status).to eq(200)
|
2015-05-23 01:25:05 -04:00
|
|
|
|
2015-05-21 21:21:16 -04:00
|
|
|
# there is an edge case which is ... disk and db cache is nuked, very unlikely to happen
|
|
|
|
end
|
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
it 'can lookup theme specific css' do
|
|
|
|
scheme = ColorScheme.create_from_base(name: "testing", colors: [])
|
2018-08-08 00:46:34 -04:00
|
|
|
theme = Fabricate(:theme, color_scheme_id: scheme.id)
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-07-12 00:18:21 -04:00
|
|
|
builder = Stylesheet::Manager.new(:desktop, theme.id)
|
2017-04-12 10:52:52 -04:00
|
|
|
builder.compile
|
|
|
|
|
|
|
|
`rm #{Stylesheet::Manager.cache_fullpath}/*`
|
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
get "/stylesheets/#{builder.stylesheet_filename.sub(".css", "")}.css"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
get "/stylesheets/#{builder.stylesheet_filename_no_digest.sub(".css", "")}.css"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-07-12 00:18:21 -04:00
|
|
|
builder = Stylesheet::Manager.new(:desktop_theme, theme.id)
|
2017-04-12 10:52:52 -04:00
|
|
|
builder.compile
|
|
|
|
|
|
|
|
`rm #{Stylesheet::Manager.cache_fullpath}/*`
|
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
get "/stylesheets/#{builder.stylesheet_filename.sub(".css", "")}.css"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
get "/stylesheets/#{builder.stylesheet_filename_no_digest.sub(".css", "")}.css"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-05 23:53:53 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
2020-08-28 10:36:52 -04:00
|
|
|
|
|
|
|
context "#color_scheme" do
|
|
|
|
it 'works as expected' do
|
|
|
|
scheme = ColorScheme.last
|
|
|
|
get "/color-scheme-stylesheet/#{scheme.id}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(json["color_scheme_id"]).to eq(scheme.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with a theme parameter' do
|
|
|
|
scheme = ColorScheme.last
|
|
|
|
theme = Theme.last
|
|
|
|
get "/color-scheme-stylesheet/#{scheme.id}/#{theme.id}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
expect(json["color_scheme_id"]).to eq(scheme.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2015-05-21 21:21:16 -04:00
|
|
|
end
|