From 169d17edc36a263ad75b8147ac1250e15fe7241b Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 15 Jun 2016 18:40:13 +0800 Subject: [PATCH] Include cdn path in the stylesheet digest. --- lib/sass/discourse_stylesheets.rb | 12 ++++++++---- spec/components/discourse_stylesheets_spec.rb | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/sass/discourse_stylesheets.rb b/lib/sass/discourse_stylesheets.rb index ac4955dbd..5bcd76fce 100644 --- a/lib/sass/discourse_stylesheets.rb +++ b/lib/sass/discourse_stylesheets.rb @@ -59,7 +59,7 @@ class DiscourseStylesheets def self.max_file_mtime globs = ["#{Rails.root}/app/assets/stylesheets/**/*.*css"] - for path in (Discourse.plugins || []).map { |plugin| File.dirname(plugin.path) } + Discourse.plugins.map { |plugin| File.dirname(plugin.path) }.each do |path| globs += [ "#{path}/plugin.rb", "#{path}/**/*.*css", @@ -71,8 +71,6 @@ class DiscourseStylesheets end.compact.max.to_i end - - def initialize(target = :desktop) @target = target end @@ -167,7 +165,13 @@ class DiscourseStylesheets if theme || category_updated > 0 Digest::SHA1.hexdigest "#{RailsMultisite::ConnectionManagement.current_db}-#{theme}-#{DiscourseStylesheets.last_file_updated}-#{category_updated}" else - Digest::SHA1.hexdigest "defaults-#{DiscourseStylesheets.last_file_updated}" + digest_string = "defaults-#{DiscourseStylesheets.last_file_updated}" + + if cdn_url = GlobalSetting.cdn_url + digest_string = "#{digest_string}-#{cdn_url}" + end + + Digest::SHA1.hexdigest digest_string end end end diff --git a/spec/components/discourse_stylesheets_spec.rb b/spec/components/discourse_stylesheets_spec.rb index ec3cead6e..30562a584 100644 --- a/spec/components/discourse_stylesheets_spec.rb +++ b/spec/components/discourse_stylesheets_spec.rb @@ -29,4 +29,18 @@ describe DiscourseStylesheets do end end + describe "#digest" do + before do + described_class.expects(:max_file_mtime).returns(Time.new(2016, 06, 05, 12, 30, 0, 0)) + end + + it "should return a digest" do + expect(described_class.new.digest).to eq('0e6c2e957cfc92ed60661c90ec3345198ccef887') + end + + it "should include the cdn url when generating the digest" do + GlobalSetting.expects(:cdn_url).returns('https://fastly.maxcdn.org') + expect(described_class.new.digest).to eq('4995163b1232c54c8ed3b44200d803a90bc47613') + end + end end