From bd940d98bd417da7cb0a815a1c02aef500c8b2db Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 20 Mar 2008 16:26:04 +0000 Subject: Re-added ActionView::Helpers::register_javascript/stylesheet_expansion to make it easier for plugin developers to inject multiple assets. Closes #10350. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9065 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/template/asset_tag_helper_test.rb | 53 +++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'actionpack/test/template/asset_tag_helper_test.rb') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index ffd1d955e1..be605329fc 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -84,7 +84,7 @@ class AssetTagHelperTest < Test::Unit::TestCase %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(), %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n), %(javascript_include_tag(:defaults)) => %(\n\n\n\n), - %(javascript_include_tag(:all)) => %(\n\n), + %(javascript_include_tag(:all)) => %(\n\n\n\n\n\n), %(javascript_include_tag(:defaults, "test")) => %(\n\n\n\n\n), %(javascript_include_tag("test", :defaults)) => %(\n\n\n\n\n) } @@ -175,6 +175,22 @@ class AssetTagHelperTest < Test::Unit::TestCase assert_dom_equal %(\n\n\n\n\n\n\n), javascript_include_tag(:defaults) end + def test_custom_javascript_expansions + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"] + assert_dom_equal %(\n\n\n\n), javascript_include_tag('first', :monkey, 'last') + end + + def test_custom_javascript_expansions_and_defaults_puts_application_js_at_the_end + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"] + assert_dom_equal %(\n\n\n\n\n\n\n\n\n), javascript_include_tag('first', :defaults, :monkey, 'last') + end + + def test_custom_javascript_expansions_with_undefined_symbol + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => nil + assert_raise(ArgumentError) { javascript_include_tag('first', :monkey, 'last') } + end + def test_stylesheet_path StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -188,6 +204,16 @@ class AssetTagHelperTest < Test::Unit::TestCase StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end + def test_custom_stylesheet_expansions + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => ["head", "body", "tail"] + assert_dom_equal %(\n\n\n\n), stylesheet_link_tag('first', :monkey, 'last') + end + + def test_custom_stylesheet_expansions_with_undefined_symbol + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => nil + assert_raise(ArgumentError) { stylesheet_link_tag('first', :monkey, 'last') } + end + def test_image_path ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -319,19 +345,40 @@ class AssetTagHelperTest < Test::Unit::TestCase FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) end + def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_the_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.asset_host = 'http://a0.example.com' + ActionController::Base.perform_caching = true + + assert_dom_equal( + %(), + javascript_include_tag(:all, :cache => "combined") + ) + + assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) + + assert_equal( + %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js), + IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) + ) + + ensure + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js')) + end + def test_caching_javascript_include_tag_when_caching_off ENV["RAILS_ASSET_ID"] = "" ActionController::Base.perform_caching = false assert_dom_equal( - %(\n\n), + %(\n\n\n\n\n\n), javascript_include_tag(:all, :cache => true) ) assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) assert_dom_equal( - %(\n\n), + %(\n\n\n\n\n\n), javascript_include_tag(:all, :cache => "money") ) -- cgit v1.2.3