Skip to content

Commit e6b4127

Browse files
committed
Restore asset_url for Rails 3.x
And only test javascript_url/stylesheet_url on 4.0+.
1 parent ef6b7b2 commit e6b4127

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/sprockets/rails/legacy_asset_url_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def asset_path(source, options = {})
3434
end
3535
alias_method :path_to_asset, :asset_path
3636

37+
def asset_url(source, options = {})
38+
path_to_asset(source, options.merge(:protocol => :request))
39+
end
40+
3741
ASSET_EXTENSIONS = {
3842
:javascript => '.js',
3943
:stylesheet => '.css'

test/test_helper.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ def setup
407407
Sprockets::Rails::Helper.raise_runtime_errors = true
408408
end
409409

410+
def asset_url_helpers?
411+
defined?(ActionView::VERSION::MAJOR) || ActionPack::VERSION::MAJOR > 3
412+
end
413+
410414
def test_public_folder_fallback_works_correctly
411415
@view.asset_path("asset-does-not-exist-foo.js")
412416
@view.asset_url("asset-does-not-exist-foo.js")
@@ -429,8 +433,10 @@ def test_asset_not_precompiled_error
429433
@view.javascript_path("foo")
430434
end
431435

432-
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
433-
@view.javascript_url("foo")
436+
if asset_url_helpers?
437+
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
438+
@view.javascript_url("foo")
439+
end
434440
end
435441

436442
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
@@ -450,7 +456,7 @@ def test_asset_not_precompiled_error
450456
@view.asset_path("foo.js")
451457
@view.asset_url("foo.js")
452458
@view.javascript_path("foo")
453-
@view.javascript_url("foo")
459+
@view.javascript_url("foo") if asset_url_helpers?
454460
@view.javascript_include_tag("foo.js")
455461
@view.javascript_include_tag("foo")
456462
@view.javascript_include_tag(:foo)
@@ -459,8 +465,10 @@ def test_asset_not_precompiled_error
459465
@view.stylesheet_path("foo")
460466
end
461467

462-
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
463-
@view.stylesheet_url("foo")
468+
if asset_url_helpers?
469+
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
470+
@view.stylesheet_url("foo")
471+
end
464472
end
465473

466474
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
@@ -474,20 +482,20 @@ def test_asset_not_precompiled_error
474482
end
475483

476484
@view.stylesheet_path("foo")
477-
@view.stylesheet_url("foo")
485+
@view.stylesheet_url("foo") if asset_url_helpers?
478486
@view.stylesheet_link_tag("foo")
479487

480488
Sprockets::Rails::Helper.precompile = [ lambda {|logical_path| true } ]
481489

482490
@view.asset_path("foo.js")
483491
@view.asset_url("foo.js")
484492
@view.javascript_path("foo")
485-
@view.javascript_url("foo")
493+
@view.javascript_url("foo") if asset_url_helpers?
486494
@view.javascript_include_tag("foo.js")
487495
@view.javascript_include_tag("foo")
488496
@view.javascript_include_tag(:foo)
489497
@view.stylesheet_path("foo")
490-
@view.stylesheet_url("foo")
498+
@view.stylesheet_url("foo") if asset_url_helpers?
491499
@view.stylesheet_link_tag("foo")
492500
end
493501

0 commit comments

Comments
 (0)