mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: serve category images from the CDN
This commit is contained in:
parent
33e7df977d
commit
d0962d6e5a
2 changed files with 50 additions and 0 deletions
|
@ -40,4 +40,14 @@ class BasicCategorySerializer < ApplicationSerializer
|
||||||
def notification_level
|
def notification_level
|
||||||
object.notification_level
|
object.notification_level
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def logo_url
|
||||||
|
url = object.logo_url
|
||||||
|
url.present? && UrlHelper.is_local(url) ? UrlHelper.schemaless(UrlHelper.absolute(url)) : url
|
||||||
|
end
|
||||||
|
|
||||||
|
def background_url
|
||||||
|
url = object.background_url
|
||||||
|
url.present? && UrlHelper.is_local(url) ? UrlHelper.schemaless(UrlHelper.absolute(url)) : url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
40
spec/serializers/basic_category_serializer_spec.rb
Normal file
40
spec/serializers/basic_category_serializer_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
require "rails_helper"
|
||||||
|
require_dependency "category"
|
||||||
|
|
||||||
|
describe BasicCategorySerializer do
|
||||||
|
|
||||||
|
let(:cdn) { "//my.awesome.cdn" }
|
||||||
|
let(:upload) { Fabricate(:upload) }
|
||||||
|
let(:json) { BasicCategorySerializer.new(category, scope: Guardian.new, root: false).as_json }
|
||||||
|
|
||||||
|
describe "logo_url" do
|
||||||
|
|
||||||
|
let(:category) { Fabricate(:category, logo_url: upload.url) }
|
||||||
|
|
||||||
|
it "uses absolute schemaless URL" do
|
||||||
|
expect(json[:logo_url]).to eq("//test.localhost#{upload.url}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses CDN when available" do
|
||||||
|
Discourse.stubs(:asset_host).returns(cdn)
|
||||||
|
expect(json[:logo_url]).to eq("#{cdn}#{upload.url}")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "background_url" do
|
||||||
|
|
||||||
|
let(:category) { Fabricate(:category, background_url: upload.url) }
|
||||||
|
|
||||||
|
it "uses absolute schemaless URL" do
|
||||||
|
expect(json[:background_url]).to eq("//test.localhost#{upload.url}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses CDN when available" do
|
||||||
|
Discourse.stubs(:asset_host).returns(cdn)
|
||||||
|
expect(json[:background_url]).to eq("#{cdn}#{upload.url}")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue