forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate JSON file for brand configs
Refs CNVS-28275, closes CNVS-28885 Generate a json file to go along with the scss file for each brand config. The intention is that the json file for each brand config will be pushed to the cdn. One difference from the scss file is that it includes all variables, even if they are not specified in the brand config. Variable that have not been customized will use the default value. In addition to generating a json file for each brand, a json file for that inclues all default values is generated so other services don't need to know the defaults if no brand config is available. To allow for long term caching the filename of the json file includes a hash of the current defaults (including fingerprinted urls for default images). This way when the defaults change (or a default image) it will point to a new file even if the brand config didn't change. Test plan: - Save a new brand config. - Look in public/dist/brandable_css/[brand config hash]/ - There should be a [hash of defaults].json file - Should include custom values from brand config - Should include default values not specified in the brand config - Run rake brand_configs:clean && rake brand_configs:write - Should generate json file for all brand configs - Open console in browser - ENV.active_brand_config_json_url should be path the current brand json file - Go back to the default brand - ENV.active_brand_config_json_url should be path to default json file - Test with a real s3 bucket for the CDN - JSON files should be uploaded to the CDN - ENV.active_brand_config_json should work when used with ENV.ASSET_HOST Change-Id: Ibcaf54a2bff324f419a7614a8d3906c0c49aed9e Reviewed-on: https://gerrit.instructure.com/77427 Reviewed-by: Ryan Shaw <[email protected]> Tested-by: Jenkins QA-Review: August Thornton <[email protected]> Product-Review: Simon Williams <[email protected]>
- Loading branch information
Showing
10 changed files
with
340 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# | ||
# Copyright (C) 2016 Instructure, Inc. | ||
# | ||
# This file is part of Canvas. | ||
# | ||
# Canvas is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Affero General Public License as published by the Free | ||
# Software Foundation, version 3 of the License. | ||
# | ||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') | ||
|
||
describe BrandableCSS do | ||
describe "all_brand_variable_values" do | ||
it "returns defaults if called without a brand config" do | ||
expect(BrandableCSS.all_brand_variable_values["ic-link-color"]).to eq '#0081bd' | ||
end | ||
|
||
it "includes image_url asset path for default images" do | ||
# un-memoize so it calls image_url stub | ||
BrandableCSS.remove_instance_variable(:@variables_map_with_image_urls) | ||
image_name = "image.png" | ||
BrandableCSS.stubs(:image_url).returns(image_name) | ||
tile_wide = BrandableCSS.all_brand_variable_values["ic-brand-msapplication-tile-wide"] | ||
expect(tile_wide).to eq image_name | ||
end | ||
|
||
describe "when called with a brand config" do | ||
before :once do | ||
parent_account = Account.default | ||
parent_account.enable_feature!(:use_new_styles) | ||
parent_config = BrandConfig.create(variables: {"ic-brand-primary" => "#321"}) | ||
|
||
subaccount_bc = BrandConfig.for( | ||
variables: {"ic-brand-global-nav-bgd" => "#123"}, | ||
parent_md5: parent_config.md5, | ||
js_overrides: nil, | ||
css_overrides: nil, | ||
mobile_js_overrides: nil, | ||
mobile_css_overrides: nil | ||
) | ||
subaccount_bc.save! | ||
@brand_variables = BrandableCSS.all_brand_variable_values(subaccount_bc) | ||
end | ||
|
||
it "includes custom variables from brand config" do | ||
expect(@brand_variables["ic-brand-global-nav-bgd"]).to eq '#123' | ||
end | ||
|
||
it "includes custom variables from parent brand config" do | ||
expect(@brand_variables["ic-brand-primary"]).to eq '#321' | ||
end | ||
|
||
it "includes default variables not found in brand config" do | ||
expect(@brand_variables["ic-link-color"]).to eq '#0081bd' | ||
end | ||
end | ||
end | ||
|
||
describe "default_json" do | ||
it "includes default variables not found in brand config" do | ||
brand_variables = JSON.parse(BrandableCSS.default_json) | ||
expect(brand_variables["ic-link-color"]).to eq '#0081bd' | ||
end | ||
end | ||
|
||
describe "save_default_file!" do | ||
it "writes the default json represendation to the default json file" do | ||
Canvas::Cdn.stubs(:enabled?).returns(false) | ||
file = StringIO.new | ||
BrandableCSS.stubs(:default_brand_json_file).returns(file) | ||
BrandableCSS.save_default_json! | ||
expect(file.string).to eq BrandableCSS.default_json | ||
end | ||
|
||
it 'uploads file to s3 if cdn is enabled' do | ||
Canvas::Cdn.stubs(:enabled?).returns(true) | ||
file = StringIO.new | ||
BrandableCSS.stubs(:default_brand_json_file).returns(file) | ||
File.stubs(:delete) | ||
BrandableCSS.s3_uploader.expects(:upload_file).with(BrandableCSS.public_default_json_path) | ||
BrandableCSS.save_default_json! | ||
end | ||
|
||
it 'delete the local file if cdn is enabled' do | ||
Canvas::Cdn.stubs(:enabled?).returns(true) | ||
file = StringIO.new | ||
BrandableCSS.stubs(:default_brand_json_file).returns(file) | ||
File.expects(:delete).with(BrandableCSS.default_brand_json_file) | ||
BrandableCSS.s3_uploader.expects(:upload_file) | ||
BrandableCSS.save_default_json! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Copyright (C) 2016 Instructure, Inc. | ||
# | ||
# This file is part of Canvas. | ||
# | ||
# Canvas is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Affero General Public License as published by the Free | ||
# Software Foundation, version 3 of the License. | ||
# | ||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') | ||
|
||
describe Canvas::Cdn do | ||
describe '.enabled?' do | ||
before :each do | ||
@original_config = Canvas::Cdn.config.dup | ||
end | ||
|
||
after :each do | ||
Canvas::Cdn.config.replace(@original_config) | ||
end | ||
|
||
it 'returns true when the cdn config has a bucket' do | ||
Canvas::Cdn.config.merge! enabled: true, bucket: 'bucket_name' | ||
expect(Canvas::Cdn.enabled?).to eq true | ||
end | ||
|
||
it 'returns false when the cdn config does not have a bucket' do | ||
Canvas::Cdn.config.merge! enabled: true, bucket: nil | ||
expect(Canvas::Cdn.enabled?).to eq false | ||
end | ||
end | ||
end |
Oops, something went wrong.