2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2015-05-22 09:21:16 +08:00
|
|
|
|
|
|
|
describe StylesheetsController do
|
|
|
|
|
|
|
|
it 'can survive cache miss' do
|
|
|
|
|
|
|
|
StylesheetCache.destroy_all
|
2017-04-12 22:52:52 +08:00
|
|
|
builder = Stylesheet::Manager.new('desktop_rtl', nil)
|
2015-05-23 13:25:05 +08:00
|
|
|
builder.compile
|
|
|
|
|
|
|
|
digest = StylesheetCache.first.digest
|
|
|
|
StylesheetCache.destroy_all
|
2015-05-22 09:21:16 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: { name: "desktop_rtl_#{digest}" }, format: :json
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2015-05-23 13:25:05 +08:00
|
|
|
|
|
|
|
cached = StylesheetCache.first
|
|
|
|
expect(cached.target).to eq 'desktop_rtl'
|
|
|
|
expect(cached.digest).to eq digest
|
|
|
|
|
2015-05-22 09:21:16 +08:00
|
|
|
# tmp folder destruction and cached
|
2017-04-12 22:52:52 +08:00
|
|
|
`rm #{Stylesheet::Manager.cache_fullpath}/*`
|
2015-05-22 09:21:16 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: { name: "desktop_rtl_#{digest}" }, format: :json
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2015-05-23 13:25:05 +08:00
|
|
|
|
2015-05-22 09:21:16 +08:00
|
|
|
# there is an edge case which is ... disk and db cache is nuked, very unlikely to happen
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
it 'can lookup theme specific css' do
|
2017-07-28 09:20:09 +08:00
|
|
|
scheme = ColorScheme.create_from_base(name: "testing", colors: [])
|
2017-04-12 22:52:52 +08:00
|
|
|
theme = Theme.create!(name: "test", color_scheme_id: scheme.id, user_id: -1)
|
|
|
|
|
|
|
|
builder = Stylesheet::Manager.new(:desktop, theme.key)
|
|
|
|
builder.compile
|
|
|
|
|
|
|
|
`rm #{Stylesheet::Manager.cache_fullpath}/*`
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: {
|
|
|
|
name: builder.stylesheet_filename.sub(".css", "")
|
|
|
|
}, format: :json
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: {
|
|
|
|
name: builder.stylesheet_filename_no_digest.sub(".css", "")
|
|
|
|
}, format: :json
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
builder = Stylesheet::Manager.new(:desktop_theme, theme.key)
|
|
|
|
builder.compile
|
|
|
|
|
|
|
|
`rm #{Stylesheet::Manager.cache_fullpath}/*`
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: {
|
|
|
|
name: builder.stylesheet_filename.sub(".css", "")
|
|
|
|
}, format: :json
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :show, params: {
|
|
|
|
name: builder.stylesheet_filename_no_digest.sub(".css", "")
|
|
|
|
}, format: :json
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-04-12 22:52:52 +08:00
|
|
|
end
|
|
|
|
|
2015-05-22 09:21:16 +08:00
|
|
|
end
|