diff --git a/.travis.yml b/.travis.yml index 9cf57eda..f0d8628d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,10 @@ rvm: - 2.1.10 - 2.2.10 - 2.3.8 - - 2.4.5 - - 2.5.3 - - 2.6.0 + - 2.4.10 + - 2.5.8 + - 2.6.6 + - 2.7.1 gemfile: - Gemfile @@ -30,17 +31,23 @@ gemfile: matrix: exclude: - gemfile: gemfiles/Gemfile.rails-4.0.x - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-4.1.x - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-4.0.x - rvm: 2.5.3 + rvm: 2.5.8 - gemfile: gemfiles/Gemfile.rails-4.1.x - rvm: 2.5.3 + rvm: 2.5.8 - gemfile: gemfiles/Gemfile.rails-4.0.x - rvm: 2.6.0 + rvm: 2.6.6 - gemfile: gemfiles/Gemfile.rails-4.1.x - rvm: 2.6.0 + rvm: 2.6.6 + - gemfile: gemfiles/Gemfile.rails-4.0.x + rvm: 2.7.1 + - gemfile: gemfiles/Gemfile.rails-4.1.x + rvm: 2.7.1 + - gemfile: gemfiles/Gemfile.rails-4.2.x + rvm: 2.7.1 - gemfile: Gemfile rvm: 1.9.3 - gemfile: Gemfile @@ -52,7 +59,7 @@ matrix: - gemfile: Gemfile rvm: 2.3.8 - gemfile: Gemfile - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-5.0.x rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails-5.0.x @@ -70,7 +77,7 @@ matrix: - gemfile: gemfiles/Gemfile.rails-5.0.x.sprockets-4.x rvm: 2.3.8 - gemfile: gemfiles/Gemfile.rails-5.0.x.sprockets-4.x - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-5.1.x rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails-5.1.x @@ -88,13 +95,15 @@ matrix: - gemfile: gemfiles/Gemfile.rails-5.1.x.sprockets-4.x rvm: 2.3.8 - gemfile: gemfiles/Gemfile.rails-5.1.x.sprockets-4.x - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-5.2.x rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails-5.2.x rvm: 2.0.0 - gemfile: gemfiles/Gemfile.rails-5.2.x rvm: 2.1.10 + - gemfile: gemfiles/Gemfile.rails-5.2.x + rvm: 2.2.10 - gemfile: gemfiles/Gemfile.rails-5.2.x.sprockets-4.x rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails-5.2.x.sprockets-4.x @@ -106,7 +115,7 @@ matrix: - gemfile: gemfiles/Gemfile.rails-5.2.x.sprockets-4.x rvm: 2.3.8 - gemfile: gemfiles/Gemfile.rails-5.2.x.sprockets-4.x - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-6.0.x rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails-6.0.x @@ -118,7 +127,7 @@ matrix: - gemfile: gemfiles/Gemfile.rails-6.0.x rvm: 2.3.8 - gemfile: gemfiles/Gemfile.rails-6.0.x - rvm: 2.4.5 + rvm: 2.4.10 - gemfile: gemfiles/Gemfile.rails-6.0.x.sprockets-4.x rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails-6.0.x.sprockets-4.x @@ -130,7 +139,7 @@ matrix: - gemfile: gemfiles/Gemfile.rails-6.0.x.sprockets-4.x rvm: 2.3.8 - gemfile: gemfiles/Gemfile.rails-6.0.x.sprockets-4.x - rvm: 2.4.5 + rvm: 2.4.10 notifications: email: false diff --git a/lib/sprockets/rails/helper.rb b/lib/sprockets/rails/helper.rb index 102798e1..ee7c5f32 100644 --- a/lib/sprockets/rails/helper.rb +++ b/lib/sprockets/rails/helper.rb @@ -58,7 +58,7 @@ def assets_environment end def self.extended(obj) - obj.class_eval do + obj.singleton_class.class_eval do attr_accessor(*VIEW_ACCESSORS) remove_method :assets_environment @@ -352,8 +352,16 @@ def find_debug_asset(path) end private - def find_asset(path, options = {}) - @env[path, **options] + if RUBY_VERSION >= "2.7" + class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def find_asset(path, options = {}) + @env[path, **options] + end + RUBY + else + def find_asset(path, options = {}) + @env[path, options] + end end def precompiled?(path) diff --git a/test/test_helper.rb b/test/test_helper.rb index 2d8da500..1ed323db 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,7 @@ require 'sprockets' require 'sprockets/rails/context' require 'sprockets/rails/helper' +require 'rails/version' ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=) @@ -19,7 +20,7 @@ def setup tmp = File.expand_path("../../tmp", __FILE__) @manifest = Sprockets::Manifest.new(@assets, tmp) - @view = ActionView::Base.new + @view = ActionView::Base.new(ActionView::LookupContext.new([])) @view.extend ::Sprockets::Rails::Helper @view.assets_environment = @assets @view.assets_manifest = @manifest @@ -106,103 +107,115 @@ def assert_servable_asset_url(url) 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") + ActiveSupport::Deprecation.silence do + 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 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 => "") + ActiveSupport::Deprecation.silence do + 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 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) + ActiveSupport::Deprecation.silence do + 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 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) + ActiveSupport::Deprecation.silence do + 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 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") + ActiveSupport::Deprecation.silence do + 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 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") + ActiveSupport::Deprecation.silence do + 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 end @@ -214,30 +227,34 @@ def setup 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=") + ActiveSupport::Deprecation.silence do + 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=") + end 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=") + ActiveSupport::Deprecation.silence do + 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=") + end assert_dom_equal %(), @view.stylesheet_link_tag("foo", integrity: true) @@ -301,16 +318,18 @@ def setup 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") + ActiveSupport::Deprecation.silence do + 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") + end assert_dom_equal %(), @view.javascript_include_tag("foo") @@ -321,16 +340,18 @@ def test_javascript_path 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") + ActiveSupport::Deprecation.silence do + 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") + end assert_dom_equal %(), @view.stylesheet_link_tag("foo") diff --git a/test/test_railtie.rb b/test/test_railtie.rb index 109c8fed..a792b8b4 100644 --- a/test/test_railtie.rb +++ b/test/test_railtie.rb @@ -156,7 +156,12 @@ def test_compressors end def test_custom_compressors - compressor = Class.new + compressor = Class.new do + def self.call(input) + { data: input[:data] } + end + end + app.configure do config.assets.configure do |env| env.register_compressor "application/javascript", :test_js, compressor