Skip to content

Commit 065cbe8

Browse files
Merge pull request #517 from etiennebarrie/add-deprecator
Use a dedicated ActiveSupport::Deprecation
2 parents 73e7351 + d8495d0 commit 065cbe8

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

lib/sprockets/rails.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
require 'sprockets/rails/version'
2+
require 'active_support'
23
if defined? Rails::Railtie
34
require 'sprockets/railtie'
45
end
6+
7+
module Sprockets
8+
module Rails
9+
def self.deprecator
10+
@deprecator ||= ActiveSupport::Deprecation.new("4.0", "Sprockets::Rails")
11+
end
12+
end
13+
end

lib/sprockets/rails/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def compute_asset_path(path, options = {})
8989
message << "To bypass the asset pipeline and preserve this behavior,\n"
9090
message << "use the `skip_pipeline: true` option.\n"
9191

92-
ActiveSupport::Deprecation.warn(message, caller_locations)
92+
Sprockets::Rails.deprecator.warn(message, caller_locations)
9393
end
9494
super
9595
end

lib/sprockets/railtie.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ def configure(&block)
125125
Sprockets.register_postprocessor "application/javascript", ::Sprockets::Rails::SourcemappingUrlProcessor
126126
end
127127

128+
initializer "sprockets-rails.deprecator" do |app|
129+
app.deprecators[:sprockets_rails] = Sprockets::Rails.deprecator if app.respond_to?(:deprecators)
130+
end
131+
128132
config.assets.version = ""
129133
config.assets.debug = false
130134
config.assets.compile = true

test/test_helper.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'action_view'
44
require 'sprockets'
5+
require 'sprockets/rails'
56
require 'sprockets/rails/context'
67
require 'sprockets/rails/helper'
78
require 'rails/version'
@@ -113,7 +114,7 @@ def assert_servable_asset_url(url)
113114

114115
class NoHostHelperTest < HelperTest
115116
def test_javascript_include_tag
116-
ActiveSupport::Deprecation.silence do
117+
Sprockets::Rails.deprecator.silence do
117118
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
118119
@view.javascript_include_tag("static")
119120
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
@@ -141,7 +142,7 @@ def test_javascript_include_tag
141142
end
142143

143144
def test_stylesheet_link_tag
144-
ActiveSupport::Deprecation.silence do
145+
Sprockets::Rails.deprecator.silence do
145146
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" />),
146147
@view.stylesheet_link_tag("static")
147148
assert_dom_equal %(<link href="/stylesheets/static.css" #{append_media_attribute} rel="stylesheet" />),
@@ -169,7 +170,7 @@ def test_stylesheet_link_tag
169170
end
170171

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

@@ -183,7 +184,7 @@ def test_javascript_include_tag_integrity
183184
end
184185

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

@@ -195,7 +196,7 @@ def test_stylesheet_link_tag_integrity
195196
end
196197

197198
def test_javascript_path
198-
ActiveSupport::Deprecation.silence do
199+
Sprockets::Rails.deprecator.silence do
199200
assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
200201
assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js")
201202
assert_equal "/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr")
@@ -210,7 +211,7 @@ def test_javascript_path
210211
end
211212

212213
def test_stylesheet_path
213-
ActiveSupport::Deprecation.silence do
214+
Sprockets::Rails.deprecator.silence do
214215
assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank")
215216
assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank.css")
216217
assert_equal "/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir")
@@ -233,7 +234,7 @@ def setup
233234
end
234235

235236
def test_javascript_include_tag_integrity
236-
ActiveSupport::Deprecation.silence do
237+
Sprockets::Rails.deprecator.silence do
237238
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
238239
@view.javascript_include_tag("static", integrity: true)
239240
assert_dom_equal %(<script src="/javascripts/static.js"></script>),
@@ -250,7 +251,7 @@ def test_javascript_include_tag_integrity
250251
end
251252

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

326327
def test_javascript_path
327-
ActiveSupport::Deprecation.silence do
328+
Sprockets::Rails.deprecator.silence do
328329
assert_equal "https://assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
329330
assert_equal "https://assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js")
330331
assert_equal "https://assets.example.com/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr")
@@ -346,7 +347,7 @@ def test_javascript_path
346347
end
347348

348349
def test_stylesheet_path
349-
ActiveSupport::Deprecation.silence do
350+
Sprockets::Rails.deprecator.silence do
350351
assert_equal "https://assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank")
351352
assert_equal "https://assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank.css")
352353
assert_equal "https://assets.example.com/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir")
@@ -914,7 +915,7 @@ def test_index_files
914915
class DeprecationTest < HelperTest
915916
def test_deprecations_for_asset_path
916917
@view.send(:define_singleton_method, :public_compute_asset_path, -> {})
917-
assert_deprecated do
918+
assert_deprecated("use the `skip_pipeline: true` option", Sprockets::Rails.deprecator) do
918919
@view.asset_path("does_not_exist.noextension")
919920
end
920921
ensure
@@ -924,7 +925,7 @@ def test_deprecations_for_asset_path
924925
def test_deprecations_for_asset_url
925926
@view.send(:define_singleton_method, :public_compute_asset_path, -> {})
926927

927-
assert_deprecated do
928+
assert_deprecated("use the `skip_pipeline: true` option", Sprockets::Rails.deprecator) do
928929
@view.asset_url("does_not_exist.noextension")
929930
end
930931
ensure
@@ -934,7 +935,7 @@ def test_deprecations_for_asset_url
934935
def test_deprecations_for_image_tag
935936
@view.send(:define_singleton_method, :public_compute_asset_path, -> {})
936937

937-
assert_deprecated do
938+
assert_deprecated("use the `skip_pipeline: true` option", Sprockets::Rails.deprecator) do
938939
@view.image_tag("does_not_exist.noextension")
939940
end
940941
ensure

0 commit comments

Comments
 (0)