Skip to content

Commit

Permalink
Restore asset_url for Rails 3.x
Browse files Browse the repository at this point in the history
And only test javascript_url/stylesheet_url on 4.0+.
  • Loading branch information
matthewd committed Aug 19, 2014
1 parent ef6b7b2 commit e6b4127
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/sprockets/rails/legacy_asset_url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def asset_path(source, options = {})
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'
Expand Down
24 changes: 16 additions & 8 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def setup
Sprockets::Rails::Helper.raise_runtime_errors = true
end

def asset_url_helpers?
defined?(ActionView::VERSION::MAJOR) || ActionPack::VERSION::MAJOR > 3
end

def test_public_folder_fallback_works_correctly
@view.asset_path("asset-does-not-exist-foo.js")
@view.asset_url("asset-does-not-exist-foo.js")
Expand All @@ -429,8 +433,10 @@ def test_asset_not_precompiled_error
@view.javascript_path("foo")
end

assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
@view.javascript_url("foo")
if asset_url_helpers?
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
@view.javascript_url("foo")
end
end

assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
Expand All @@ -450,7 +456,7 @@ def test_asset_not_precompiled_error
@view.asset_path("foo.js")
@view.asset_url("foo.js")
@view.javascript_path("foo")
@view.javascript_url("foo")
@view.javascript_url("foo") if asset_url_helpers?
@view.javascript_include_tag("foo.js")
@view.javascript_include_tag("foo")
@view.javascript_include_tag(:foo)
Expand All @@ -459,8 +465,10 @@ def test_asset_not_precompiled_error
@view.stylesheet_path("foo")
end

assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
@view.stylesheet_url("foo")
if asset_url_helpers?
assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
@view.stylesheet_url("foo")
end
end

assert_raises(Sprockets::Rails::Helper::AssetFilteredError) do
Expand All @@ -474,20 +482,20 @@ def test_asset_not_precompiled_error
end

@view.stylesheet_path("foo")
@view.stylesheet_url("foo")
@view.stylesheet_url("foo") if asset_url_helpers?
@view.stylesheet_link_tag("foo")

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

@view.asset_path("foo.js")
@view.asset_url("foo.js")
@view.javascript_path("foo")
@view.javascript_url("foo")
@view.javascript_url("foo") if asset_url_helpers?
@view.javascript_include_tag("foo.js")
@view.javascript_include_tag("foo")
@view.javascript_include_tag(:foo)
@view.stylesheet_path("foo")
@view.stylesheet_url("foo")
@view.stylesheet_url("foo") if asset_url_helpers?
@view.stylesheet_link_tag("foo")
end

Expand Down

0 comments on commit e6b4127

Please sign in to comment.