Skip to content

Commit

Permalink
Add layout attribute to response object with the name of the layout t…
Browse files Browse the repository at this point in the history
…hat 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
  • Loading branch information
Marcel Molina committed May 17, 2006
1 parent 36d1a2f commit 7252666
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *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 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] * Fix flip flopped logic in docs for url_for's :only_path option. Closes #4998. [esad@esse.at]
Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/action_controller/layout.rb
Expand Up @@ -249,6 +249,7 @@ def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layo
erase_render_results erase_render_results
add_variables_to_assigns add_variables_to_assigns
@template.instance_variable_set("@content_for_layout", content_for_layout) @template.instance_variable_set("@content_for_layout", content_for_layout)
@response.layout = layout
render_text(@template.render_file(layout, true), deprecated_status) render_text(@template.render_file(layout, true), deprecated_status)
else else
render_with_no_layout(options, deprecated_status, &block) render_with_no_layout(options, deprecated_status, &block)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/response.rb
@@ -1,7 +1,7 @@
module ActionController module ActionController
class AbstractResponse #:nodoc: class AbstractResponse #:nodoc:
DEFAULT_HEADERS = { "Cache-Control" => "no-cache" } 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 def initialize
@body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], [] @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
Expand Down
51 changes: 51 additions & 0 deletions actionpack/test/controller/layout_test.rb
Expand Up @@ -70,4 +70,55 @@ def test_namespaced_controllers_auto_detect_layouts
assert_equal 'layouts/controller_name_space/nested', @controller.active_layout assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
end 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 end

0 comments on commit 7252666

Please sign in to comment.