Skip to content

Commit

Permalink
Use a dedicated ActiveSupport::Deprecation
Browse files Browse the repository at this point in the history
Rails 7.1 will deprecate using the singleton ActiveSupport::Deprecation
instance. This defines one for the gem and uses it.

It's also added to the application's set of deprecators, allowing it to
be configured along all the other deprecators.
  • Loading branch information
etiennebarrie committed May 9, 2023
1 parent 73e7351 commit d8495d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
9 changes: 9 additions & 0 deletions lib/sprockets/rails.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
require 'sprockets/rails/version'
require 'active_support'
if defined? Rails::Railtie
require 'sprockets/railtie'
end

module Sprockets
module Rails
def self.deprecator
@deprecator ||= ActiveSupport::Deprecation.new("4.0", "Sprockets::Rails")
end
end
end
2 changes: 1 addition & 1 deletion lib/sprockets/rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def compute_asset_path(path, options = {})
message << "To bypass the asset pipeline and preserve this behavior,\n"
message << "use the `skip_pipeline: true` option.\n"

ActiveSupport::Deprecation.warn(message, caller_locations)
Sprockets::Rails.deprecator.warn(message, caller_locations)
end
super
end
Expand Down
4 changes: 4 additions & 0 deletions lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def configure(&block)
Sprockets.register_postprocessor "application/javascript", ::Sprockets::Rails::SourcemappingUrlProcessor
end

initializer "sprockets-rails.deprecator" do |app|
app.deprecators[:sprockets_rails] = Sprockets::Rails.deprecator if app.respond_to?(:deprecators)
end

config.assets.version = ""
config.assets.debug = false
config.assets.compile = true
Expand Down
27 changes: 14 additions & 13 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'action_view'
require 'sprockets'
require 'sprockets/rails'
require 'sprockets/rails/context'
require 'sprockets/rails/helper'
require 'rails/version'
Expand Down Expand Up @@ -113,7 +114,7 @@ def assert_servable_asset_url(url)

class NoHostHelperTest < HelperTest
def test_javascript_include_tag
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.silence do
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
@view.javascript_include_tag("static")
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_javascript_include_tag
end

def test_stylesheet_link_tag
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.silence do
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" />),
@view.stylesheet_link_tag("static")
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" />),
Expand Down Expand Up @@ -169,7 +170,7 @@ def test_stylesheet_link_tag
end

def test_javascript_include_tag_integrity
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.silence do
assert_dom_equal %(<script src="/javascripts/static.js" integrity="sha-256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>),
@view.javascript_include_tag("static", integrity: "sha-256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs=")

Expand All @@ -183,7 +184,7 @@ def test_javascript_include_tag_integrity
end

def test_stylesheet_link_tag_integrity
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.silence do
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" integrity="sha-256-5YzTQPuOJz/EpeXfN/+v1sxsjAj/dw8q26abiHZM3A4=" />),
@view.stylesheet_link_tag("static", integrity: "sha-256-5YzTQPuOJz/EpeXfN/+v1sxsjAj/dw8q26abiHZM3A4=")

Expand All @@ -195,7 +196,7 @@ def test_stylesheet_link_tag_integrity
end

def test_javascript_path
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.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")
Expand All @@ -210,7 +211,7 @@ def test_javascript_path
end

def test_stylesheet_path
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.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")
Expand All @@ -233,7 +234,7 @@ def setup
end

def test_javascript_include_tag_integrity
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.silence do
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
@view.javascript_include_tag("static", integrity: true)
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
Expand All @@ -250,7 +251,7 @@ def test_javascript_include_tag_integrity
end

def test_stylesheet_link_tag_integrity
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.silence do
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" />),
@view.stylesheet_link_tag("static", integrity: true)
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" />),
Expand Down Expand Up @@ -324,7 +325,7 @@ def setup
end

def test_javascript_path
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.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")
Expand All @@ -346,7 +347,7 @@ def test_javascript_path
end

def test_stylesheet_path
ActiveSupport::Deprecation.silence do
Sprockets::Rails.deprecator.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")
Expand Down Expand Up @@ -914,7 +915,7 @@ def test_index_files
class DeprecationTest < HelperTest
def test_deprecations_for_asset_path
@view.send(:define_singleton_method, :public_compute_asset_path, -> {})
assert_deprecated do
assert_deprecated("use the `skip_pipeline: true` option", Sprockets::Rails.deprecator) do
@view.asset_path("does_not_exist.noextension")
end
ensure
Expand All @@ -924,7 +925,7 @@ def test_deprecations_for_asset_path
def test_deprecations_for_asset_url
@view.send(:define_singleton_method, :public_compute_asset_path, -> {})

assert_deprecated do
assert_deprecated("use the `skip_pipeline: true` option", Sprockets::Rails.deprecator) do
@view.asset_url("does_not_exist.noextension")
end
ensure
Expand All @@ -934,7 +935,7 @@ def test_deprecations_for_asset_url
def test_deprecations_for_image_tag
@view.send(:define_singleton_method, :public_compute_asset_path, -> {})

assert_deprecated do
assert_deprecated("use the `skip_pipeline: true` option", Sprockets::Rails.deprecator) do
@view.image_tag("does_not_exist.noextension")
end
ensure
Expand Down

0 comments on commit d8495d0

Please sign in to comment.