From 11c715a53fd6309c37883b7d44462cc0a66f3bba Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 5 Jul 2006 02:38:55 +0000 Subject: Added exception handling of missing layouts (closes #5373) [chris@ozmm.org] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4550 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/layout.rb | 2 ++ actionpack/test/controller/layout_test.rb | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c85acf800b..2cf28dd283 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added exception handling of missing layouts #5373 [chris@ozmm.org] + * Fixed that real files and symlinks should be treated the same when compiling templates #5438 [zachary@panandscan.com] * Fixed that the flash should be reset when reset_session is called #5584 [shugo@ruby-lang.org] diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index e421f8ed9e..91ca16913e 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -236,6 +236,8 @@ module ActionController #:nodoc: template_with_options = options.is_a?(Hash) if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) + assert_existence_of_template_file(layout) + options = options.merge :layout => false if template_with_options logger.info("Rendering #{options} within #{layout}") if logger diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 9dc0cdcfe9..bbb13d0320 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -121,4 +121,23 @@ class LayoutSetInResponseTest < Test::Unit::TestCase get :hello assert_nil @response.layout end -end \ No newline at end of file +end + + +class SetsNonExistentLayoutFile < LayoutTest + layout "nofile.rhtml" +end + +class LayoutExceptionRaised < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_exception_raised_when_layout_file_not_found + @controller = SetsNonExistentLayoutFile.new + get :hello + @response.template.class.module_eval { attr_accessor :exception } + assert_equal ActionController::MissingTemplate, @response.template.exception.class + end +end -- cgit v1.2.3