diff -Nru ruby-sprockets-rails-2.3.2/CHANGELOG.md ruby-sprockets-rails-3.2.1/CHANGELOG.md --- ruby-sprockets-rails-2.3.2/CHANGELOG.md 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/CHANGELOG.md 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,9 @@ +# Master + +## 3.2.1 + +- Fix load error with `ActionView::Helpers`. [#383] + +## 3.2.0 + +- Add new config option `config.assets.unknown_asset_fallback` when set to a falsy value will error when a requested asset is not in the pipeline. [#375] diff -Nru ruby-sprockets-rails-2.3.2/CONTRIBUTING.md ruby-sprockets-rails-3.2.1/CONTRIBUTING.md --- ruby-sprockets-rails-2.3.2/CONTRIBUTING.md 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/CONTRIBUTING.md 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,99 @@ +Contributing to Sprockets Rails +===================== + +[![Build Status](https://travis-ci.org/rails/sprockets-rails.svg?branch=master)](https://travis-ci.org/rails/sprockets-rails) + +Sprockets Rails is work of [many contributors](https://github.com/rails/sprockets-rails/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/rails/sprockets-rails/pulls), [propose features and discuss issues](https://github.com/rails/sprockets-rails/issues). + +#### Fork the Project + +Fork the [project on Github](https://github.com/rails/sprockets-rails) and check out your copy. + +``` +git clone https://github.com/contributor/sprockets-rails.git +cd sprockets-rails +git remote add upstream https://github.com/rails/sprockets-rails.git +``` + +#### Create a Topic Branch + +Make sure your fork is up-to-date and create a topic branch for your feature or bug fix. + +``` +git checkout master +git pull upstream master +git checkout -b my-feature-branch +``` + +#### Bundle Install and Test + +Ensure that you can build the project and run tests. + +``` +bundle install +bundle exec rake test +``` + +#### Write Tests + +Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [test](test). + +We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix. + +#### Write Code + +Implement your feature or bug fix. + +Make sure that `bundle exec rake test` completes without errors. + +#### Write Documentation + +Document any external behavior in the [README](README.md). + +#### Commit Changes + +Make sure git knows your name and email address: + +``` +git config --global user.name "Your Name" +git config --global user.email "contributor@example.com" +``` + +Writing good commit logs is important. A commit log should describe what changed and why. + +``` +git add ... +git commit +``` + +#### Push + +``` +git push origin my-feature-branch +``` + +#### Make a Pull Request + +Go to https://github.com/contributor/sprockets-rails and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days. + +#### Rebase + +If you've been working on a change for a while, rebase with upstream/master. + +``` +git fetch upstream +git rebase upstream/master +git push origin my-feature-branch -f +``` + +#### Check on Your Pull Request + +Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above. + +#### Be Patient + +It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there! + +#### Thank You + +Please do know that we really appreciate and value your time and work. We love you, really. diff -Nru ruby-sprockets-rails-2.3.2/debian/changelog ruby-sprockets-rails-3.2.1/debian/changelog --- ruby-sprockets-rails-2.3.2/debian/changelog 2015-12-12 18:21:32.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/debian/changelog 2019-02-06 20:56:35.000000000 +0000 @@ -1,3 +1,27 @@ +ruby-sprockets-rails (3.2.1-1) unstable; urgency=medium + + [ Pirate Praveen ] + * New upstream version 3.2.1 + * Bump debhelper compatibility level to 11 + * Bump Standards-Version to 4.3.0 (no changes needed) + + [ Utkarsh Gupta ] + * Adding myself as an uploader + * Add extended description + + -- Utkarsh Gupta Thu, 07 Feb 2019 02:26:35 +0530 + +ruby-sprockets-rails (2.3.2+git-1) unstable; urgency=medium + + * Same upstream release, but tarball fetched from upstream github. + * Added debian/ruby-tests.rake. + * debian/watch: fetch from upstream's github instead. + * Bump standard-version to 4.2.1 without any other changes. + * debian/control: updated Vcs tags. + * Fetched upstream tarbll from github instead of from rubygems.org. + + -- Andrew Lee (李健秋) Wed, 21 Nov 2018 15:17:35 +0800 + ruby-sprockets-rails (2.3.2-1) unstable; urgency=medium * Upload to unstable diff -Nru ruby-sprockets-rails-2.3.2/debian/compat ruby-sprockets-rails-3.2.1/debian/compat --- ruby-sprockets-rails-2.3.2/debian/compat 2015-12-12 18:21:32.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/debian/compat 2019-02-06 20:56:35.000000000 +0000 @@ -1 +1 @@ -9 +11 diff -Nru ruby-sprockets-rails-2.3.2/debian/control ruby-sprockets-rails-3.2.1/debian/control --- ruby-sprockets-rails-2.3.2/debian/control 2015-12-12 18:21:32.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/debian/control 2019-02-06 20:56:35.000000000 +0000 @@ -2,16 +2,17 @@ Section: ruby Priority: optional Maintainer: Debian Ruby Extras Maintainers -Uploaders: Antonio Terceiro -Build-Depends: debhelper (>= 9~), +Uploaders: Utkarsh Gupta +Build-Depends: debhelper (>= 11~), gem2deb, ruby-actionpack (>= 2:3.0), ruby-activesupport (>= 2:3.0), ruby-sprockets (<< 4.0), - ruby-sprockets (>= 2.8) -Standards-Version: 3.9.6 -Vcs-Git: git://anonscm.debian.org/pkg-ruby-extras/ruby-sprockets-rails.git -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-ruby-extras/ruby-sprockets-rails.git + ruby-sprockets (>= 2.8), + ruby-rails +Standards-Version: 4.3.0 +Vcs-Git: https://salsa.debian.org/ruby-team/ruby-sprockets-rails.git +Vcs-Browser: https://salsa.debian.org/ruby-team/ruby-sprockets-rails Homepage: https://github.com/rails/sprockets-rails Testsuite: autopkgtest-pkg-ruby XS-Ruby-Versions: all @@ -26,6 +27,12 @@ ruby-sprockets (>= 2.8), ${misc:Depends}, ${shlibs:Depends} +Breaks: rails (<< 2:5.2.2+dfsg-4) Description: Sprockets Rails integration (part of Rails) This package provides Sprockets implementation for Rails 4.x (and beyond) Asset Pipeline. + . + If the basic tasks don't do all that you need, it's straight forward to + redefine them and replace them with something more specific to your app. + . + You can also redefine the task with the built in task generator. diff -Nru ruby-sprockets-rails-2.3.2/debian/copyright ruby-sprockets-rails-3.2.1/debian/copyright --- ruby-sprockets-rails-2.3.2/debian/copyright 2015-12-12 18:21:32.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/debian/copyright 2019-02-06 20:56:35.000000000 +0000 @@ -1,4 +1,4 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: sprockets-rails Source: https://github.com/rails/sprockets-rails diff -Nru ruby-sprockets-rails-2.3.2/debian/ruby-tests.rake ruby-sprockets-rails-3.2.1/debian/ruby-tests.rake --- ruby-sprockets-rails-2.3.2/debian/ruby-tests.rake 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/debian/ruby-tests.rake 2019-02-06 20:56:35.000000000 +0000 @@ -0,0 +1,8 @@ +require 'gem2deb/rake/testtask' + +Gem2Deb::Rake::TestTask.new do |t| + t.libs << "test" + t.test_files = FileList['test/test_*.rb'] + t.verbose = true +end + diff -Nru ruby-sprockets-rails-2.3.2/debian/watch ruby-sprockets-rails-3.2.1/debian/watch --- ruby-sprockets-rails-2.3.2/debian/watch 2015-12-12 18:21:32.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/debian/watch 2019-02-06 20:56:35.000000000 +0000 @@ -1,2 +1,3 @@ version=3 -http://pkg-ruby-extras.alioth.debian.org/cgi-bin/gemwatch/sprockets-rails .*/sprockets-rails-(.*).tar.gz +opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/v$1\.tar\.gz/" \ + https://github.com/rails/sprockets-rails/tags .*/v?(\d\S*)\.tar\.gz diff -Nru ruby-sprockets-rails-2.3.2/Gemfile ruby-sprockets-rails-3.2.1/Gemfile --- ruby-sprockets-rails-2.3.2/Gemfile 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/Gemfile 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' +gemspec + +gem 'actionpack', github: 'rails/rails', branch: 'master' +gem 'railties', github: 'rails/rails', branch: 'master' +gem 'rack', github: 'rack/rack', branch: 'master' +gem 'sprockets', github: 'rails/sprockets', branch: '3.x' diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-4.0.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-4.0.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-4.0.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-4.0.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' +gemspec :path => ".." + +gem "actionpack", "~> 4.0.0" +gem "railties", "~> 4.0.0" +gem "nokogiri", "< 1.7.0" if RUBY_VERSION < "2.1" +gem "sass", "< 3.5.0" if RUBY_VERSION < "2.0" diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-4.1.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-4.1.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-4.1.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-4.1.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' +gemspec :path => ".." + +gem "actionpack", "~> 4.1.0" +gem "railties", "~> 4.1.0" +gem "nokogiri", "< 1.7.0" if RUBY_VERSION < "2.1" +gem "sass", "< 3.5.0" if RUBY_VERSION < "2.0" diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-4.2.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-4.2.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-4.2.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-4.2.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' +gemspec :path => ".." + +gem 'actionpack', '~> 4.2.0' +gem 'railties', '~> 4.2.0' +gem "nokogiri", "< 1.7.0" if RUBY_VERSION < "2.1" +gem "sass", "< 3.5.0" if RUBY_VERSION < "2.0" diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.0.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.0.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.0.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.0.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,6 @@ +source 'https://rubygems.org' +gemspec path: '..' + +gem 'actionpack', '~> 5.0.0' +gem 'railties', '~> 5.0.0' +gem 'sprockets', github: 'rails/sprockets', branch: '3.x' diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.0.x.sprockets-4.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.0.x.sprockets-4.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.0.x.sprockets-4.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.0.x.sprockets-4.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,6 @@ +source 'https://rubygems.org' +gemspec path: '..' + +gem 'actionpack', '~> 5.0.0' +gem 'railties', '~> 5.0.0' +gem 'sprockets', github: 'rails/sprockets', branch: 'master' diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.1.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.1.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.1.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.1.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' +gemspec path: '..' + +gem 'actionpack', github: 'rails/rails', branch: 'master' +gem 'railties', github: 'rails/rails', branch: 'master' +gem 'rack', github: 'rack/rack', branch: 'master' +gem 'sprockets', github: 'rails/sprockets', branch: '3.x' diff -Nru ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.1.x.sprockets-4.x ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.1.x.sprockets-4.x --- ruby-sprockets-rails-2.3.2/gemfiles/Gemfile.rails-5.1.x.sprockets-4.x 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/gemfiles/Gemfile.rails-5.1.x.sprockets-4.x 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,6 @@ +source 'https://rubygems.org' +gemspec path: '..' + +gem 'actionpack', '~> 5.1.0' +gem 'railties', '~> 5.1.0' +gem 'sprockets', github: 'rails/sprockets', branch: 'master' diff -Nru ruby-sprockets-rails-2.3.2/.gitignore ruby-sprockets-rails-3.2.1/.gitignore --- ruby-sprockets-rails-2.3.2/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/.gitignore 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,3 @@ +Gemfile*.lock +tmp/ +*.gem diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/context.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/context.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/context.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/context.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,48 @@ +require 'action_view/helpers' +require 'sprockets' + +module Sprockets + module Rails + module Context + include ActionView::Helpers::AssetUrlHelper + include ActionView::Helpers::AssetTagHelper + + def self.included(klass) + klass.class_eval do + class_attribute :config, :assets_prefix, :digest_assets + end + end + + def compute_asset_path(path, options = {}) + @dependencies << 'actioncontroller-asset-url-config' + + begin + asset_uri = resolve(path) + rescue FileNotFound + # TODO: eh, we should be able to use a form of locate that returns + # nil instead of raising an exception. + end + + if asset_uri + asset = link_asset(path) + digest_path = asset.digest_path + path = digest_path if digest_assets + File.join(assets_prefix || "/", path) + else + super + end + end + end + end + + register_dependency_resolver 'actioncontroller-asset-url-config' do |env| + config = env.context_class.config + [config.relative_url_root, + (config.asset_host unless config.asset_host.respond_to?(:call))] + end + + # fallback to the default pipeline when using Sprockets 3.x + unless config[:pipelines].include? :debug + register_pipeline :debug, config[:pipelines][:default] + end +end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/helper.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/helper.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/helper.rb 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/helper.rb 2019-02-06 16:11:35.000000000 +0000 @@ -1,128 +1,131 @@ require 'action_view' require 'sprockets' require 'active_support/core_ext/class/attribute' +require 'sprockets/rails/utils' module Sprockets module Rails module Helper - class << self - attr_accessor :precompile, :assets, :raise_runtime_errors - end - - def precompile - Sprockets::Rails::Helper.precompile - end - - def assets - Sprockets::Rails::Helper.assets - end - - def raise_runtime_errors - Sprockets::Rails::Helper.raise_runtime_errors - end + class AssetNotFound < StandardError; end - class AssetFilteredError < StandardError + class AssetNotPrecompiled < StandardError + include Sprockets::Rails::Utils def initialize(source) - msg = "Asset filtered out and will not be served: " << - "add `Rails.application.config.assets.precompile += %w( #{source} )` " << - "to `config/initializers/assets.rb` and restart your server" + msg = + if using_sprockets4? + "Asset `#{ source }` was not declared to be precompiled in production.\n" + + "Declare links to your assets in `app/assets/config/manifest.js`.\n\n" + + " //= link #{ source }\n" + + "and restart your server" + else + "Asset was not declared to be precompiled in production.\n" + + "Add `Rails.application.config.assets.precompile += " + + "%w( #{source} )` to `config/initializers/assets.rb` and " + + "restart your server" + end super(msg) end end - class AbsoluteAssetPathError < ArgumentError - def initialize(bad_path, good_path, prefix) - msg = "Asset names passed to helpers should not include the #{prefix.inspect} prefix. " << - "Instead of #{bad_path.inspect}, use #{good_path.inspect}" - super(msg) - end - end - - if defined? ActionView::Helpers::AssetUrlHelper - include ActionView::Helpers::AssetUrlHelper - include ActionView::Helpers::AssetTagHelper - else - require 'sprockets/rails/legacy_asset_tag_helper' - require 'sprockets/rails/legacy_asset_url_helper' - include LegacyAssetTagHelper - include LegacyAssetUrlHelper - end - - VIEW_ACCESSORS = [:assets_environment, :assets_manifest, - :assets_prefix, :digest_assets, :debug_assets] + include ActionView::Helpers::AssetUrlHelper + include ActionView::Helpers::AssetTagHelper + include Sprockets::Rails::Utils + + VIEW_ACCESSORS = [ + :assets_environment, :assets_manifest, + :assets_precompile, :precompiled_asset_checker, + :assets_prefix, :digest_assets, :debug_assets, + :resolve_assets_with, :check_precompiled_asset, + :unknown_asset_fallback + ] def self.included(klass) - if klass < Sprockets::Context - klass.class_eval do - alias_method :assets_environment, :environment - def assets_manifest; end - class_attribute :config, :assets_prefix, :digest_assets, :debug_assets + klass.class_attribute(*VIEW_ACCESSORS) + + klass.class_eval do + remove_method :assets_environment + def assets_environment + if instance_variable_defined?(:@assets_environment) + @assets_environment = @assets_environment.cached + elsif env = self.class.assets_environment + @assets_environment = env.cached + else + nil + end end - else - klass.class_attribute(*VIEW_ACCESSORS) end end def self.extended(obj) obj.class_eval do attr_accessor(*VIEW_ACCESSORS) + + remove_method :assets_environment + def assets_environment + if env = @assets_environment + @assets_environment = env.cached + else + nil + end + end end end + # Writes over the built in ActionView::Helpers::AssetUrlHelper#compute_asset_path + # to use the asset pipeline. def compute_asset_path(path, options = {}) - # Check if we are inside Sprockets context before calling check_dependencies!. - check_dependencies!(path) if defined?(depend_on) + debug = options[:debug] - if digest_path = asset_digest_path(path) - path = digest_path if digest_assets - path += "?body=1" if options[:debug] - File.join(assets_prefix || "/", path) + if asset_path = resolve_asset_path(path, debug) + File.join(assets_prefix || "/", legacy_debug_path(asset_path, debug)) else + message = "The asset #{ path.inspect } is not present in the asset pipeline." + raise AssetNotFound, message unless unknown_asset_fallback + + if respond_to?(:public_compute_asset_path) + message << "Falling back to an asset that may be in the public folder.\n" + message << "This behavior is deprecated and will be removed.\n" + message << "To bypass the asset pipeline and preserve this behavior,\n" + message << "use the `skip_pipeline: true` option.\n" + + call_stack = Kernel.respond_to?(:caller_locations) && ::Rails::VERSION::MAJOR >= 5 ? caller_locations : caller + ActiveSupport::Deprecation.warn(message, call_stack) + end super end end - # Computes the full URL to a asset in the public directory. This - # method checks for errors before returning path. - def asset_path(source, options = {}) - unless options[:debug] - check_errors_for(source, options) + # Resolve the asset path against the Sprockets manifest or environment. + # Returns nil if it's an asset we don't know about. + def resolve_asset_path(path, allow_non_precompiled = false) #:nodoc: + resolve_asset do |resolver| + resolver.asset_path path, digest_assets, allow_non_precompiled end - super(source, options) end - alias :path_to_asset :asset_path - # Get digest for asset path. + # Expand asset path to digested form. # # path - String path # options - Hash options # - # Returns String Hex digest or nil if digests are disabled. - def asset_digest(path, options = {}) - return unless digest_assets - - if digest_path = asset_digest_path(path, options) - digest_path[/-(.+)\./, 1] + # Returns String path or nil if no asset was found. + def asset_digest_path(path, options = {}) + resolve_asset do |resolver| + resolver.digest_path path, options[:debug] end end - # Expand asset path to digested form. + # Experimental: Get integrity for asset path. # # path - String path # options - Hash options # - # Returns String path or nil if no asset was found. - def asset_digest_path(path, options = {}) - if manifest = assets_manifest - if digest_path = manifest.assets[path] - return digest_path - end - end + # Returns String integrity attribute or nil if no asset was found. + def asset_integrity(path, options = {}) + path = path_with_extname(path, options) - if environment = assets_environment - if asset = environment[path] - return asset.digest_path - end + resolve_asset do |resolver| + resolver.integrity path end end @@ -131,21 +134,27 @@ # Eventually will be deprecated and replaced by source maps. def javascript_include_tag(*sources) options = sources.extract_options!.stringify_keys + integrity = compute_integrity?(options) if options["debug"] != false && request_debug_assets? sources.map { |source| - check_errors_for(source, :type => :javascript) - if asset = lookup_asset_for_path(source, :type => :javascript) - asset.to_a.map do |a| - super(path_to_javascript(a.logical_path, :debug => true), options) + if asset = lookup_debug_asset(source, type: :javascript) + if asset.respond_to?(:to_a) + asset.to_a.map do |a| + super(path_to_javascript(a.logical_path, debug: true), options) + end + else + super(path_to_javascript(asset.logical_path, debug: true), options) end else super(source, options) end }.flatten.uniq.join("\n").html_safe else - sources.push(options) - super(*sources) + sources.map { |source| + options = options.merge('integrity' => asset_integrity(source, type: :javascript)) if integrity + super source, options + }.join("\n").html_safe end end @@ -154,81 +163,206 @@ # Eventually will be deprecated and replaced by source maps. def stylesheet_link_tag(*sources) options = sources.extract_options!.stringify_keys + integrity = compute_integrity?(options) + if options["debug"] != false && request_debug_assets? sources.map { |source| - check_errors_for(source, :type => :stylesheet) - if asset = lookup_asset_for_path(source, :type => :stylesheet) - asset.to_a.map do |a| - super(path_to_stylesheet(a.logical_path, :debug => true), options) + if asset = lookup_debug_asset(source, type: :stylesheet) + if asset.respond_to?(:to_a) + asset.to_a.map do |a| + super(path_to_stylesheet(a.logical_path, debug: true), options) + end + else + super(path_to_stylesheet(asset.logical_path, debug: true), options) end else super(source, options) end }.flatten.uniq.join("\n").html_safe else - sources.push(options) - super(*sources) + sources.map { |source| + options = options.merge('integrity' => asset_integrity(source, type: :stylesheet)) if integrity + super source, options + }.join("\n").html_safe end end protected - # Ensures the asset is included in the dependencies list. - def check_dependencies!(dep) - depend_on(dep) - depend_on_asset(dep) - rescue Sprockets::FileNotFound + # This is awkward: `integrity` is a boolean option indicating whether + # we want to include or omit the subresource integrity hash, but the + # options hash is also passed through as literal tag attributes. + # That means we have to delete the shortcut boolean option so it + # doesn't bleed into the tag attributes, but also check its value if + # it's boolean-ish. + def compute_integrity?(options) + if secure_subresource_integrity_context? + case options['integrity'] + when nil, false, true + options.delete('integrity') == true + end + else + options.delete 'integrity' + false + end end - # Raise errors when source is not in the precompiled list, or - # incorrectly contains the assets_prefix. - def check_errors_for(source, options) - return unless self.raise_runtime_errors + # Only serve integrity metadata for HTTPS requests: + # http://www.w3.org/TR/SRI/#non-secure-contexts-remain-non-secure + def secure_subresource_integrity_context? + respond_to?(:request) && self.request && (self.request.local? || self.request.ssl?) + end - source = source.to_s - return if source.blank? || source =~ URI_REGEXP + # Enable split asset debugging. Eventually will be deprecated + # and replaced by source maps in Sprockets 3.x. + def request_debug_assets? + debug_assets || (defined?(controller) && controller && params[:debug_assets]) + rescue # FIXME: what exactly are we rescuing? + false + end - asset = lookup_asset_for_path(source, options) + # Internal method to support multifile debugging. Will + # eventually be removed w/ Sprockets 3.x. + def lookup_debug_asset(path, options = {}) + path = path_with_extname(path, options) - if asset && asset_needs_precompile?(asset.logical_path, asset.pathname.to_s) - raise AssetFilteredError.new(asset.logical_path) + resolve_asset do |resolver| + resolver.find_debug_asset path end + end - full_prefix = File.join(self.assets_prefix || "/", '') - if !asset && source.start_with?(full_prefix) - short_path = source[full_prefix.size, source.size] - if lookup_asset_for_path(short_path, options) - raise AbsoluteAssetPathError.new(source, short_path, full_prefix) + # compute_asset_extname is in AV::Helpers::AssetUrlHelper + def path_with_extname(path, options) + path = path.to_s + "#{path}#{compute_asset_extname(path, options)}" + end + + # Try each asset resolver and return the first non-nil result. + def resolve_asset + asset_resolver_strategies.detect do |resolver| + if result = yield(resolver) + break result end end end - # Returns true when an asset will not be available after precompile is run - def asset_needs_precompile?(source, filename) - if assets_environment && assets_environment.send(:matches_filter, precompile || [], source, filename) - false + # List of resolvers in `config.assets.resolve_with` order. + def asset_resolver_strategies + @asset_resolver_strategies ||= + Array(resolve_assets_with).map do |name| + HelperAssetResolvers[name].new(self) + end + end + + # Append ?body=1 if debug is on and we're on old Sprockets. + def legacy_debug_path(path, debug) + if debug && !using_sprockets4? + "#{path}?body=1" else - true + path end end + end - # Enable split asset debugging. Eventually will be deprecated - # and replaced by source maps in Sprockets 3.x. - def request_debug_assets? - debug_assets || (defined?(controller) && controller && params[:debug_assets]) - rescue - return false + # Use a separate module since Helper is mixed in and we needn't pollute + # the class namespace with our internals. + module HelperAssetResolvers #:nodoc: + def self.[](name) + case name + when :manifest + Manifest + when :environment + Environment + else + raise ArgumentError, "Unrecognized asset resolver: #{name.inspect}. Expected :manifest or :environment" end + end - # Internal method to support multifile debugging. Will - # eventually be removed w/ Sprockets 3.x. - def lookup_asset_for_path(path, options = {}) - return unless env = assets_environment - path = path.to_s - if extname = compute_asset_extname(path, options) - path = "#{path}#{extname}" + class Manifest #:nodoc: + def initialize(view) + @manifest = view.assets_manifest + raise ArgumentError, 'config.assets.resolve_with includes :manifest, but app.assets_manifest is nil' unless @manifest + end + + def asset_path(path, digest, allow_non_precompiled = false) + if digest + digest_path path, allow_non_precompiled + end + end + + def digest_path(path, allow_non_precompiled = false) + @manifest.assets[path] + end + + def integrity(path) + if meta = metadata(path) + meta["integrity"] + end + end + + def find_debug_asset(path) + nil + end + + private + def metadata(path) + if digest_path = digest_path(path) + @manifest.files[digest_path] + end + end + end + + class Environment #:nodoc: + def initialize(view) + raise ArgumentError, 'config.assets.resolve_with includes :environment, but app.assets is nil' unless view.assets_environment + @env = view.assets_environment + @precompiled_asset_checker = view.precompiled_asset_checker + @check_precompiled_asset = view.check_precompiled_asset + end + + def asset_path(path, digest, allow_non_precompiled = false) + # Digests enabled? Do the work to calculate the full asset path. + if digest + digest_path path, allow_non_precompiled + + # Otherwise, ask the Sprockets environment whether the asset exists + # and check whether it's also precompiled for production deploys. + elsif asset = find_asset(path) + raise_unless_precompiled_asset asset.logical_path unless allow_non_precompiled + path + end + end + + def digest_path(path, allow_non_precompiled = false) + if asset = find_asset(path) + raise_unless_precompiled_asset asset.logical_path unless allow_non_precompiled + asset.digest_path end - env[path] end + + def integrity(path) + find_asset(path).try :integrity + end + + def find_debug_asset(path) + if asset = find_asset(path, pipeline: :debug) + raise_unless_precompiled_asset asset.logical_path.sub('.debug', '') + asset + end + end + + private + def find_asset(path, options = {}) + @env[path, options] + end + + def precompiled?(path) + @precompiled_asset_checker.call path + end + + def raise_unless_precompiled_asset(path) + raise Helper::AssetNotPrecompiled.new(path) if @check_precompiled_asset && !precompiled?(path) + end + end end end end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/legacy_asset_tag_helper.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/legacy_asset_tag_helper.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/legacy_asset_tag_helper.rb 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/legacy_asset_tag_helper.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -require 'sprockets' - -module Sprockets - module Rails - # Backports of AssetTagHelper methods for Rails 2.x and 3.x. - module LegacyAssetTagHelper - include ActionView::Helpers::TagHelper - - def javascript_include_tag(*sources) - options = sources.extract_options!.stringify_keys - sources.uniq.map { |source| - tag_options = { - "src" => path_to_javascript(source) - }.merge(options) - content_tag(:script, "", tag_options) - }.join("\n").html_safe - end - - def stylesheet_link_tag(*sources) - options = sources.extract_options!.stringify_keys - sources.uniq.map { |source| - tag_options = { - "rel" => "stylesheet", - "media" => "screen", - "href" => path_to_stylesheet(source) - }.merge(options) - tag(:link, tag_options) - }.join("\n").html_safe - end - end - end -end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/legacy_asset_url_helper.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/legacy_asset_url_helper.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/legacy_asset_url_helper.rb 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/legacy_asset_url_helper.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,133 +0,0 @@ -require 'sprockets' - -module Sprockets - module Rails - # Backports of AssetUrlHelper methods for Rails 2.x and 3.x. - module LegacyAssetUrlHelper - URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//} - - def asset_path(source, options = {}) - source = source.to_s - return "" unless source.present? - return source if source =~ URI_REGEXP - - tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '') - - if extname = compute_asset_extname(source, options) - source = "#{source}#{extname}" - end - - if source[0] != ?/ - source = compute_asset_path(source, options) - end - - relative_url_root = defined?(config.relative_url_root) && config.relative_url_root - if relative_url_root - source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/") - end - - if host = compute_asset_host(source, options) - source = "#{host}#{source}" - end - - "#{source}#{tail}" - end - alias_method :path_to_asset, :asset_path - - def asset_url(source, options = {}) - path_to_asset(source, options.merge(:protocol => :request)) - end - - ASSET_EXTENSIONS = { - :javascript => '.js', - :stylesheet => '.css' - } - - def compute_asset_extname(source, options = {}) - return if options[:extname] == false - extname = options[:extname] || ASSET_EXTENSIONS[options[:type]] - extname if extname && File.extname(source) != extname - end - - ASSET_PUBLIC_DIRECTORIES = { - :audio => '/audios', - :font => '/fonts', - :image => '/images', - :javascript => '/javascripts', - :stylesheet => '/stylesheets', - :video => '/videos' - } - - def compute_asset_path(source, options = {}) - dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || "" - File.join(dir, source) - end - - def compute_asset_host(source = "", options = {}) - request = self.request if respond_to?(:request) - - if defined? config - host = config.asset_host - elsif defined? ActionController::Base.asset_host - host = ActionController::Base.asset_host - end - - host ||= request.base_url if request && options[:protocol] == :request - return unless host - - if host.respond_to?(:call) - arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity - args = [source] - args << request if request && (arity > 1 || arity < 0) - host = host.call(*args) - elsif host =~ /%d/ - host = host % (Zlib.crc32(source) % 4) - end - - if host =~ URI_REGEXP - host - else - protocol = options[:protocol] || (request ? :request : :relative) - case protocol - when :relative - "//#{host}" - when :request - "#{request.protocol}#{host}" - else - "#{protocol}://#{host}" - end - end - end - - def javascript_path(source, options = {}) - path_to_asset(source, {:type => :javascript}.merge(options)) - end - alias_method :path_to_javascript, :javascript_path - - def stylesheet_path(source, options = {}) - path_to_asset(source, {:type => :stylesheet}.merge(options)) - end - alias_method :path_to_stylesheet, :stylesheet_path - - def image_path(source, options = {}) - path_to_asset(source, {:type => :image}.merge(options)) - end - alias_method :path_to_image, :image_path - - def video_path(source, options = {}) - path_to_asset(source, {:type => :video}.merge(options)) - end - alias_method :path_to_video, :video_path - - def audio_path(source, options = {}) - path_to_asset(source, {:type => :audio}.merge(options)) - end - alias_method :path_to_audio, :audio_path - - def font_path(source, options = {}) - path_to_asset(source, {:type => :font}.merge(options)) - end - alias_method :path_to_font, :font_path - end - end -end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/quiet_assets.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/quiet_assets.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,18 @@ +module Sprockets + module Rails + class QuietAssets + def initialize(app) + @app = app + @assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix}) + end + + def call(env) + if env['PATH_INFO'] =~ @assets_regex + ::Rails.logger.silence { @app.call(env) } + else + @app.call(env) + end + end + end + end +end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/route_wrapper.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/route_wrapper.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/route_wrapper.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/route_wrapper.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,23 @@ +module Sprockets + module Rails + module RouteWrapper + + def internal_assets_path? + path =~ %r{\A#{self.class.assets_prefix}\z} + end + + def internal? + super || internal_assets_path? + end + + def self.included(klass) + klass.class_eval do + def internal_with_sprockets? + internal_without_sprockets? || internal_assets_path? + end + alias_method_chain :internal?, :sprockets + end + end + end + end +end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/task.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/task.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/task.rb 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/task.rb 2019-02-06 16:11:35.000000000 +0000 @@ -16,7 +16,9 @@ def environment if app - app.assets + # Use initialized app.assets or force build an environment if + # config.assets.compile is disabled + app.assets || Sprockets::Railtie.build_environment(app) else super end @@ -24,7 +26,8 @@ def output if app - File.join(app.root, 'public', app.config.assets.prefix) + config = app.config + File.join(config.paths['public'].first, config.assets.prefix) else super end @@ -46,17 +49,12 @@ end end - def cache_path - if app - "#{app.config.root}/tmp/cache/assets" - else - @cache_path - end - end - attr_writer :cache_path - def define namespace :assets do + %w( environment precompile clean clobber ).each do |task| + Rake::Task[task].clear if Rake::Task.task_defined?(task) + end + # Override this task change the loaded dependencies desc "Load asset compile environment" task :environment do @@ -73,9 +71,8 @@ desc "Remove old compiled assets" task :clean, [:keep] => :environment do |t, args| - keep = Integer(args.keep || 2) with_logger do - manifest.clean(keep) + manifest.clean(Integer(args.keep || self.keep)) end end @@ -83,7 +80,6 @@ task :clobber => :environment do with_logger do manifest.clobber - rm_rf cache_path if cache_path end end end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/utils.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/utils.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/utils.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/utils.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,11 @@ +require 'sprockets' + +module Sprockets + module Rails + module Utils + def using_sprockets4? + Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('4.x') + end + end + end +end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/rails/version.rb ruby-sprockets-rails-3.2.1/lib/sprockets/rails/version.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/rails/version.rb 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/rails/version.rb 2019-02-06 16:11:35.000000000 +0000 @@ -1,5 +1,5 @@ module Sprockets module Rails - VERSION = "2.3.2" + VERSION = "3.2.1" end end diff -Nru ruby-sprockets-rails-2.3.2/lib/sprockets/railtie.rb ruby-sprockets-rails-3.2.1/lib/sprockets/railtie.rb --- ruby-sprockets-rails-2.3.2/lib/sprockets/railtie.rb 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/lib/sprockets/railtie.rb 2019-02-06 16:11:35.000000000 +0000 @@ -2,9 +2,14 @@ require 'rails/railtie' require 'action_controller/railtie' require 'active_support/core_ext/module/remove_method' +require 'active_support/core_ext/numeric/bytes' require 'sprockets' +require 'sprockets/rails/context' require 'sprockets/rails/helper' +require 'sprockets/rails/quiet_assets' +require 'sprockets/rails/route_wrapper' require 'sprockets/rails/version' +require 'set' module Rails class Application @@ -19,37 +24,40 @@ remove_possible_method :assets= # Returns Sprockets::Environment for app config. - def assets - @assets ||= Sprockets::Environment.new(root.to_s) do |env| - env.version = ::Rails.env + attr_accessor :assets - path = "#{config.root}/tmp/cache/assets/#{::Rails.env}" - env.cache = Sprockets::Cache::FileStore.new(path) + # Returns Sprockets::Manifest for app config. + attr_accessor :assets_manifest - env.context_class.class_eval do - include ::Sprockets::Rails::Helper - end + # Called from asset helpers to alert you if you reference an asset URL that + # isn't precompiled and hence won't be available in production. + def asset_precompiled?(logical_path) + if precompiled_assets.include?(logical_path) + true + elsif !config.cache_classes + # Check to see if precompile list has been updated + precompiled_assets(true).include?(logical_path) + else + false end end - attr_writer :assets - # Returns Sprockets::Manifest for app config. - attr_accessor :assets_manifest + # Lazy-load the precompile list so we don't cause asset compilation at app + # boot time, but ensure we cache the list so we don't recompute it for each + # request or test case. + def precompiled_assets(clear_cache = false) + @precompiled_assets = nil if clear_cache + @precompiled_assets ||= assets_manifest.find(config.assets.precompile).map(&:logical_path).to_set + end end class Engine < Railtie # Skip defining append_assets_path on Rails <= 4.2 unless initializers.find { |init| init.name == :append_assets_path } initializer :append_assets_path, :group => :all do |app| - if paths["app/assets"].respond_to?(:existent_directories) - app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) - app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) - app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) - else - app.config.assets.paths.unshift(*paths["vendor/assets"].paths.select { |d| File.directory?(d) }) - app.config.assets.paths.unshift(*paths["lib/assets"].paths.select { |d| File.directory?(d) }) - app.config.assets.paths.unshift(*paths["app/assets"].paths.select { |d| File.directory?(d) }) - end + app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) end end end @@ -57,8 +65,25 @@ module Sprockets class Railtie < ::Rails::Railtie - LOOSE_APP_ASSETS = lambda do |filename, path| - path =~ /app\/assets/ && !%w(.js .css).include?(File.extname(filename)) + include Sprockets::Rails::Utils + + class ManifestNeededError < StandardError + def initialize + msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" + + "But did not, please create this file and use it to link any assets that need\n" + + "to be rendered by your app:\n\n" + + "Example:\n" + + " //= link_tree ../images\n" + + " //= link_directory ../javascripts .js\n" + + " //= link_directory ../stylesheets .css\n" + + "and restart your server" + super msg + end + end + + LOOSE_APP_ASSETS = lambda do |logical_path, filename| + filename.start_with?(::Rails.root.join("app/assets").to_s) && + !['.js', '.css', ''].include?(File.extname(logical_path)) end class OrderedOptions < ActiveSupport::OrderedOptions @@ -68,90 +93,162 @@ end config.assets = OrderedOptions.new - config.assets._blocks = [] - config.assets.paths = [] - config.assets.prefix = "/assets" - config.assets.manifest = nil - config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/] - config.assets.version = "" - config.assets.debug = false - config.assets.compile = true - config.assets.digest = false + config.assets._blocks = [] + config.assets.paths = [] + config.assets.precompile = [] + config.assets.prefix = "/assets" + config.assets.manifest = nil + config.assets.quiet = false + + initializer :set_default_precompile do |app| + if using_sprockets4? + raise ManifestNeededError unless ::Rails.root.join("app/assets/config/manifest.js").exist? + app.config.assets.precompile += %w( manifest.js ) + else + app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/] + end + end + + initializer :quiet_assets do |app| + if app.config.assets.quiet + app.middleware.insert_before ::Rails::Rack::Logger, ::Sprockets::Rails::QuietAssets + end + end + + config.assets.version = "" + config.assets.debug = false + config.assets.compile = true + config.assets.digest = true + config.assets.cache_limit = 50.megabytes + config.assets.gzip = true + config.assets.check_precompiled_asset = true + config.assets.unknown_asset_fallback = true + + config.assets.configure do |env| + config.assets.paths.each { |path| env.append_path(path) } + end + + config.assets.configure do |env| + env.context_class.send :include, ::Sprockets::Rails::Context + env.context_class.assets_prefix = config.assets.prefix + env.context_class.digest_assets = config.assets.digest + env.context_class.config = config.action_controller + end + + config.assets.configure do |env| + env.cache = Sprockets::Cache::FileStore.new( + "#{env.root}/tmp/cache/assets", + config.assets.cache_limit, + env.logger + ) + end + + Sprockets.register_dependency_resolver 'rails-env' do + ::Rails.env.to_s + end + + config.assets.configure do |env| + env.depend_on 'rails-env' + end + + config.assets.configure do |env| + env.version = config.assets.version + end + + config.assets.configure do |env| + env.gzip = config.assets.gzip if env.respond_to?(:gzip=) + end rake_tasks do |app| require 'sprockets/rails/task' Sprockets::Rails::Task.new(app) end - config.after_initialize do |app| - config = app.config - - # Configuration options that should invalidate - # the Sprockets cache when changed. - app.assets.version = [ - app.assets.version, - config.assets.version, - config.action_controller.relative_url_root, - (config.action_controller.asset_host unless config.action_controller.asset_host.respond_to?(:call)), - Sprockets::Rails::VERSION - ].compact.join('-') - - # Copy config.assets.paths to Sprockets - config.assets.paths.each do |path| - app.assets.append_path path + def build_environment(app, initialized = nil) + initialized = app.initialized? if initialized.nil? + unless initialized + ::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!" end - app.assets.js_compressor = config.assets.js_compressor - app.assets.css_compressor = config.assets.css_compressor + env = Sprockets::Environment.new(app.root.to_s) + + config = app.config # Run app.assets.configure blocks config.assets._blocks.each do |block| - block.call app.assets + block.call(env) end + # Set compressors after the configure blocks since they can + # define new compressors and we only accept existent compressors. + env.js_compressor = config.assets.js_compressor + env.css_compressor = config.assets.css_compressor + # No more configuration changes at this point. # With cache classes on, Sprockets won't check the FS when files # change. Preferable in production when the FS only changes on # deploys when the app restarts. if config.cache_classes - app.assets = app.assets.index + env = env.cached end - manifest_assets_path = File.join(config.paths['public'].first, config.assets.prefix) + env + end + + def self.build_manifest(app) + config = app.config + path = File.join(config.paths['public'].first, config.assets.prefix) + Sprockets::Manifest.new(app.assets, path, config.assets.manifest) + end + + config.after_initialize do |app| + config = app.config + if config.assets.compile - app.assets_manifest = Sprockets::Manifest.new(app.assets, manifest_assets_path, config.assets.manifest) - else - app.assets_manifest = Sprockets::Manifest.new(manifest_assets_path, config.assets.manifest) + app.assets = self.build_environment(app, true) + app.routes.prepend do + mount app.assets => config.assets.prefix + end + end + + app.assets_manifest = build_manifest(app) + + if config.assets.resolve_with.nil? + config.assets.resolve_with = [] + config.assets.resolve_with << :manifest if config.assets.digest && !config.assets.debug + config.assets.resolve_with << :environment if config.assets.compile + end + + ActionDispatch::Routing::RouteWrapper.class_eval do + class_attribute :assets_prefix + + if defined?(prepend) && ::Rails.version >= '4' + prepend Sprockets::Rails::RouteWrapper + else + include Sprockets::Rails::RouteWrapper + end + + self.assets_prefix = config.assets.prefix end ActiveSupport.on_load(:action_view) do include Sprockets::Rails::Helper # Copy relevant config to AV context - self.debug_assets = config.assets.debug - self.digest_assets = config.assets.digest - self.assets_prefix = config.assets.prefix + self.debug_assets = config.assets.debug + self.digest_assets = config.assets.digest + self.assets_prefix = config.assets.prefix + self.assets_precompile = config.assets.precompile - # Copy over to Sprockets as well - context = app.assets.context_class - context.assets_prefix = config.assets.prefix - context.digest_assets = config.assets.digest - context.config = config.action_controller - - self.assets_environment = app.assets if config.assets.compile + self.assets_environment = app.assets self.assets_manifest = app.assets_manifest - end - Sprockets::Rails::Helper.precompile ||= app.config.assets.precompile - Sprockets::Rails::Helper.assets ||= app.assets - Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors + self.resolve_assets_with = config.assets.resolve_with - if config.assets.compile - if app.routes.respond_to?(:prepend) - app.routes.prepend do - mount app.assets => config.assets.prefix - end - end + self.check_precompiled_asset = config.assets.check_precompiled_asset + self.unknown_asset_fallback = config.assets.unknown_asset_fallback + # Expose the app precompiled asset check to the view + self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path } end end end diff -Nru ruby-sprockets-rails-2.3.2/LICENSE ruby-sprockets-rails-3.2.1/LICENSE --- ruby-sprockets-rails-2.3.2/LICENSE 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/LICENSE 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -Copyright (c) 2014 Joshua Peek - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -Nru ruby-sprockets-rails-2.3.2/metadata.yml ruby-sprockets-rails-3.2.1/metadata.yml --- ruby-sprockets-rails-2.3.2/metadata.yml 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/metadata.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,156 +0,0 @@ ---- !ruby/object:Gem::Specification -name: sprockets-rails -version: !ruby/object:Gem::Version - version: 2.3.2 -platform: ruby -authors: -- Joshua Peek -autorequire: -bindir: bin -cert_chain: [] -date: 2015-06-23 00:00:00.000000000 Z -dependencies: -- !ruby/object:Gem::Dependency - name: sprockets - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '2.8' - - - < - - !ruby/object:Gem::Version - version: '4.0' - type: :runtime - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '2.8' - - - < - - !ruby/object:Gem::Version - version: '4.0' -- !ruby/object:Gem::Dependency - name: actionpack - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '3.0' - type: :runtime - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '3.0' -- !ruby/object:Gem::Dependency - name: activesupport - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '3.0' - type: :runtime - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '3.0' -- !ruby/object:Gem::Dependency - name: railties - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '3.0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '3.0' -- !ruby/object:Gem::Dependency - name: rake - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -- !ruby/object:Gem::Dependency - name: sass - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -- !ruby/object:Gem::Dependency - name: uglifier - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -description: -email: josh@joshpeek.com -executables: [] -extensions: [] -extra_rdoc_files: [] -files: -- README.md -- lib/sprockets/rails/helper.rb -- lib/sprockets/rails/legacy_asset_tag_helper.rb -- lib/sprockets/rails/legacy_asset_url_helper.rb -- lib/sprockets/rails/task.rb -- lib/sprockets/rails/version.rb -- lib/sprockets/rails.rb -- lib/sprockets/railtie.rb -- LICENSE -homepage: https://github.com/rails/sprockets-rails -licenses: -- MIT -metadata: {} -post_install_message: -rdoc_options: [] -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -requirements: [] -rubyforge_project: -rubygems_version: 2.0.14 -signing_key: -specification_version: 4 -summary: Sprockets Rails integration -test_files: [] diff -Nru ruby-sprockets-rails-2.3.2/MIT-LICENSE ruby-sprockets-rails-3.2.1/MIT-LICENSE --- ruby-sprockets-rails-2.3.2/MIT-LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/MIT-LICENSE 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,20 @@ +Copyright (c) 2014-2016 Joshua Peek + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -Nru ruby-sprockets-rails-2.3.2/Rakefile ruby-sprockets-rails-3.2.1/Rakefile --- ruby-sprockets-rails-2.3.2/Rakefile 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/Rakefile 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,11 @@ +require 'rake/testtask' +require 'bundler/gem_tasks' + +task :default => :test + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/test_*.rb' + t.warning = true + t.verbose = true +end diff -Nru ruby-sprockets-rails-2.3.2/README.md ruby-sprockets-rails-3.2.1/README.md --- ruby-sprockets-rails-2.3.2/README.md 2015-07-27 04:50:26.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/README.md 2019-02-06 16:11:35.000000000 +0000 @@ -27,7 +27,7 @@ **`rake assets:clobber`** -Nuke `public/assets` and clear the Sprockets file system cache. +Nuke `public/assets`. #### Customize @@ -37,11 +37,6 @@ ``` ruby require 'sprockets/rails/task' -# clean the old tasks -Rake::Task["assets:environment"].clear -Rake::Task["assets:precompile"].clear -Rake::Task["assets:clean"].clear -Rake::Task["assets:clobber"].clear Sprockets::Rails::Task.new(Rails.application) do |t| t.environment = lambda { Rails.application.assets } t.assets = %w( application.js application.css ) @@ -51,23 +46,25 @@ Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment. -Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb). - +Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/rails/sprockets/blob/master/lib/rake/sprocketstask.rb). ### Initializer options -**`config.assets.precompile`** +**`config.assets.unknown_asset_fallback`** -Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`. +When set to a truthy value, a result will be returned even if the requested asset is not found in the asset pipeline. When set to a falsey value it will raise an error when no asset is found in the pipeline. Defaults to `true`. -**`config.assets.raise_runtime_errors`** +**`config.assets.precompile`** -Set to `true` to enable additional runtime error checking. Recommended in the `development` environment to minimize unexpected behavior when deploying to `production`. +Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`. **`config.assets.paths`** Add additional load paths to this Array. Rails includes `app/assets`, `lib/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to this. +**`config.assets.quiet`** + +Suppresses logger output for asset requests. Uses the `config.assets.prefix` path to match asset requests. Defaults to `false`. **`config.assets.version`** @@ -83,13 +80,9 @@ Defaults to `/assets`. Changes the directory to compile assets to. -**`config.assets.manifest`** - -Defines the full path to be used for the asset precompiler's manifest file. Defaults to a randomly-generated filename in the `config.assets.prefix` directory within the public folder. - **`config.assets.digest`** -Link to undigest asset filenames. This option will eventually go away. Unless when `compile` is disabled. +When enabled, fingerprints will be added to asset filenames. **`config.assets.debug`** @@ -97,7 +90,7 @@ **`config.assets.compile`** -Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`. +Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be `nil` to prevent inadvertent compilation calls. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. Initializers expecting `Rails.application.assets` during boot should be accessing the environment in a `config.assets.configure` block. See below. **`config.assets.configure`** @@ -105,18 +98,38 @@ ``` ruby config.assets.configure do |env| - env.js_compressor = :uglify # or :closure, :yui + env.js_compressor = :uglifier # or :closure, :yui env.css_compressor = :sass # or :yui require 'my_processor' env.register_preprocessor 'application/javascript', MyProcessor env.logger = Rails.logger - - env.cache = ActiveSupport::Cache::FileStore.new("tmp/cache/assets") end ``` +**`config.assets.resolve_with`** + +A list of `:environment` and `:manifest` symbols that defines the order that +we try to find assets: manifest first, environment second? Manifest only? + +By default, we check the manifest first if asset digests are enabled and debug +is not enabled, then we check the environment if compiling is enabled: +``` +# Dev where debug is true, or digests are disabled +%i[ environment ] + +# Dev default, or production with compile enabled. +%i[ manifest environment ] + +# Production default. +%i[ manifest ] +``` +If the resolver list is empty (e.g. if debug is true and compile is false), the standard rails public path resolution will be used. + +**`config.assets.check_precompiled_asset`** + +When enabled, an exception is raised for missing assets. This option is enabled by default. ## Complementary plugins @@ -132,29 +145,35 @@ * Only compiles digest filenames. Static non-digest assets should simply live in public/. * Unmanaged asset paths and urls fallback to linking to public/. This should make it easier to work with both compiled assets and simple static assets. As a side effect, there will never be any "asset not precompiled errors" when linking to missing assets. They will just link to a public file which may or may not exist. -* JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglify` or `config.assets.css_compressor = :sass` for the standard compressors. +* JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglifier` or `config.assets.css_compressor = :sass` for the standard compressors. * The manifest file is now in a JSON format. Since it lives in public/ by default, the initial filename is also randomized to obfuscate public access to the resource. * `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory. -* Two cleanup tasks. `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used. While `rake assets:clobber` nukes the entire `public/assets` directory and clears your filesystem cache. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built. +* Two cleanup tasks: `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used, while `rake assets:clobber` nukes the entire `public/assets` directory. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built. +## Experimental -## Contributing +### [SRI](http://www.w3.org/TR/SRI/) support -Usual bundler workflow. +Sprockets 3.x adds experimental support for subresource integrity checks. The spec is still evolving and the API may change in backwards incompatible ways. -``` shell -$ git clone https://github.com/rails/sprockets-rails.git -$ cd sprockets-rails/ -$ bundle install -$ bundle exec rake test +``` ruby +javascript_include_tag :application, integrity: true +# => "" ``` -[![Build Status](https://secure.travis-ci.org/rails/sprockets-rails.png)](http://travis-ci.org/rails/sprockets-rails) +Note that sprockets-rails only adds integrity hashes to assets when served in a secure context (over an HTTPS connection or localhost). +## Contributing to Sprockets Rails + +Sprockets Rails is work of many contributors. You're encouraged to submit pull requests, propose +features and discuss issues. + +See [CONTRIBUTING](CONTRIBUTING.md). + ## Releases -sprockets-rails 2.x will primarily target sprockets 2.x with future compatibility for 3.x. Consider upgrading to sprockets-rails 3.x to take full advantage of 3.x features. +sprockets-rails 3.x will primarily target sprockets 3.x. And future versions will target the corresponding sprockets release line. The minor and patch version will be updated according to [semver](http://semver.org/). @@ -162,9 +181,12 @@ * Any time the sprockets dependency is bumped, there will be a new minor release * Simple bug fixes will be patch releases - ## License -Copyright © 2014 Joshua Peek. +Sprockets Rails is released under the [MIT License](MIT-LICENSE). + +## Code Status -Released under the MIT license. See `LICENSE` for details. +* [![Travis CI](https://travis-ci.org/rails/sprockets-rails.svg?branch=master)](http://travis-ci.org/rails/sprockets-rails) +* [![Gem Version](https://badge.fury.io/rb/sprockets-rails.svg)](http://badge.fury.io/rb/sprockets-rails) +* [![Dependencies](https://gemnasium.com/rails/sprockets-rails.svg)](https://gemnasium.com/rails/sprockets-rails) diff -Nru ruby-sprockets-rails-2.3.2/sprockets-rails.gemspec ruby-sprockets-rails-3.2.1/sprockets-rails.gemspec --- ruby-sprockets-rails-2.3.2/sprockets-rails.gemspec 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/sprockets-rails.gemspec 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,26 @@ +$:.unshift File.expand_path("../lib", __FILE__) +require "sprockets/rails/version" + +Gem::Specification.new do |s| + s.name = "sprockets-rails" + s.version = Sprockets::Rails::VERSION + + s.homepage = "https://github.com/rails/sprockets-rails" + s.summary = "Sprockets Rails integration" + s.license = "MIT" + + s.files = Dir["README.md", "lib/**/*.rb", "MIT-LICENSE"] + + s.required_ruby_version = '>= 1.9.3' + + s.add_dependency "sprockets", ">= 3.0.0" + s.add_dependency "actionpack", ">= 4.0" + s.add_dependency "activesupport", ">= 4.0" + s.add_development_dependency "railties", ">= 4.0" + s.add_development_dependency "rake" + s.add_development_dependency "sass" + s.add_development_dependency "uglifier" + + s.author = "Joshua Peek" + s.email = "josh@joshpeek.com" +end diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/bar.css ruby-sprockets-rails-3.2.1/test/fixtures/bar.css --- ruby-sprockets-rails-2.3.2/test/fixtures/bar.css 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/bar.css 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +/*= require foo */ diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/bar.js ruby-sprockets-rails-3.2.1/test/fixtures/bar.js --- ruby-sprockets-rails-2.3.2/test/fixtures/bar.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/bar.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,2 @@ +//= require foo +var Bar; diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/bundle/index.js ruby-sprockets-rails-3.2.1/test/fixtures/bundle/index.js --- ruby-sprockets-rails-2.3.2/test/fixtures/bundle/index.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/bundle/index.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +var jQuery; diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/dependency.css ruby-sprockets-rails-3.2.1/test/fixtures/dependency.css --- ruby-sprockets-rails-2.3.2/test/fixtures/dependency.css 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/dependency.css 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +/* dependency */ diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/dependency.js ruby-sprockets-rails-3.2.1/test/fixtures/dependency.js --- ruby-sprockets-rails-2.3.2/test/fixtures/dependency.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/dependency.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +// dependency diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/error/dependency.js.erb ruby-sprockets-rails-3.2.1/test/fixtures/error/dependency.js.erb --- ruby-sprockets-rails-2.3.2/test/fixtures/error/dependency.js.erb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/error/dependency.js.erb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +<%= asset_path("bar.js") %> diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/error/missing.css.erb ruby-sprockets-rails-3.2.1/test/fixtures/error/missing.css.erb --- ruby-sprockets-rails-2.3.2/test/fixtures/error/missing.css.erb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/error/missing.css.erb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +p { background: url(<%= image_path "does_not_exist.png" %>); } diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/file1.css ruby-sprockets-rails-3.2.1/test/fixtures/file1.css --- ruby-sprockets-rails-2.3.2/test/fixtures/file1.css 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/file1.css 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,2 @@ +/*= require dependency + */ diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/file1.js ruby-sprockets-rails-3.2.1/test/fixtures/file1.js --- ruby-sprockets-rails-2.3.2/test/fixtures/file1.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/file1.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +//= require dependency diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/file2.css ruby-sprockets-rails-3.2.1/test/fixtures/file2.css --- ruby-sprockets-rails-2.3.2/test/fixtures/file2.css 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/file2.css 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,2 @@ +/*= require dependency + */ diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/file2.js ruby-sprockets-rails-3.2.1/test/fixtures/file2.js --- ruby-sprockets-rails-2.3.2/test/fixtures/file2.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/file2.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +//= require dependency diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/foo.css ruby-sprockets-rails-3.2.1/test/fixtures/foo.css --- ruby-sprockets-rails-2.3.2/test/fixtures/foo.css 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/foo.css 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +.foo {} diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/foo.js ruby-sprockets-rails-3.2.1/test/fixtures/foo.js --- ruby-sprockets-rails-2.3.2/test/fixtures/foo.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/foo.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +var Foo; \ No newline at end of file diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/jquery/bower.json ruby-sprockets-rails-3.2.1/test/fixtures/jquery/bower.json --- ruby-sprockets-rails-2.3.2/test/fixtures/jquery/bower.json 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/jquery/bower.json 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,4 @@ +{ + "name": "jquery", + "main": "./jquery.js" +} diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/jquery/jquery.js ruby-sprockets-rails-3.2.1/test/fixtures/jquery/jquery.js --- ruby-sprockets-rails-2.3.2/test/fixtures/jquery/jquery.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/jquery/jquery.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +var jQuery; Binary files /tmp/tmpHJfxJy/FCk5dfNjaO/ruby-sprockets-rails-2.3.2/test/fixtures/logo.png and /tmp/tmpHJfxJy/8nxBeVHB64/ruby-sprockets-rails-3.2.1/test/fixtures/logo.png differ diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/manifest.js ruby-sprockets-rails-3.2.1/test/fixtures/manifest.js --- ruby-sprockets-rails-2.3.2/test/fixtures/manifest.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/manifest.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,10 @@ +// manifest.js +//= link foo.css +//= link foo.js +//= link bar.css +//= link bar.js +//= link file1.css +//= link file1.js +//= link file2.css +//= link file2.js +//= link bundle.js diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/not_precompiled.css ruby-sprockets-rails-3.2.1/test/fixtures/not_precompiled.css --- ruby-sprockets-rails-2.3.2/test/fixtures/not_precompiled.css 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/not_precompiled.css 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +.not-precompiled {} diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/not_precompiled.js ruby-sprockets-rails-3.2.1/test/fixtures/not_precompiled.js --- ruby-sprockets-rails-2.3.2/test/fixtures/not_precompiled.js 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/not_precompiled.js 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +var not_precompiled; diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/url.css.erb ruby-sprockets-rails-3.2.1/test/fixtures/url.css.erb --- ruby-sprockets-rails-2.3.2/test/fixtures/url.css.erb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/url.css.erb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +p { background: url(<%= image_path "logo.png" %>); } diff -Nru ruby-sprockets-rails-2.3.2/test/fixtures/url.js.erb ruby-sprockets-rails-3.2.1/test/fixtures/url.js.erb --- ruby-sprockets-rails-2.3.2/test/fixtures/url.js.erb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/fixtures/url.js.erb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1 @@ +var url = '<%= javascript_path :foo %>'; diff -Nru ruby-sprockets-rails-2.3.2/test/test_helper.rb ruby-sprockets-rails-3.2.1/test/test_helper.rb --- ruby-sprockets-rails-2.3.2/test/test_helper.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/test_helper.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,937 @@ +require 'minitest/autorun' + +require 'action_view' +require 'sprockets' +require 'sprockets/rails/context' +require 'sprockets/rails/helper' + +ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=) + +class HelperTest < ActionView::TestCase + FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) + + def setup + @assets = Sprockets::Environment.new + @assets.append_path FIXTURES_PATH + @assets.context_class.class_eval do + include ::Sprockets::Rails::Context + end + tmp = File.expand_path("../../tmp", __FILE__) + @manifest = Sprockets::Manifest.new(@assets, tmp) + + @view = ActionView::Base.new + @view.extend ::Sprockets::Rails::Helper + @view.assets_environment = @assets + @view.assets_manifest = @manifest + @view.resolve_assets_with = [ :manifest, :environment ] + @view.assets_prefix = "/assets" + @view.assets_precompile = %w( manifest.js ) + precompiled_assets = @manifest.find(@view.assets_precompile).map(&:logical_path) + @view.check_precompiled_asset = true + @view.unknown_asset_fallback = true + @view.precompiled_asset_checker = -> logical_path { precompiled_assets.include? logical_path } + @view.request = ActionDispatch::Request.new({ + "rack.url_scheme" => "https" + }) + + @assets.context_class.assets_prefix = @view.assets_prefix + @assets.context_class.config = @view.config + + @foo_js_integrity = @assets['foo.js'].integrity + @foo_css_integrity = @assets['foo.css'].integrity + @bar_js_integrity = @assets['bar.js'].integrity + + @foo_js_digest = @assets['foo.js'].etag + @foo_css_digest = @assets['foo.css'].etag + @bar_js_digest = @assets['bar.js'].etag + @bar_css_digest = @assets['bar.css'].etag + @logo_digest = @assets['logo.png'].etag + + @foo_self_js_digest = @assets['foo.self.js'].etag + @foo_self_css_digest = @assets['foo.self.css'].etag + @bar_self_js_digest = @assets['bar.self.js'].etag + @bar_self_css_digest = @assets['bar.self.css'].etag + + @foo_debug_js_digest = @assets['foo.debug.js'].etag + @foo_debug_css_digest = @assets['foo.debug.css'].etag + @bar_debug_js_digest = @assets['bar.debug.js'].etag + @bar_debug_css_digest = @assets['bar.debug.css'].etag + + @dependency_js_digest = @assets['dependency.js'].etag + @dependency_css_digest = @assets['dependency.css'].etag + @file1_js_digest = @assets['file1.js'].etag + @file1_css_digest = @assets['file1.css'].etag + @file2_js_digest = @assets['file2.js'].etag + @file2_css_digest = @assets['file2.css'].etag + + @dependency_self_js_digest = @assets['dependency.self.js'].etag + @dependency_self_css_digest = @assets['dependency.self.css'].etag + @file1_self_js_digest = @assets['file1.self.js'].etag + @file1_self_css_digest = @assets['file1.self.css'].etag + @file2_self_js_digest = @assets['file2.self.js'].etag + @file2_self_css_digest = @assets['file2.self.css'].etag + + @dependency_debug_js_digest = @assets['dependency.debug.js'].etag + @dependency_debug_css_digest = @assets['dependency.debug.css'].etag + @file1_debug_js_digest = @assets['file1.debug.js'].etag + @file1_debug_css_digest = @assets['file1.debug.css'].etag + @file2_debug_js_digest = @assets['file2.debug.js'].etag + @file2_debug_css_digest = @assets['file2.debug.css'].etag + end + + def using_sprockets4? + Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('4.x') + end + + def test_truth + end + + def test_foo_and_bar_different_digests + refute_equal @foo_js_digest, @bar_js_digest + refute_equal @foo_css_digest, @bar_css_digest + end + + def assert_servable_asset_url(url) + path, query = url.split("?", 2) + path = path.sub(@view.assets_prefix, "") + + status = @assets.call({ + 'REQUEST_METHOD' => 'GET', + 'PATH_INFO' => path, + 'QUERY_STRING' => query + })[0] + assert_equal 200, status, "#{url} responded with #{status}" + end +end + +class NoHostHelperTest < HelperTest + def test_javascript_include_tag + assert_dom_equal %(), + @view.javascript_include_tag("static") + assert_dom_equal %(), + @view.javascript_include_tag("static.js") + assert_dom_equal %(), + @view.javascript_include_tag(:static) + + assert_dom_equal %(), + @view.javascript_include_tag("/elsewhere.js") + assert_dom_equal %(\n), + @view.javascript_include_tag("/script1.js", "script2.js") + + assert_dom_equal %(), + @view.javascript_include_tag("http://example.com/script") + assert_dom_equal %(), + @view.javascript_include_tag("http://example.com/script.js") + assert_dom_equal %(), + @view.javascript_include_tag("//example.com/script.js") + + assert_dom_equal %(), + @view.javascript_include_tag("static", :defer => "defer") + assert_dom_equal %(), + @view.javascript_include_tag("static", :async => "async") + end + + def test_stylesheet_link_tag + assert_dom_equal %(), + @view.stylesheet_link_tag("static") + assert_dom_equal %(), + @view.stylesheet_link_tag("static.css") + assert_dom_equal %(), + @view.stylesheet_link_tag(:static) + + assert_dom_equal %(), + @view.stylesheet_link_tag("/elsewhere.css") + assert_dom_equal %(\n), + @view.stylesheet_link_tag("/style1.css", "style2.css") + + assert_dom_equal %(), + @view.stylesheet_link_tag("http://www.example.com/styles/style") + assert_dom_equal %(), + @view.stylesheet_link_tag("http://www.example.com/styles/style.css") + assert_dom_equal %(), + @view.stylesheet_link_tag("//www.example.com/styles/style.css") + + assert_dom_equal %(), + @view.stylesheet_link_tag("print", :media => "print") + assert_dom_equal %(), + @view.stylesheet_link_tag("print", :media => "") + end + + def test_javascript_include_tag_integrity + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: "sha-256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs=") + + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: false) + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: nil) + end + + def test_stylesheet_link_tag_integrity + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: "sha-256-5YzTQPuOJz/EpeXfN/+v1sxsjAj/dw8q26abiHZM3A4=") + + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: false) + end + + def test_javascript_path + assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr") + assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js") + assert_equal "/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr") + assert_equal "/super/xmlhr.js", @view.javascript_path("/super/xmlhr") + + assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1") + assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1") + assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash") + assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash") + assert_equal "/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash") + end + + def test_stylesheet_path + assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank") + assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank.css") + assert_equal "/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir") + assert_equal "/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css") + + assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1") + assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1") + assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash") + assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash") + assert_equal "/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash") + end +end + +class NoSSLHelperTest < NoHostHelperTest + def setup + super + + @view.request = nil + end + + def test_javascript_include_tag_integrity + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: false) + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: nil) + + assert_dom_equal %(), + @view.javascript_include_tag("static", integrity: "sha-256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs=") + + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: true) + end + + def test_stylesheet_link_tag_integrity + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: false) + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: nil) + + assert_dom_equal %(), + @view.stylesheet_link_tag("static", integrity: "sha-256-5YzTQPuOJz/EpeXfN/+v1sxsjAj/dw8q26abiHZM3A4=") + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: true) + end +end + +class LocalhostHelperTest < NoHostHelperTest + def setup + super + + @view.request = ActionDispatch::Request.new({ + "rack.url_scheme" => "http", + "REMOTE_ADDR" => "127.0.0.1" + }) + end + + def test_javascript_include_tag_integrity + super + + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: false) + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: nil) + + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag("foo.js", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag(:foo, integrity: true) + + assert_dom_equal %(\n), + @view.javascript_include_tag(:foo, :bar, integrity: true) + end + + def test_stylesheet_link_tag_integrity + super + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: false) + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: nil) + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo, integrity: true) + + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:foo, :bar, integrity: true) + end +end + +class RelativeHostHelperTest < HelperTest + def setup + super + + @view.config.asset_host = "assets.example.com" + end + + def test_javascript_path + assert_equal "https://assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr") + assert_equal "https://assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js") + assert_equal "https://assets.example.com/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr") + assert_equal "https://assets.example.com/super/xmlhr.js", @view.javascript_path("/super/xmlhr") + + assert_equal "https://assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1") + assert_equal "https://assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1") + assert_equal "https://assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash") + assert_equal "https://assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash") + assert_equal "https://assets.example.com/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash") + + assert_dom_equal %(), + @view.javascript_include_tag("foo") + assert_dom_equal %(), + @view.javascript_include_tag("foo.js") + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + end + + def test_stylesheet_path + assert_equal "https://assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank") + assert_equal "https://assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank.css") + assert_equal "https://assets.example.com/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir") + assert_equal "https://assets.example.com/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css") + + assert_equal "https://assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1") + assert_equal "https://assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1") + assert_equal "https://assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash") + assert_equal "https://assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash") + assert_equal "https://assets.example.com/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash") + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo") + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css") + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + end + + def test_asset_url + assert_equal "var url = '//assets.example.com/assets/foo.js';\n", @assets["url.js"].to_s + assert_equal "p { background: url(//assets.example.com/assets/logo.png); }\n", @assets["url.css"].to_s + end +end + + +class NoDigestHelperTest < NoHostHelperTest + def setup + super + @view.digest_assets = false + @assets.context_class.digest_assets = false + end + + def test_javascript_include_tag + super + + assert_dom_equal %(), + @view.javascript_include_tag("foo") + assert_dom_equal %(), + @view.javascript_include_tag("foo.js") + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + + assert_servable_asset_url "/assets/foo.js" + end + + def test_stylesheet_link_tag + super + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo") + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css") + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + + assert_servable_asset_url "/assets/foo.css" + end + + def test_javascript_path + super + + assert_equal "/assets/foo.js", @view.javascript_path("foo") + assert_servable_asset_url "/assets/foo.js" + end + + def test_stylesheet_path + super + + assert_equal "/assets/foo.css", @view.stylesheet_path("foo") + assert_servable_asset_url "/assets/foo.css" + end + + def test_asset_url + assert_equal "var url = '/assets/foo.js';\n", @assets["url.js"].to_s + assert_equal "p { background: url(/assets/logo.png); }\n", @assets["url.css"].to_s + end +end + +class DigestHelperTest < NoHostHelperTest + def setup + super + @view.digest_assets = true + @assets.context_class.digest_assets = true + end + + def test_javascript_include_tag + super + + assert_dom_equal %(), + @view.javascript_include_tag("foo") + assert_dom_equal %(), + @view.javascript_include_tag("foo.js") + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + + assert_dom_equal %(\n), + @view.javascript_include_tag(:foo, :bar) + + assert_servable_asset_url "/assets/foo-#{@foo_js_digest}.js" + end + + def test_stylesheet_link_tag + super + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo") + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css") + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:foo, :bar) + + assert_servable_asset_url "/assets/foo-#{@foo_css_digest}.css" + end + + def test_javascript_include_tag_integrity + super + + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: false) + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: nil) + + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag("foo.js", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag(:foo, integrity: true) + + assert_dom_equal %(\n), + @view.javascript_include_tag(:foo, :bar, integrity: true) + end + + def test_stylesheet_link_tag_integrity + super + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: false) + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: nil) + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo, integrity: true) + + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:foo, :bar, integrity: true) + end + + def test_javascript_path + super + + assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo") + assert_servable_asset_url "/assets/foo-#{@foo_js_digest}.js" + end + + def test_stylesheet_path + super + + assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo") + assert_servable_asset_url "/assets/foo-#{@foo_css_digest}.css" + end + + def test_asset_digest_path + assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js") + assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css") + end + + def test_asset_url + assert_equal "var url = '/assets/foo-#{@foo_js_digest}.js';\n", @assets["url.js"].to_s + assert_equal "p { background: url(/assets/logo-#{@logo_digest}.png); }\n", @assets["url.css"].to_s + end +end + +class DebugHelperTest < NoHostHelperTest + def setup + super + @view.debug_assets = true + end + + def test_javascript_include_tag + super + + if using_sprockets4? + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + assert_dom_equal %(), + @view.javascript_include_tag(:bar) + assert_dom_equal %(\n), + @view.javascript_include_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.debug.js" + assert_servable_asset_url "/assets/bar.debug.js" + assert_servable_asset_url "/assets/dependency.debug.js" + assert_servable_asset_url "/assets/file1.debug.js" + assert_servable_asset_url "/assets/file2.debug.js" + else + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + assert_dom_equal %(\n), + @view.javascript_include_tag(:bar) + assert_dom_equal %(\n\n), + @view.javascript_include_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.self.js?body=1" + assert_servable_asset_url "/assets/bar.self.js?body=1" + assert_servable_asset_url "/assets/dependency.self.js?body=1" + assert_servable_asset_url "/assets/file1.self.js?body=1" + assert_servable_asset_url "/assets/file2.self.js?body=1" + end + end + + def test_stylesheet_link_tag + super + + if using_sprockets4? + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + assert_dom_equal %(), + @view.stylesheet_link_tag(:bar) + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.self.css" + assert_servable_asset_url "/assets/bar.self.css" + assert_servable_asset_url "/assets/dependency.self.css" + assert_servable_asset_url "/assets/file1.self.css" + assert_servable_asset_url "/assets/file2.self.css" + else + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:bar) + assert_dom_equal %(\n\n), + @view.stylesheet_link_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.self.css?body=1" + assert_servable_asset_url "/assets/bar.self.css?body=1" + assert_servable_asset_url "/assets/dependency.self.css?body=1" + assert_servable_asset_url "/assets/file1.self.css?body=1" + assert_servable_asset_url "/assets/file2.self.css?body=1" + end + end + + def test_javascript_path + super + + assert_equal "/assets/foo.js", @view.javascript_path("foo") + assert_servable_asset_url "/assets/foo.js" + end + + def test_stylesheet_path + super + + assert_equal "/assets/foo.css", @view.stylesheet_path("foo") + assert_servable_asset_url "/assets/foo.css" + end +end + +class DebugDigestHelperTest < NoHostHelperTest + def setup + super + @view.debug_assets = true + @view.digest_assets = true + @assets.context_class.digest_assets = true + end + + def test_javascript_include_tag + super + + if using_sprockets4? + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + assert_dom_equal %(), + @view.javascript_include_tag(:bar) + assert_dom_equal %(\n), + @view.javascript_include_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.debug-#{@foo_debug_js_digest}.js" + assert_servable_asset_url "/assets/bar.debug-#{@bar_debug_js_digest}.js" + assert_servable_asset_url "/assets/dependency.debug-#{@dependency_debug_js_digest}.js" + assert_servable_asset_url "/assets/file1.debug-#{@file1_debug_js_digest}.js" + assert_servable_asset_url "/assets/file2.debug-#{@file2_debug_js_digest}.js" + else + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + assert_dom_equal %(\n), + @view.javascript_include_tag(:bar) + assert_dom_equal %(\n\n), + @view.javascript_include_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.self-#{@foo_self_js_digest}.js?body=1" + assert_servable_asset_url "/assets/bar.self-#{@bar_self_js_digest}.js?body=1" + assert_servable_asset_url "/assets/dependency.self-#{@dependency_self_js_digest}.js?body=1" + assert_servable_asset_url "/assets/file1.self-#{@file1_self_js_digest}.js?body=1" + assert_servable_asset_url "/assets/file2.self-#{@file2_self_js_digest}.js?body=1" + end + end + + def test_stylesheet_link_tag + super + + if using_sprockets4? + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + assert_dom_equal %(), + @view.stylesheet_link_tag(:bar) + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.self-#{@foo_self_css_digest}.css" + assert_servable_asset_url "/assets/bar.self-#{@bar_self_css_digest}.css" + assert_servable_asset_url "/assets/dependency.self-#{@dependency_self_css_digest}.css" + assert_servable_asset_url "/assets/file1.self-#{@file1_self_css_digest}.css" + assert_servable_asset_url "/assets/file2.self-#{@file2_self_css_digest}.css" + else + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + assert_dom_equal %(\n), + @view.stylesheet_link_tag(:bar) + assert_dom_equal %(\n\n), + @view.stylesheet_link_tag(:file1, :file2) + + assert_servable_asset_url "/assets/foo.self-#{@foo_self_css_digest}.css?body=1" + assert_servable_asset_url "/assets/bar.self-#{@bar_self_css_digest}.css?body=1" + assert_servable_asset_url "/assets/dependency.self-#{@dependency_self_css_digest}.css?body=1" + assert_servable_asset_url "/assets/file1.self-#{@file1_self_css_digest}.css?body=1" + assert_servable_asset_url "/assets/file2.self-#{@file2_self_css_digest}.css?body=1" + end + end + + def test_javascript_path + super + + assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo") + assert_servable_asset_url "/assets/foo-#{@foo_js_digest}.js" + end + + def test_stylesheet_path + super + + assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo") + assert_servable_asset_url "/assets/foo-#{@foo_css_digest}.css" + end + + def test_asset_digest_path + assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js") + assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css") + end + + def test_asset_url + assert_equal "var url = '/assets/foo-#{@foo_js_digest}.js';\n", @assets["url.js"].to_s + assert_equal "p { background: url(/assets/logo-#{@logo_digest}.png); }\n", @assets["url.css"].to_s + end +end + +class ManifestHelperTest < NoHostHelperTest + def setup + super + + @manifest = Sprockets::Manifest.new(@assets, FIXTURES_PATH) + @manifest.assets["foo.js"] = "foo-#{@foo_js_digest}.js" + @manifest.assets["foo.css"] = "foo-#{@foo_css_digest}.css" + + @manifest.files["foo-#{@foo_js_digest}.js"] = { "integrity" => @foo_js_integrity } + @manifest.files["foo-#{@foo_css_digest}.css"] = { "integrity" => @foo_css_integrity } + + @view.digest_assets = true + @view.assets_environment = nil + @view.assets_manifest = @manifest + @view.resolve_assets_with = [ :manifest ] + end + + def test_javascript_include_tag + super + + assert_dom_equal %(), + @view.javascript_include_tag("foo") + assert_dom_equal %(), + @view.javascript_include_tag("foo.js") + assert_dom_equal %(), + @view.javascript_include_tag(:foo) + end + + def test_stylesheet_link_tag + super + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo") + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css") + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo) + end + + def test_javascript_include_tag_integrity + super + + assert_dom_equal %(), + @view.javascript_include_tag("foo", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag("foo.js", integrity: true) + assert_dom_equal %(), + @view.javascript_include_tag(:foo, integrity: true) + end + + def test_stylesheet_link_tag_integrity + super + + assert_dom_equal %(), + @view.stylesheet_link_tag("foo", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag("foo.css", integrity: true) + assert_dom_equal %(), + @view.stylesheet_link_tag(:foo, integrity: true) + end + + def test_javascript_path + super + + assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo") + end + + def test_stylesheet_path + super + + assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo") + end + + def test_asset_digest_path + assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js") + assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css") + end + + def test_assets_environment_unavailable + refute @view.assets_environment + end +end + +class DebugManifestHelperTest < ManifestHelperTest + def setup + super + + @view.debug_assets = true + end + + def test_javascript_include_tag_integrity + end + + def test_stylesheet_link_tag_integrity + end +end + +class AssetResolverOrderingTest < HelperTest + def setup + super + + @view.digest_assets = true + + @view.assets_manifest = Sprockets::Manifest.new(@assets, FIXTURES_PATH).tap do |stale| + stale.assets["foo.js"] = "foo-stale.js" + stale.files["foo-stale.js"] = { "integrity" => "stale-manifest" } + + stale.assets["foo.css"] = "foo-stale.css" + stale.files["foo-stale.css"] = { "integrity" => "stale-manifest" } + end + end + + def test_digest_prefers_asset_environment_over_manifest + @view.resolve_assets_with = [ :environment, :manifest ] + + assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js") + assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css") + + assert_equal @foo_js_integrity, @view.asset_integrity("foo.js") + assert_equal @foo_css_integrity, @view.asset_integrity("foo.css") + end + + def test_try_resolvers_until_first_result + @view.resolve_assets_with = [ :manifest, :environment ] + + assert_equal 'foo-stale.js', @view.asset_digest_path('foo.js') + assert_equal "bar-#{@bar_js_digest}.js", @view.asset_digest_path('bar.js') + assert_nil @view.asset_digest_path('nonexistent') + + assert_equal 'stale-manifest', @view.asset_integrity('foo.js') + assert_equal @bar_js_integrity, @view.asset_integrity('bar.js') + assert_nil @view.asset_integrity('nonexistent') + end + + def test_obeys_asset_resolver_order + @view.resolve_assets_with = [] + assert_nil @view.asset_digest_path('foo.js') + assert_nil @view.asset_integrity('foo.js') + end +end + +class AssetUrlHelperLinksTarget < HelperTest + def test_precompile_allows_links + @view.assets_precompile = ["url.css"] + precompiled_assets = @manifest.find(@view.assets_precompile).map(&:logical_path) + @view.precompiled_asset_checker = -> logical_path { precompiled_assets.include? logical_path } + assert @view.asset_path("url.css") + assert @view.asset_path("logo.png") + + assert_raises(Sprockets::Rails::Helper::AssetNotPrecompiled) do + @view.asset_path("foo.css") + end + end + + def test_links_image_target + assert_match "logo.png", @assets['url.css'].links.to_a[0] + end + + def test_doesnt_track_public_assets + refute_match "does_not_exist.png", @assets['error/missing.css'].links.to_a[0] + end + + def test_asset_environment_reference_is_cached + env = @view.assets_environment + assert_kind_of Sprockets::CachedEnvironment, env + assert @view.assets_environment.equal?(env), "view didn't return the same cached instance" + end +end + +class PrecompiledAssetHelperTest < HelperTest + def setup + super + @bundle_js_name = '/assets/bundle.js' + end + + def test_javascript_precompile + assert_raises(Sprockets::Rails::Helper::AssetNotPrecompiled) do + @view.javascript_include_tag("not_precompiled") + end + end + + def test_stylesheet_precompile + assert_raises(Sprockets::Rails::Helper::AssetNotPrecompiled) do + @view.stylesheet_link_tag("not_precompiled") + end + end + + def test_index_files + assert_dom_equal %(), + @view.javascript_include_tag("bundle") + end +end + +class DeprecationTest < HelperTest + def test_deprecations_for_asset_path + @view.send(:define_singleton_method, :public_compute_asset_path, -> {}) + assert_deprecated do + @view.asset_path("does_not_exist.noextension") + end + ensure + @view.instance_eval('undef :public_compute_asset_path') + end + + def test_deprecations_for_asset_url + @view.send(:define_singleton_method, :public_compute_asset_path, -> {}) + + assert_deprecated do + @view.asset_url("does_not_exist.noextension") + end + ensure + @view.instance_eval('undef :public_compute_asset_path') + end + + def test_deprecations_for_image_tag + @view.send(:define_singleton_method, :public_compute_asset_path, -> {}) + + assert_deprecated do + @view.image_tag("does_not_exist.noextension") + end + ensure + @view.instance_eval('undef :public_compute_asset_path') + end +end + +class RaiseUnlessPrecompiledAssetDisabledTest < HelperTest + def test_check_precompiled_asset_enabled + @view.check_precompiled_asset = true + assert_raises(Sprockets::Rails::Helper::AssetNotPrecompiled) do + @view.asset_path("not_precompiled.css") + end + end + + def test_check_precompiled_asset_disabled + @view.check_precompiled_asset = false + assert @view.asset_path("not_precompiled.css") + end +end + +class PrecompiledDebugAssetHelperTest < PrecompiledAssetHelperTest + + # Re-run all PrecompiledAssetHelperTest with a different setup + def setup + super + @view.debug_assets = true + if using_sprockets4? + @bundle_js_name = '/assets/bundle.debug.js' + else + @bundle_js_name = '/assets/bundle/index.self.js?body=1' + end + end +end diff -Nru ruby-sprockets-rails-2.3.2/test/test_quiet_assets.rb ruby-sprockets-rails-3.2.1/test/test_quiet_assets.rb --- ruby-sprockets-rails-2.3.2/test/test_quiet_assets.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/test_quiet_assets.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,51 @@ +require 'active_support' +require 'active_support/testing/isolation' +require 'active_support/log_subscriber/test_helper' +require 'minitest/autorun' + +require 'sprockets/railtie' +require 'rails' + +Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) + +class TestQuietAssets < Minitest::Test + include ActiveSupport::Testing::Isolation + + ROOT_PATH = Pathname.new(File.expand_path("../../tmp/app", __FILE__)) + ASSET_PATH = ROOT_PATH.join("app","assets", "config") + + def setup + FileUtils.mkdir_p(ROOT_PATH) + Dir.chdir(ROOT_PATH) + + @app = Class.new(Rails::Application) + @app.config.eager_load = false + @app.config.logger = ActiveSupport::Logger.new("/dev/null") + + FileUtils.mkdir_p(ASSET_PATH) + File.open(ASSET_PATH.join("manifest.js"), "w") { |f| f << "" } + + @app.initialize! + + Rails.logger.level = Logger::DEBUG + end + + def test_silences_with_default_prefix + assert_equal Logger::ERROR, middleware.call("PATH_INFO" => "/assets/stylesheets/application.css") + end + + def test_silencess_with_custom_prefix + Rails.application.config.assets.prefix = "path/to" + assert_equal Logger::ERROR, middleware.call("PATH_INFO" => "/path/to/thing") + end + + def test_does_not_silence_without_match + assert_equal Logger::DEBUG, middleware.call("PATH_INFO" => "/path/to/thing") + end + + private + + def middleware + @middleware ||= Sprockets::Rails::QuietAssets.new(->(env) { Rails.logger.level }) + end +end diff -Nru ruby-sprockets-rails-2.3.2/test/test_railtie.rb ruby-sprockets-rails-3.2.1/test/test_railtie.rb --- ruby-sprockets-rails-2.3.2/test/test_railtie.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/test_railtie.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,413 @@ +require 'active_support' +require 'active_support/testing/isolation' +require 'minitest/autorun' + +Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) + +def silence_stderr + orig_stderr = $stderr.clone + $stderr.reopen File.new('/dev/null', 'w') + yield +ensure + $stderr.reopen orig_stderr +end + +class TestBoot < Minitest::Test + include ActiveSupport::Testing::Isolation + + ROOT = File.expand_path("../../tmp/app", __FILE__) + FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) + + attr_reader :app + + def setup + require 'rails' + # Can't seem to get initialize to run w/o this + require 'action_controller/railtie' + require 'active_support/dependencies' + require 'tzinfo' + + ENV['RAILS_ENV'] = 'test' + + FileUtils.mkdir_p ROOT + Dir.chdir ROOT + + @app = Class.new(Rails::Application) + @app.config.eager_load = false + @app.config.time_zone = 'UTC' + @app.config.middleware ||= Rails::Configuration::MiddlewareStackProxy.new + @app.config.active_support.deprecation = :notify + ActionView::Base # load ActionView + + Dir.chdir(app.root) do + dir = "app/assets/config" + FileUtils.mkdir_p(dir) + File.open("#{ dir }/manifest.js", "w") do |f| + f << "" + end + end + end + + def test_initialize + app.initialize! + end +end + +class TestRailtie < TestBoot + def setup + require 'sprockets/railtie' + super + end + + def test_defaults_to_compile_assets_with_env_and_manifest_available + assert_equal true, app.config.assets.compile + + app.initialize! + + # Env is available + refute_nil env = app.assets + assert_kind_of Sprockets::Environment, env + + # Manifest is always available + assert manifest = app.assets_manifest + assert_equal app.assets, manifest.environment + assert_equal File.join(ROOT, "public/assets"), manifest.dir + + # Resolves against manifest then environment by default + assert_equal [ :manifest, :environment ], app.config.assets.resolve_with + + # Sprockets config + assert_equal ROOT, env.root + assert_equal "", env.version + assert env.cache + assert_includes(env.paths, "#{ROOT}/app/assets/config") + + assert_nil env.js_compressor + assert_nil env.css_compressor + end + + def test_disabling_compile_has_manifest_but_no_env + app.configure do + config.assets.compile = false + end + + assert_equal false, app.config.assets.compile + + app.initialize! + + # No env when compile is disabled + assert_nil app.assets + + # Manifest is always available + refute_nil manifest = app.assets_manifest + assert_nil manifest.environment + assert_equal File.join(ROOT, "public/assets"), manifest.dir + + # Resolves against manifest only + assert_equal [ :manifest ], app.config.assets.resolve_with + end + + def test_enabling_debug_resolves_with_env_only + app.configure do + config.assets.debug = true + end + + assert_equal true, app.config.assets.debug + assert_equal true, app.config.assets.compile + + app.initialize! + + # Resolves against environment only + assert_equal [ :environment ], app.config.assets.resolve_with + end + + def test_copies_paths + app.configure do + config.assets.paths << "javascripts" + config.assets.paths << "stylesheets" + end + app.initialize! + + assert env = app.assets + assert_includes(env.paths, "#{ROOT}/javascripts") + assert_includes(env.paths, "#{ROOT}/stylesheets") + assert_includes(env.paths, "#{ROOT}/app/assets/config") + end + + def test_compressors + app.configure do + config.assets.js_compressor = :uglifier + config.assets.css_compressor = :sass + end + app.initialize! + + assert env = app.assets + assert_equal Sprockets::UglifierCompressor.name, env.js_compressor.name + + silence_warnings do + require 'sprockets/sass_compressor' + end + assert_equal Sprockets::SassCompressor.name, env.css_compressor.name + end + + def test_custom_compressors + compressor = Class.new + app.configure do + config.assets.configure do |env| + env.register_compressor "application/javascript", :test_js, compressor + env.register_compressor "text/css", :test_css, compressor + end + config.assets.js_compressor = :test_js + config.assets.css_compressor = :test_css + end + app.initialize! + + assert env = app.assets + assert_equal compressor, env.js_compressor + assert_equal compressor, env.css_compressor + end + + def test_default_gzip_config + app.initialize! + + assert env = app.assets + assert_equal true, env.gzip? + end + + def test_gzip_config + app.configure do + config.assets.gzip = false + end + app.initialize! + + assert env = app.assets + assert_equal false, env.gzip? + end + + def test_default_check_precompiled_assets + assert app.config.assets.check_precompiled_asset + app.initialize! + @view = ActionView::Base.new + assert @view.check_precompiled_asset + end + + def test_configure_check_precompiled_assets + app.configure do + config.assets.check_precompiled_asset = false + end + app.initialize! + @view = ActionView::Base.new + refute @view.check_precompiled_asset + end + + def test_version + app.configure do + config.assets.version = 'v2' + end + app.initialize! + + assert env = app.assets + assert_equal "v2", env.version + end + + def test_configure + app.configure do + config.assets.configure do |env| + env.append_path "javascripts" + end + config.assets.configure do |env| + env.append_path "stylesheets" + end + end + app.initialize! + + assert env = app.assets + + assert_includes(env.paths, "#{ROOT}/javascripts") + assert_includes(env.paths, "#{ROOT}/stylesheets") + assert_includes(env.paths, "#{ROOT}/app/assets/config") + end + + def test_environment_is_frozen_if_caching_classes + app.configure do + config.cache_classes = true + end + app.initialize! + + assert env = app.assets + assert_kind_of Sprockets::CachedEnvironment, env + end + + def test_action_view_helper + app.configure do + config.assets.paths << FIXTURES_PATH + config.assets.precompile += ["foo.js"] + end + app.initialize! + + assert app.assets.paths.include?(FIXTURES_PATH) + + assert_equal false, ActionView::Base.debug_assets + assert_equal true, ActionView::Base.digest_assets + assert_equal "/assets", ActionView::Base.assets_prefix + assert_equal app.assets, ActionView::Base.assets_environment + assert_equal app.assets_manifest, ActionView::Base.assets_manifest + assert_kind_of Sprockets::Environment, ActionView::Base.assets_environment + + @view = ActionView::Base.new + assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr") + assert_equal "/assets/foo-4ef5541f349f7ed5a0d6b71f2fa4c82745ca106ae02f212aea5129726ac6f6ab.js", @view.javascript_path("foo") + + env = @view.assets_environment + assert_kind_of Sprockets::CachedEnvironment, env + assert @view.assets_environment.equal?(env), "view didn't return the same cached instance" + end + + def test_action_view_helper_when_no_compile + app.configure do + config.assets.compile = false + end + + assert_equal false, app.config.assets.compile + + app.initialize! + + refute ActionView::Base.assets_environment + assert_equal app.assets_manifest, ActionView::Base.assets_manifest + + @view = ActionView::Base.new + refute @view.assets_environment + assert_equal app.assets_manifest, @view.assets_manifest + end + + def test_sprockets_context_helper + app.initialize! + + assert env = app.assets + assert_equal "/assets", env.context_class.assets_prefix + assert_equal true, env.context_class.digest_assets + assert_nil env.context_class.config.asset_host + end + + def test_manifest_path + app.configure do + config.assets.manifest = Rails.root.join('config','foo','bar.json') + end + app.initialize! + + assert manifest = app.assets_manifest + assert_match %r{config/foo/bar\.json$}, manifest.path + assert_match %r{public/assets$}, manifest.dir + end + + def test_manifest_path_respects_rails_public_path + app.configure do + config.paths['public'] = 'test_public' + end + app.initialize! + + assert manifest = app.assets_manifest + assert_match %r{test_public/assets/\.sprockets-manifest-.*\.json$}, manifest.path + assert_match %r{test_public/assets$}, manifest.dir + end + + def test_load_tasks + app.initialize! + app.load_tasks + + assert Rake.application['assets:environment'] + assert Rake.application['assets:precompile'] + assert Rake.application['assets:clean'] + assert Rake.application['assets:clobber'] + end + + def test_task_precompile + app.configure do + config.assets.paths << FIXTURES_PATH + config.assets.precompile += ["foo.js"] + end + app.initialize! + app.load_tasks + + path = "#{app.assets_manifest.dir}/foo-4ef5541f349f7ed5a0d6b71f2fa4c82745ca106ae02f212aea5129726ac6f6ab.js" + + silence_stderr do + Rake.application['assets:clobber'].execute + end + refute File.exist?(path) + + silence_stderr do + Rake.application['assets:precompile'].execute + end + assert File.exist?(path) + + silence_stderr do + Rake.application['assets:clobber'].execute + end + refute File.exist?(path) + end + + def test_task_precompile_compile_false + app.configure do + config.assets.compile = false + config.assets.paths << FIXTURES_PATH + config.assets.precompile += ["foo.js"] + end + app.initialize! + app.load_tasks + + path = "#{app.assets_manifest.dir}/foo-4ef5541f349f7ed5a0d6b71f2fa4c82745ca106ae02f212aea5129726ac6f6ab.js" + + silence_stderr do + Rake.application['assets:clobber'].execute + end + refute File.exist?(path) + + silence_stderr do + Rake.application['assets:precompile'].execute + end + assert File.exist?(path) + + silence_stderr do + Rake.application['assets:clobber'].execute + end + refute File.exist?(path) + end + + def test_direct_build_environment_call + app.configure do + config.assets.paths << "javascripts" + config.assets.paths << "stylesheets" + end + app.initialize! + + assert env = Sprockets::Railtie.build_environment(app) + assert_kind_of Sprockets::Environment, env + + assert_equal ROOT, env.root + assert_includes(env.paths, "#{ROOT}/javascripts") + assert_includes(env.paths, "#{ROOT}/stylesheets") + assert_includes(env.paths, "#{ROOT}/app/assets/config") + end + + def test_quiet_assets_defaults_to_off + app.initialize! + app.load_tasks + + assert_equal false, app.config.assets.quiet + refute app.config.middleware.include?(Sprockets::Rails::QuietAssets) + end + + def test_quiet_assets_inserts_middleware + app.configure do + config.assets.quiet = true + end + app.initialize! + app.load_tasks + middleware = app.config.middleware + + assert_equal true, app.config.assets.quiet + assert middleware.include?(Sprockets::Rails::QuietAssets) + assert middleware.each_cons(2).include?([Sprockets::Rails::QuietAssets, Rails::Rack::Logger]) + end +end diff -Nru ruby-sprockets-rails-2.3.2/test/test_task.rb ruby-sprockets-rails-3.2.1/test/test_task.rb --- ruby-sprockets-rails-2.3.2/test/test_task.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/test/test_task.rb 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,142 @@ +require 'minitest/autorun' +require 'tmpdir' + +require 'sprockets' +require 'sprockets/rails/task' + +Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) + +class TestTask < Minitest::Test + FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) + + def setup + @rake = Rake::Application.new + Rake.application = @rake + + @assets = Sprockets::Environment.new + @assets.append_path FIXTURES_PATH + + @dir = File.join(Dir::tmpdir, 'rails', 'task') + + @manifest_file = File.join(Dir::tmpdir, 'rails', 'manifest', 'custom-manifest.json') + FileUtils.mkdir_p File.dirname(@manifest_file) + @manifest = Sprockets::Manifest.new(@assets, @dir, @manifest_file) + + Sprockets::Rails::Task.new do |t| + t.environment = @assets + t.manifest = @manifest + t.assets = ['foo.js', 'foo-modified.js'] + t.log_level = :fatal + end + + @environment_ran = false + # Stub Rails environment task + @rake.define_task Rake::Task, :environment do + @environment_ran = true + end + end + + def teardown + Rake.application = nil + + FileUtils.rm_rf(@dir) + assert Dir["#{@dir}/*"].empty? + + manifest_dir = File.dirname(@manifest_file) + FileUtils.rm_rf(manifest_dir) + assert Dir["#{manifest_dir}/*"].empty? + end + + def test_precompile + assert !@environment_ran + + digest_path = @assets['foo.js'].digest_path + assert !File.exist?("#{@dir}/#{digest_path}") + + @rake['assets:precompile'].invoke + + assert @environment_ran + assert File.exist?(@manifest_file) + assert File.exist?("#{@dir}/#{digest_path}") + end + + def test_precompile_without_manifest + Sprockets::Rails::Task.new do |t| + t.environment = @assets + t.manifest = Sprockets::Manifest.new(@assets, @dir, nil) + t.assets = ['foo.js', 'foo-modified.js'] + t.log_level = :fatal + end + + assert !@environment_ran + + digest_path = @assets['foo.js'].digest_path + assert !File.exist?("#{@dir}/#{digest_path}") + + @rake['assets:precompile'].invoke + + assert @environment_ran + assert Dir["#{@dir}/.sprockets-manifest-*.json"].first + assert File.exist?("#{@dir}/#{digest_path}") + end + + def test_clobber + assert !@environment_ran + digest_path = @assets['foo.js'].digest_path + + @rake['assets:precompile'].invoke + assert File.exist?("#{@dir}/#{digest_path}") + + assert @environment_ran + + @rake['assets:clobber'].invoke + assert !File.exist?("#{@dir}/#{digest_path}") + end + + def test_clean + assert !@environment_ran + digest_path = @assets['foo.js'].digest_path + + @rake['assets:precompile'].invoke + assert File.exist?("#{@dir}/#{digest_path}") + + assert @environment_ran + + @rake['assets:clean'].invoke + assert File.exist?("#{@dir}/#{digest_path}") + end + + def test_clean_with_keep_specified + assert !@environment_ran + path = Pathname.new(@assets['foo.js'].filename) + new_path = path.join("../foo-modified.js") + + FileUtils.cp(path, new_path) + + assert File.exist?(new_path) + digest_path = @assets['foo-modified.js'].digest_path + + @rake['assets:precompile'].invoke + assert File.exist?("#{@dir}/#{digest_path}") + assert @environment_ran + + # clean environment + setup + + # modify file + File.open(new_path, "a") {|f| f.write("var Bar;") } + @rake['assets:precompile'].invoke + old_digest_path = digest_path + digest_path = @assets['foo-modified.js'].digest_path + + refute_equal old_digest_path, digest_path + assert File.exist?("#{@dir}/#{old_digest_path}") + assert File.exist?("#{@dir}/#{digest_path}") + + @rake['assets:clean'].invoke(0) + assert File.exist?("#{@dir}/#{digest_path}") + # refute File.exist?("#{@dir}/#{old_digest_path}") + ensure + FileUtils.rm(new_path) if new_path + end +end diff -Nru ruby-sprockets-rails-2.3.2/.travis.yml ruby-sprockets-rails-3.2.1/.travis.yml --- ruby-sprockets-rails-2.3.2/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sprockets-rails-3.2.1/.travis.yml 2019-02-06 16:11:35.000000000 +0000 @@ -0,0 +1,66 @@ +language: ruby +cache: bundler +sudo: false + +rvm: + - 1.9.3 + - 2.0.0 + - 2.1 + - 2.2.7 + - 2.3.4 + - 2.4.1 + +gemfile: + - Gemfile + - gemfiles/Gemfile.rails-4.0.x + - gemfiles/Gemfile.rails-4.1.x + - gemfiles/Gemfile.rails-4.2.x + - gemfiles/Gemfile.rails-5.0.x + - gemfiles/Gemfile.rails-5.0.x.sprockets-4.x + - gemfiles/Gemfile.rails-5.1.x + - gemfiles/Gemfile.rails-5.1.x.sprockets-4.x + +matrix: + exclude: + - gemfile: gemfiles/Gemfile.rails-4.0.x + rvm: 2.4.1 + - gemfile: gemfiles/Gemfile.rails-4.1.x + rvm: 2.4.1 + - gemfile: Gemfile + rvm: 1.9.3 + - gemfile: Gemfile + rvm: 2.0.0 + - gemfile: Gemfile + rvm: 2.1 + - gemfile: gemfiles/Gemfile.rails-5.0.x + rvm: 1.9.3 + - gemfile: gemfiles/Gemfile.rails-5.0.x + rvm: 2.0.0 + - gemfile: gemfiles/Gemfile.rails-5.0.x + rvm: 2.1 + - gemfile: gemfiles/Gemfile.rails-5.0.x.sprockets-4.x + rvm: 1.9.3 + - gemfile: gemfiles/Gemfile.rails-5.0.x.sprockets-4.x + rvm: 2.0.0 + - gemfile: gemfiles/Gemfile.rails-5.0.x.sprockets-4.x + rvm: 2.1 + - gemfile: gemfiles/Gemfile.rails-5.1.x + rvm: 1.9.3 + - gemfile: gemfiles/Gemfile.rails-5.1.x + rvm: 2.0.0 + - gemfile: gemfiles/Gemfile.rails-5.1.x + rvm: 2.1 + - gemfile: gemfiles/Gemfile.rails-5.1.x.sprockets-4.x + rvm: 1.9.3 + - gemfile: gemfiles/Gemfile.rails-5.1.x.sprockets-4.x + rvm: 2.0.0 + - gemfile: gemfiles/Gemfile.rails-5.1.x.sprockets-4.x + rvm: 2.1 + +notifications: + email: false + campfire: + on_success: change + on_failure: always + rooms: + - secure: "RkdRnCTQkmW7izb9+p9XB8pDrj7XiwHaOXQtEw29U7gXQDPqz77QzoL4cKlvMwalW77079Abp4gQpYeLFIZVm2VcVwFW3/6s0kgf3LGssbrF5fPSQnXk6GQGJBRGUyLt0TCi63Y/5DskREtEINbRfKLiDGm8ar/ExFoJzcZIsig="