Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ported over render :template tests

  • Loading branch information...
commit 0c3d9bc4c2b329cb754bfed1e465f99d058e1193 1 parent 4f68311
Yehuda Katz + Carl Lerche authored
View
3  actionpack/lib/action_controller/abstract/layouts.rb
@@ -50,8 +50,7 @@ def _layout
end
def _render_template(template, options)
- # layout = options[:_layout].is_a?(ActionView::Template) ? options[:_layout] : _layout_for_name(options[:_layout])
- _action_view._render_template_with_layout(template, options[:_layout])
+ _action_view._render_template_with_layout(template, options[:_layout], options)
end
private
View
1  actionpack/lib/action_controller/abstract/renderer.rb
@@ -40,7 +40,6 @@ def render(options = {})
#
# :api: plugin
def render_to_body(options = {})
- options = {:_template_name => options} if options.is_a?(String)
name = options[:_template_name] || action_name
template = options[:_template] || view_paths.find_by_parts(name.to_s, {:formats => formats}, options[:_prefix])
View
4 actionpack/lib/action_controller/new_base/renderer.rb
@@ -21,10 +21,6 @@ def render(action, options = {})
end
def render_to_body(options)
- unless options.is_a?(Hash)
- options = {:action => options}
- end
-
if options.key?(:text)
options[:_template] = ActionView::TextTemplate.new(_text(options))
template = nil
View
19 actionpack/test/controller/render_test.rb
@@ -80,6 +80,7 @@ def handle_last_modified_and_etags
fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ])
end
+ # :ported:
def render_hello_world
render :template => "test/hello_world"
end
@@ -94,14 +95,17 @@ def render_hello_world_with_etag_set
render :template => "test/hello_world"
end
+ # :ported: compatibility
def render_hello_world_with_forward_slash
render :template => "/test/hello_world"
end
+ # :ported:
def render_template_in_top_directory
render :template => 'shared'
end
+ # :deprecated:
def render_template_in_top_directory_with_slash
render :template => '/shared'
end
@@ -251,6 +255,10 @@ def render_vanilla_js_hello
render :js => "alert('hello')"
end
+ # This test is testing 3 things:
+ # render :file in AV :ported:
+ # render :template in AC :ported:
+ # setting content type
def render_xml_hello
@name = "David"
render :template => "test/hello"
@@ -399,6 +407,7 @@ def accessing_params_in_template_with_layout
render :layout => true, :inline => "Hello: <%= params[:name] %>"
end
+ # :ported:
def render_with_explicit_template
render :template => "test/hello_world"
end
@@ -407,6 +416,7 @@ def render_with_explicit_string_template
render "test/hello_world"
end
+ # :ported:
def render_with_explicit_template_with_locals
render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
end
@@ -443,10 +453,15 @@ def @template.name() nil end
render :action => "potential_conflicts"
end
+ # :deprecated:
+ # Tests being able to pick a .builder template over a .erb
+ # For instance, being able to have hello.xml.builder and hello.xml.erb
+ # and select one via "hello.builder" or "hello.erb"
def hello_world_from_rxml_using_action
render :action => "hello_world_from_rxml.builder"
end
+ # :deprecated:
def hello_world_from_rxml_using_template
render :template => "test/hello_world_from_rxml.builder"
end
@@ -798,17 +813,20 @@ def test_line_offset
end
end
+ # :ported: compatibility
def test_render_with_forward_slash
get :render_hello_world_with_forward_slash
assert_template "test/hello_world"
end
+ # :ported:
def test_render_in_top_directory
get :render_template_in_top_directory
assert_template "shared"
assert_equal "Elastica", @response.body
end
+ # :ported:
def test_render_in_top_directory_with_slash
get :render_template_in_top_directory_with_slash
assert_template "shared"
@@ -1259,6 +1277,7 @@ def test_render_text_with_assigns
assert_equal "world", assigns["hello"]
end
+ # :ported:
def test_template_with_locals
get :render_with_explicit_template_with_locals
assert_equal "The secret is area51\n", @response.body
View
15 actionpack/test/new_base/render_template_test.rb
@@ -5,7 +5,8 @@ class WithoutLayoutController < ActionController::Base2
self.view_paths = [ActionView::Template::FixturePath.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
- "shared.html.erb" => "Elastica"
+ "shared.html.erb" => "Elastica",
+ "locals.html.erb" => "The secret is <%= secret %>"
)]
def index
@@ -19,6 +20,10 @@ def in_top_directory
def in_top_directory_with_slash
render :template => '/shared'
end
+
+ def with_locals
+ render :template => "locals", :locals => { :secret => 'area51' }
+ end
end
class TestWithoutLayout < SimpleRouteCase
@@ -44,6 +49,14 @@ class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase
assert_body "Elastica"
assert_status 200
end
+
+ class TestTemplateRenderWithLocals < SimpleRouteCase
+ describe "rendering a template with local variables"
+
+ get "/render_template/without_layout/with_locals"
+ assert_body "The secret is area51"
+ assert_status 200
+ end
class WithLayoutController < ::ApplicationController
View
5 actionpack/test/new_base/test_helper.rb
@@ -58,6 +58,11 @@ def self.app_loaded!
end
end
+ def render_to_body(options = {})
+ options = {:template => options} if options.is_a?(String)
+ super
+ end
+
# append_view_path File.join(File.dirname(__FILE__), '..', 'fixtures')
CORE_METHODS = self.public_instance_methods
Please sign in to comment.
Something went wrong with that request. Please try again.