Permalink
Browse files

Add a bunch of tests for various render :action, layout combinations

  • Loading branch information...
1 parent 4a93148 commit 34f058e082754bb726a4753fa26e8e8c082702c0 @wycats wycats committed Mar 23, 2009
@@ -2,7 +2,7 @@ module ActionController
module Layouts
def render_to_string(options)
if !options.key?(:text) || options.key?(:layout)
- options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _layout
+ options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _default_layout
end
super
@@ -13,7 +13,7 @@ def render_to_string(options)
def _layout_for_option(name)
case name
when String then _layout_for_name(name)
- when true then _layout
+ when true then _default_layout(true)
when false then nil
end
end
@@ -22,13 +22,14 @@ def _layout_for_name(name)
view_paths.find_by_parts(name, formats, "layouts")
end
- def _layout
+ def _default_layout(require_layout = false)
begin
_layout_for_name(controller_path)
rescue ActionView::MissingTemplate
begin
_layout_for_name("application")
- rescue ActionView::MissingTemplate
+ rescue ActionView::MissingTemplate => e
+ raise e if require_layout
end
end
end
@@ -42,6 +42,9 @@ def find_by_parts(path, extension = nil, prefix = nil, partial = false)
end
Template.new(path, self)
+ rescue ActionView::MissingTemplate => e
+ extension ||= []
+ raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}.{#{extension.join(",")}}")
end
def find_template(original_template_path, format = nil)
@@ -1,60 +0,0 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
-
-module HappyPath
-
- # This has no layout and it works
- class RenderActionLolController < ActionController::Base2
-
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({
- "happy_path/render_action_lol/hello_world.html.erb" => "Hello world!",
- "happy_path/render_action_lol/goodbye_world.html.erb" => "Goodbye world!",
- "happy_path/sexy_time/borat.html.erb" => "I LIKE!!!"
- })]
-
- def render_action_hello_world
- render :action => "hello_world"
- end
-
- def render_action_goodbye_world
- render :action => "goodbye_world"
- end
-
- end
-
- class SexyTimeController < ActionController::Base2
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({
- "happy_path/render_action_lol/hello_world.html.erb" => "Hello world!",
- "happy_path/render_action_lol/goodbye_world.html.erb" => "Goodbye world!",
- "happy_path/sexy_time/borat.html.erb" => "I LIKE!!!"
- })]
-
- def borat
- render "borat"
- end
- end
-
- class TestRenderHelloAction < SimpleRouteCase
-
- describe "Rendering an action using :action => <String>"
-
- get "/happy_path/render_action/render_action_hello_world"
- assert_body "Hello world!"
- assert_status 200
-
- end
-
- class TestRenderGoodbyeAction < SimpleRouteCase
- describe "Goodbye"
-
- get "/happy_path/render_action_lol/render_action_goodbye_world"
- assert_body "Goodbye world!"
- assert_status 200
- end
-
- class TestRenderBorat < SimpleRouteCase
- describe "Borat yo"
- get "/happy_path/sexy_time/borat"
- assert_body "I LIKE!!!"
- assert_status 200
- end
-end
Oops, something went wrong.

0 comments on commit 34f058e

Please sign in to comment.