Skip to content

Commit 3c40ada

Browse files
committed
include asset host in theme json files
also include asset host in ENV.active_brand_config_json_url closes CNVS-29764 test plan - use a real s3 bucket for canvas cdn - create a new theme - should have one custom image uploaded - should have some default images - in the browser console `ENV.active_brand_config_jons_url` should include the asset host - open the json url - default and custom image urls should work Change-Id: I1dd1c11617db624e93686da706b94afee738df12 Reviewed-on: https://gerrit.instructure.com/81445 Reviewed-by: Ryan Shaw <ryan@instructure.com> Tested-by: Jenkins Product-Review: Ryan Shaw <ryan@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com>
1 parent 4f547f3 commit 3c40ada

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def active_brand_config(opts={})
710710
def active_brand_config_json_url(opts={})
711711
path = active_brand_config(opts).try(:public_json_path)
712712
path ||= BrandableCSS.public_default_json_path
713-
"/#{path}"
713+
"#{Canvas::Cdn.config.host}/#{path}"
714714
end
715715

716716
def brand_config_for_account(opts={})

lib/brandable_css.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@
77
# stuff take FOREVER in the webpack build. That means for the time being,
88
# changes here if they happen may need to be mirrored in that file.
99

10-
module BrandableCSS
11-
extend ActionView::Helpers::AssetTagHelper
10+
# this is to get urls that always have the asset host on them,
11+
# it was fixed in rails 4.1 so is unneeded once we are using 4.1+
12+
# at that point we can just use ActionController::Base.helpers.image_url below
13+
# see: https://github.com/rails/rails/issues/10051#issuecomment-26967074
14+
if CANVAS_RAILS4_0
15+
class DummyControllerWithCorrectAssetUrls < ActionController::Base
16+
def self.helpers
17+
@helper_proxy ||= begin
18+
proxy = ActionView::Base.new
19+
proxy.config = config.inheritable_copy
20+
proxy.extend(_helpers)
21+
end
22+
end
23+
end
24+
end
1225

26+
module BrandableCSS
1327
APP_ROOT = defined?(Rails) && Rails.root || Pathname.pwd
1428
CONFIG = YAML.load_file(APP_ROOT.join('config/brandable_css.yml')).freeze
1529
BRANDABLE_VARIABLES = JSON.parse(File.read(APP_ROOT.join(CONFIG['paths']['brandable_variables_json']))).freeze
@@ -90,7 +104,11 @@ def variables_map
90104
def variables_map_with_image_urls
91105
@variables_map_with_image_urls ||= variables_map.each_with_object({}) do |(key, config), memo|
92106
if config['type'] == 'image'
93-
memo[key] = config.merge('default' => image_url(config['default']))
107+
if CANVAS_RAILS4_0
108+
memo[key] = config.merge('default' => DummyControllerWithCorrectAssetUrls.helpers.image_url(config['default']))
109+
else
110+
memo[key] = config.merge('default' => ActionController::Base.helpers.image_url(config['default']))
111+
end
94112
else
95113
memo[key] = config
96114
end

spec/lib/brandable_css_spec.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@
2626

2727
it "includes image_url asset path for default images" do
2828
# un-memoize so it calls image_url stub
29-
BrandableCSS.remove_instance_variable(:@variables_map_with_image_urls)
30-
image_name = "image.png"
31-
BrandableCSS.stubs(:image_url).returns(image_name)
29+
if BrandableCSS.instance_variable_get(:@variables_map_with_image_urls)
30+
BrandableCSS.remove_instance_variable(:@variables_map_with_image_urls)
31+
end
32+
url = "https://test.host/image.png"
33+
if CANVAS_RAILS4_0
34+
DummyControllerWithCorrectAssetUrls.helpers.stubs(:image_url).returns(url)
35+
else
36+
ActionController::Base.helpers.stubs(:image_url).returns(url)
37+
end
3238
tile_wide = BrandableCSS.all_brand_variable_values["ic-brand-msapplication-tile-wide"]
33-
expect(tile_wide).to eq image_name
39+
expect(tile_wide).to eq url
3440
end
3541

3642
describe "when called with a brand config" do

0 commit comments

Comments
 (0)