From 4b6321efa9be103ca1e00c13dd9d955b076dd31e Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Thu, 3 Sep 2009 14:00:40 -0500 Subject: Don't raise exceptions for missing javascript_include_tag or stylesheet_link_tag sources unless the :cache or :concat options are given. [#2738 state:resolved] Signed-off-by: Joshua Peek --- .../lib/action_view/helpers/asset_tag_helper.rb | 8 ++- actionpack/test/template/asset_tag_helper_test.rb | 62 ++++++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index c71840d41f..6b00e7afb5 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -286,7 +286,9 @@ module ActionView end javascript_src_tag(joined_javascript_name, options) else - ensure_javascript_sources!(expand_javascript_sources(sources, recursive)).collect { |source| javascript_src_tag(source, options) }.join("\n") + sources = expand_javascript_sources(sources, recursive) + ensure_javascript_sources!(sources) if cache + sources.collect { |source| javascript_src_tag(source, options) }.join("\n") end end @@ -435,7 +437,9 @@ module ActionView end stylesheet_tag(joined_stylesheet_name, options) else - ensure_stylesheet_sources!(expand_stylesheet_sources(sources, recursive)).collect { |source| stylesheet_tag(source, options) }.join("\n") + sources = expand_stylesheet_sources(sources, recursive) + ensure_stylesheet_sources!(sources) if cache + sources.collect { |source| stylesheet_tag(source, options) }.join("\n") end end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 28f9d48671..83fc6a282c 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -213,11 +213,11 @@ class AssetTagHelperTest < ActionView::TestCase end def test_javascript_include_tag_with_missing_source - assert_raise(Errno::ENOENT) { + assert_nothing_raised { javascript_include_tag('missing_security_guard') } - assert_raise(Errno::ENOENT) { + assert_nothing_raised { javascript_include_tag(:defaults, 'missing_security_guard') } @@ -276,7 +276,7 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_link_tag_with_missing_source - assert_raise(Errno::ENOENT) { + assert_nothing_raised { stylesheet_link_tag('missing_security_guard') } @@ -639,6 +639,40 @@ class AssetTagHelperTest < ActionView::TestCase assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) end + def test_caching_javascript_include_tag_when_caching_on_and_missing_javascript_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.perform_caching = true + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => true) + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => "money") + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) + end + + def test_caching_javascript_include_tag_when_caching_off_and_missing_javascript_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.perform_caching = false + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => true) + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => "money") + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) + end + def test_caching_stylesheet_link_tag_when_caching_on ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' @@ -709,7 +743,6 @@ class AssetTagHelperTest < ActionView::TestCase def test_caching_stylesheet_link_tag_when_caching_on_and_missing_css_file ENV["RAILS_ASSET_ID"] = "" - ActionController::Base.asset_host = 'http://a0.example.com' ActionController::Base.perform_caching = true assert_raise(Errno::ENOENT) { @@ -729,6 +762,27 @@ class AssetTagHelperTest < ActionView::TestCase FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) end + def test_caching_stylesheet_link_tag_when_caching_off_and_missing_css_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.perform_caching = false + + assert_raise(Errno::ENOENT) { + stylesheet_link_tag('bank', 'robber', 'missing_security_guard', :cache => true) + } + + assert ! File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) + + assert_raise(Errno::ENOENT) { + stylesheet_link_tag('bank', 'robber', 'missing_security_guard', :cache => "money") + } + + assert ! File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) + + ensure + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) + end + def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } -- cgit v1.2.3