From 5f5448f9550a44779357662f255a69211060fd7a Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 02:31:55 +0200 Subject: [PATCH 1/7] Bump sprockets-rails --- Gemfile | 2 +- Gemfile.lock | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 19f037bb3..9e0f197a5 100644 --- a/Gemfile +++ b/Gemfile @@ -57,7 +57,7 @@ gem "bootstrap-sass", "3.3.7" gem "bootstrap-switch-rails", "3.3.3" gem "compass-rails", "3.0.2" gem "sass-rails", "5.0.6" -gem "sprockets", "2.12.4" +gem "sprockets-rails", "3.2.0" # Database diff --git a/Gemfile.lock b/Gemfile.lock index 50486ca8d..f0adbbfb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -287,7 +287,6 @@ GEM tilt (>= 1.2) hashdiff (0.3.4) hashie (3.5.6) - hike (1.2.3) hitimes (1.2.5) http (2.2.2) addressable (~> 2.3) @@ -657,15 +656,13 @@ GEM spring (>= 0.9.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (2.12.4) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) state_machines (0.5.0) string-direction (1.2.0) yard (~> 0.8) @@ -686,7 +683,7 @@ GEM activerecord (>= 3.2) thor (0.19.1) thread_safe (0.3.6) - tilt (1.4.1) + tilt (2.0.8) timecop (0.9.1) timers (4.1.2) hitimes @@ -879,7 +876,7 @@ DEPENDENCIES spring (= 2.0.2) spring-commands-cucumber (= 1.0.1) spring-commands-rspec (= 1.0.4) - sprockets (= 2.12.4) + sprockets-rails (= 3.2.0) string-direction (= 1.2.0) test_after_commit (= 1.1.0) thor (= 0.19.1) From 91ec412f147c05462893d60b4294fbf3d635a413 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 02:33:02 +0200 Subject: [PATCH 2/7] manifest-*.json is now called .sprockets-manifest-*.json --- lib/tasks/assets.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 9cbd410e2..0bf591cfb 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -15,7 +15,7 @@ namespace :assets do logger = ::Logging::Logger["assets:non_digest_assets"] non_digest_assets = Diaspora::Application.config.assets.non_digest_assets - manifest_path = Dir.glob(File.join(Rails.root, "public/assets/manifest-*.json")).first + manifest_path = Dir.glob(Rails.root.join("public", "assets", ".sprockets-manifest-*.json")).first JSON.load(File.new(manifest_path))["assets"].each do |logical_path, digested_path| logical_pathname = Pathname.new(logical_path) From 1360dd4207ffeed7b4bd15c315b9c24280f9a8d5 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 02:43:00 +0200 Subject: [PATCH 3/7] Fix require favico.js See rails/sprockets#169 --- app/assets/javascripts/jsxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jsxc.js b/app/assets/javascripts/jsxc.js index 9e90634ca..66ed5d622 100644 --- a/app/assets/javascripts/jsxc.js +++ b/app/assets/javascripts/jsxc.js @@ -1,5 +1,5 @@ //= require emojione -//= require favico.js +//= require favico.js/favico //= require jquery.ui/ui/resizable //= require jquery.ui/ui/draggable From 29a7f151b6303bdd9bb6a47130d1f40dc41a9b45 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 03:43:07 +0200 Subject: [PATCH 4/7] Use config.assets.quiet instead of quiet_assets gem The quiet_assets gem doesn't support rails 5, but sprockets 3 now has a config.assets.quiet option, which deprecates the quiet_assets gem. But the logging gem has a no-op silence method, that's why the quiet option doesn't work out-of-the-box. I added a little hack to use the silence method from ActiveSupport, which is also used from the original rails logger. --- Gemfile | 3 --- Gemfile.lock | 3 --- config/environments/development.rb | 3 +++ config/environments/test.rb | 3 +++ config/logging.rb | 7 +++++++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 9e0f197a5..c19e6f890 100644 --- a/Gemfile +++ b/Gemfile @@ -312,7 +312,4 @@ group :development, :test do gem "jasmine-jquery-rails", "2.0.3" gem "rails-assets-jasmine-ajax", "3.3.1", source: "https://rails-assets.org" gem "sinon-rails", "1.15.0" - - # silence assets - gem "quiet_assets", "1.1.0" end diff --git a/Gemfile.lock b/Gemfile.lock index f0adbbfb3..ddea815ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -463,8 +463,6 @@ GEM byebug (~> 9.0) pry (~> 0.10) public_suffix (2.0.5) - quiet_assets (1.1.0) - railties (>= 3.1, < 5.0) rack (1.6.8) rack-cors (1.0.1) rack-google-analytics (1.2.0) @@ -826,7 +824,6 @@ DEPENDENCIES pronto-scss (= 0.9.1) pry pry-byebug - quiet_assets (= 1.1.0) rack-cors (= 1.0.1) rack-google-analytics (= 1.2.0) rack-piwik (= 0.3.0) diff --git a/config/environments/development.rb b/config/environments/development.rb index 2d00a9b03..c32bb8287 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -32,6 +32,9 @@ Diaspora::Application.configure do # Expands the lines which load the assets config.assets.debug = true + # No assets request logging + config.assets.quiet = true + # Set the logging destination(s) config.log_to = %w[stdout file] diff --git a/config/environments/test.rb b/config/environments/test.rb index ad12d1620..c9fd1846d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -16,6 +16,9 @@ Diaspora::Application.configure do config.serve_static_files = true config.static_cache_control = "public, max-age=3600" + # No assets request logging + config.assets.quiet = true + # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false diff --git a/config/logging.rb b/config/logging.rb index 57cf39b0a..2c674562d 100644 --- a/config/logging.rb +++ b/config/logging.rb @@ -103,3 +103,10 @@ Logging::Rails.configure do |config| end end end + +# Include LoggerSilence from ActiveSupport. This is needed to silent assets +# requests with `config.assets.quiet`, because the default silence method of +# the logging gem is no-op. See: https://github.com/TwP/logging/issues/11 +Logging::Logger.send :alias_method, :local_level, :level +Logging::Logger.send :alias_method, :local_level=, :level= +Logging::Logger.send :include, LoggerSilence From 7ee8bfbac4cc5348782f0b51de3c1736db69fec9 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 05:00:11 +0200 Subject: [PATCH 5/7] Precompile poltergeist_disable_transition.css for tests --- config/environments/test.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/environments/test.rb b/config/environments/test.rb index c9fd1846d..ad06a51ac 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -19,6 +19,9 @@ Diaspora::Application.configure do # No assets request logging config.assets.quiet = true + # Precompile poltergeist_disable_transition.css for tests + config.assets.precompile += %w[poltergeist_disable_transition.css] + # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false From 7a26456875cd7f6a33aa4167b834a11907557c42 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 05:21:33 +0200 Subject: [PATCH 6/7] Add checksums to assets in specs --- spec/helpers/application_helper_spec.rb | 4 ++-- spec/presenters/avatar_presenter_spec.rb | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 1109c2a4c..c7564c5be 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -54,13 +54,13 @@ describe ApplicationHelper, :type => :helper do end it 'includes jquery.js from asset pipeline' do - expect(helper.jquery_include_tag).to match(/jquery3\.js/) + expect(helper.jquery_include_tag).to match(/jquery3-[0-9a-f]{64}\.js/) expect(helper.jquery_include_tag).not_to match(/jquery\.com/) end end it 'inclues jquery_ujs.js' do - expect(helper.jquery_include_tag).to match(/jquery_ujs\.js/) + expect(helper.jquery_include_tag).to match(/jquery_ujs-[0-9a-f]{64}\.js/) end it "disables ajax caching" do diff --git a/spec/presenters/avatar_presenter_spec.rb b/spec/presenters/avatar_presenter_spec.rb index 0a7daea6a..f51b4ef83 100644 --- a/spec/presenters/avatar_presenter_spec.rb +++ b/spec/presenters/avatar_presenter_spec.rb @@ -10,11 +10,10 @@ describe AvatarPresenter do it "returns the default images if no images set" do @profile = FactoryGirl.create(:profile, person: alice.person) @presenter = AvatarPresenter.new(@profile) - expect(@presenter.base_hash).to eq( - small: "/assets/user/default.png", - medium: "/assets/user/default.png", - large: "/assets/user/default.png" - ) + expect(@presenter.base_hash.keys).to eq(%i[small medium large]) + expect(@presenter.base_hash[:small]).to match(%r{/assets/user/default-[0-9a-f]{64}\.png}) + expect(@presenter.base_hash[:medium]).to match(%r{/assets/user/default-[0-9a-f]{64}\.png}) + expect(@presenter.base_hash[:large]).to match(%r{/assets/user/default-[0-9a-f]{64}\.png}) end end end From a797f2d27b4827e1529ca80b2681b0d16ac7aa5a Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 30 Jul 2017 05:43:18 +0200 Subject: [PATCH 7/7] Don't precompile all themes for tests And sprockets 3 also caches files in tmp/cache/assets/sprockets --- .travis.yml | 2 +- config/environments/test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da4e27666..e4b310171 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ cache: bundler: true directories: - app/assets/images - - tmp/cache/assets/test + - tmp/cache/assets branches: only: diff --git a/config/environments/test.rb b/config/environments/test.rb index ad06a51ac..7df9c1b93 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -22,6 +22,14 @@ Diaspora::Application.configure do # Precompile poltergeist_disable_transition.css for tests config.assets.precompile += %w[poltergeist_disable_transition.css] + # Don't precompile all themes for tests + config.assets.precompile -= %w[color_themes/*/desktop.css color_themes/*/mobile.css] + config.assets.precompile += %w[ + color_themes/original/desktop.css + color_themes/dark_green/desktop.css + color_themes/original/mobile.css + ] + # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false