diff options
author | Joshua Peek <josh@joshpeek.com> | 2012-10-13 10:13:47 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2012-10-13 10:13:47 -0500 |
commit | 60a4fffd83e94ad4471570b16f9d954f04bc0300 (patch) | |
tree | 8652a0bc3d0fe388d9be1419c5fa1fedd2a228bb /actionpack | |
parent | 5dfeb1b852c6c4a7b9c4aa3fa8dc5f25b516f9f1 (diff) | |
download | rails-60a4fffd83e94ad4471570b16f9d954f04bc0300.tar.gz rails-60a4fffd83e94ad4471570b16f9d954f04bc0300.tar.bz2 rails-60a4fffd83e94ad4471570b16f9d954f04bc0300.zip |
Allow asset url config to be undefined
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_url_helper.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 41 |
2 files changed, 45 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_url_helper.rb b/actionpack/lib/action_view/helpers/asset_url_helper.rb index 9255c1e2f6..a0fcac59a3 100644 --- a/actionpack/lib/action_view/helpers/asset_url_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_url_helper.rb @@ -135,7 +135,9 @@ module ActionView source = compute_asset_path(source, options) end - if relative_url_root = config.relative_url_root || asset_request.try(:script_name) + relative_url_root = (defined?(config.relative_url_root) && config.relative_url_root) || + (asset_request && asset_request.script_name) + if relative_url_root source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/") end @@ -180,7 +182,7 @@ module ActionView # (proc or otherwise). def compute_asset_host(source = "", options = {}) request = asset_request - host = config.asset_host + host = config.asset_host if defined? config.asset_host host ||= request.base_url if request && options[:protocol] == :request return unless host diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 5dc854d561..8435db3166 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -733,3 +733,44 @@ class AssetUrlHelperControllerTest < ActionView::TestCase assert_equal "http://www.example.com/foo", @controller.asset_url("foo") end end + +class AssetUrlHelperEmptyModuleTest < ActionView::TestCase + tests ActionView::Helpers::AssetUrlHelper + + def setup + super + + @module = Module.new + @module.extend ActionView::Helpers::AssetUrlHelper + end + + def test_asset_path + assert_equal "/foo", @module.asset_path("foo") + end + + def test_asset_url + assert_equal "/foo", @module.asset_url("foo") + end + + def test_asset_url_with_request + @module.instance_eval do + def request + Struct.new(:base_url, :script_name).new("http://www.example.com", nil) + end + end + + assert @module.request + assert_equal "http://www.example.com/foo", @module.asset_url("foo") + end + + def test_asset_url_with_config_asset_host + @module.instance_eval do + def config + Struct.new(:asset_host).new("http://www.example.com") + end + end + + assert @module.config.asset_host + assert_equal "http://www.example.com/foo", @module.asset_url("foo") + end +end |