From a1b0349362fd6c17af5aeff481996f6fac235828 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 6 Jan 2008 20:53:23 +0000 Subject: The asset_host block takes the controller request as an optional second argument. Example: use a single asset host for SSL requests. Closes #10549. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8578 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/template/asset_tag_helper_test.rb | 41 ++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 0d84816765..37392b9f67 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -34,6 +34,8 @@ class AssetTagHelperTest < Test::Unit::TestCase @request = Class.new do def relative_url_root() "" end def protocol() 'http://' end + def ssl?() false end + def host_with_port() 'localhost' end end.new @controller.request = @request @@ -248,7 +250,7 @@ class AssetTagHelperTest < Test::Unit::TestCase end def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host - ENV["RAILS_ASSET_ID"] = "" + ENV['RAILS_ASSET_ID'] = '' ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } ActionController::Base.perform_caching = true @@ -264,6 +266,43 @@ class AssetTagHelperTest < Test::Unit::TestCase FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) end + def test_caching_javascript_include_tag_when_caching_on_with_2_argument_proc_asset_host + ENV['RAILS_ASSET_ID'] = '' + ActionController::Base.asset_host = Proc.new { |source, request| + if request.ssl? + "#{request.protocol}#{request.host_with_port}" + else + "#{request.protocol}assets#{source.length}.example.com" + end + } + ActionController::Base.perform_caching = true + + assert_equal '/javascripts/vanilla.js'.length, 23 + assert_dom_equal( + %(), + javascript_include_tag(:all, :cache => 'vanilla') + ) + + assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js')) + + class << @controller.request + def protocol() 'https://' end + def ssl?() true end + end + + assert_equal '/javascripts/secure.js'.length, 22 + assert_dom_equal( + %(), + javascript_include_tag(:all, :cache => 'secure') + ) + + assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js')) + + ensure + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js')) + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js')) + end + def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a%d.example.com' -- cgit v1.2.3