Skip to content

Commit

Permalink
restore ability to return nil from asset_host proc, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Walbran committed May 15, 2013
1 parent e2f3e50 commit 122ac9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/helpers/asset_url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request)
host = config.asset_host if defined? config.asset_host
host ||= request.base_url if request && options[:protocol] == :request
return unless host

if host.respond_to?(:call)
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
Expand All @@ -204,6 +203,8 @@ def compute_asset_host(source = "", options = {})
host = host % (Zlib.crc32(source) % 4)
end

return unless host

if host =~ URI_REGEXP
host
else
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/template/asset_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ def test_should_not_modify_source_string
assert_equal copy, source
end

def test_image_path_with_asset_host_proc_returning_nil
@controller.config.asset_host = Proc.new do |source|
unless source.end_with?("tiff")
"cdn.example.com"
end
end

assert_equal "/images/file.tiff", image_path("file.tiff")
assert_equal "http://cdn.example.com/images/file.png", image_path("file.png")
end

def test_caching_image_path_with_caching_and_proc_asset_host_using_request
@controller.config.asset_host = Proc.new do |source, request|
if request.ssl?
Expand Down

0 comments on commit 122ac9f

Please sign in to comment.