1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Allow asset url config to be undefined

This commit is contained in:
Joshua Peek 2012-10-13 10:13:47 -05:00
parent 5dfeb1b852
commit 60a4fffd83
2 changed files with 45 additions and 2 deletions

View file

@ -135,7 +135,9 @@ module ActionView
source = compute_asset_path(source, options) source = compute_asset_path(source, options)
end 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}/") source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
end end
@ -180,7 +182,7 @@ module ActionView
# (proc or otherwise). # (proc or otherwise).
def compute_asset_host(source = "", options = {}) def compute_asset_host(source = "", options = {})
request = asset_request 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 host ||= request.base_url if request && options[:protocol] == :request
return unless host return unless host

View file

@ -733,3 +733,44 @@ class AssetUrlHelperControllerTest < ActionView::TestCase
assert_equal "http://www.example.com/foo", @controller.asset_url("foo") assert_equal "http://www.example.com/foo", @controller.asset_url("foo")
end end
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