FIX: CDN wasn't properly applied to category background images when using S3

This commit is contained in:
Régis Hanol 2017-05-22 18:37:01 +02:00
parent decb432740
commit a7f337fa93
3 changed files with 36 additions and 5 deletions

View File

@ -132,12 +132,8 @@ COMMENT
@theme == :nil ? nil : @theme
end
def apply_cdn(url)
"#{GlobalSetting.cdn_url}#{url}"
end
def category_css(category)
"body.category-#{category.full_slug} { background-image: url(#{apply_cdn(category.uploaded_background.url)}) }\n"
"body.category-#{category.full_slug} { background-image: url(#{upload_cdn_path(category.uploaded_background.url)}) }\n"
end
def imports(asset, parent_path)

View File

@ -0,0 +1,31 @@
require 'rails_helper'
require 'stylesheet/importer'
describe Stylesheet::Importer do
def compile_css(name)
Stylesheet::Compiler.compile_asset(name)[0]
end
it "applies CDN to background category images" do
expect(compile_css("category_backgrounds")).to_not include("background-image")
background = Fabricate(:upload)
category = Fabricate(:category, uploaded_background: background)
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(#{background.url})}")
GlobalSetting.expects(:cdn_url).returns("//awesome.cdn")
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(//awesome.cdn#{background.url})}")
end
it "applies S3 CDN to background category images" do
SiteSetting.s3_cdn_url = "https://s3.cdn"
background = Fabricate(:upload_s3)
category = Fabricate(:category, uploaded_background: background)
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(https://s3.cdn/uploads")
end
end

View File

@ -8,6 +8,10 @@ Fabricator(:upload) do
url { sequence(:url) { |n| "/uploads/default/#{n}/1234567890123456.png" } }
end
Fabricator(:upload_s3, from: :upload) do
url { sequence(:url) { |n| "#{Discourse.store.absolute_base_url}/uploads/default/#{n}/1234567890123456.png" } }
end
Fabricator(:attachment, from: :upload) do
id 42
user