aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/asset_tag_helper_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-06 20:53:23 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-06 20:53:23 +0000
commita1b0349362fd6c17af5aeff481996f6fac235828 (patch)
treeacae9550ddae5e678618b9eb79ffc3bbf00b5c23 /actionpack/test/template/asset_tag_helper_test.rb
parentca4c7ab362d0110bfade496ca66b30bafdb7f25e (diff)
downloadrails-a1b0349362fd6c17af5aeff481996f6fac235828.tar.gz
rails-a1b0349362fd6c17af5aeff481996f6fac235828.tar.bz2
rails-a1b0349362fd6c17af5aeff481996f6fac235828.zip
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
Diffstat (limited to 'actionpack/test/template/asset_tag_helper_test.rb')
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb41
1 files changed, 40 insertions, 1 deletions
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(
+ %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>),
+ 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(
+ %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>),
+ 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'