diff options
author | Marcel Molina <marcel@vernix.org> | 2006-05-17 07:25:36 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2006-05-17 07:25:36 +0000 |
commit | 7252666b74e00c569b431d1a798fb7280923929f (patch) | |
tree | 2f6ba0b6fbf8cfcccfac4ae4496b15484068fb03 | |
parent | 36d1a2f302817815e0e70334733d2daf1a14a4f5 (diff) | |
download | rails-7252666b74e00c569b431d1a798fb7280923929f.tar.gz rails-7252666b74e00c569b431d1a798fb7280923929f.tar.bz2 rails-7252666b74e00c569b431d1a798fb7280923929f.zip |
Add layout attribute to response object with the name of the layout that was rendered, or nil if none rendered. [Kevin Clark kevin.clark@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4346 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/layout.rb | 1 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/response.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/layout_test.rb | 51 |
4 files changed, 55 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 9a75a3852c..b3388a3773 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add layout attribute to response object with the name of the layout that was rendered, or nil if none rendered. [Kevin Clark kevin.clark@gmail.com] + * Fix NoMethodError when parsing params like &&. [Adam Greenfield] * Fix flip flopped logic in docs for url_for's :only_path option. Closes #4998. [esad@esse.at] diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index f27e42ea17..e421f8ed9e 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -249,6 +249,7 @@ module ActionController #:nodoc: erase_render_results add_variables_to_assigns @template.instance_variable_set("@content_for_layout", content_for_layout) + @response.layout = layout render_text(@template.render_file(layout, true), deprecated_status) else render_with_no_layout(options, deprecated_status, &block) diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb index 746d6097be..2bec477647 100755 --- a/actionpack/lib/action_controller/response.rb +++ b/actionpack/lib/action_controller/response.rb @@ -1,7 +1,7 @@ module ActionController class AbstractResponse #:nodoc: DEFAULT_HEADERS = { "Cache-Control" => "no-cache" } - attr_accessor :body, :headers, :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params + attr_accessor :body, :headers, :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params, :layout def initialize @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], [] diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index c7db19ccc9..9dc0cdcfe9 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -70,4 +70,55 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase assert_equal 'layouts/controller_name_space/nested', @controller.active_layout assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body end +end + + +class DefaultLayoutController < LayoutTest +end + +class HasOwnLayoutController < LayoutTest + layout 'item' +end + +class SetsLayoutInRenderController < LayoutTest + def hello + render :layout => 'third_party_template_library' + end +end + +class RendersNoLayoutController < LayoutTest + def hello + render :layout => false + end +end + +class LayoutSetInResponseTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_layout_set_when_using_default_layout + @controller = DefaultLayoutController.new + get :hello + assert_equal 'layouts/layout_test', @response.layout + end + + def test_layout_set_when_set_in_controller + @controller = HasOwnLayoutController.new + get :hello + assert_equal 'layouts/item', @response.layout + end + + def test_layout_set_when_using_render + @controller = SetsLayoutInRenderController.new + get :hello + assert_equal 'layouts/third_party_template_library', @response.layout + end + + def test_layout_is_not_set_when_none_rendered + @controller = RendersNoLayoutController.new + get :hello + assert_nil @response.layout + end end
\ No newline at end of file |