mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
parent
4711298767
commit
39514af7e7
8 changed files with 46 additions and 0 deletions
|
@ -105,6 +105,7 @@ module AbstractController
|
|||
# Find and renders a template based on the options given.
|
||||
# :api: private
|
||||
def _render_template(options) #:nodoc:
|
||||
lookup_context.rendered_format = nil if options[:formats]
|
||||
view_renderer.render(view_context, options)
|
||||
end
|
||||
|
||||
|
|
|
@ -559,6 +559,23 @@ class TestController < ActionController::Base
|
|||
render :template => "test/hello_world"
|
||||
end
|
||||
|
||||
def render_to_string_with_template_and_html_partial
|
||||
@text = render_to_string :template => "test/with_partial", :formats => [:text]
|
||||
@html = render_to_string :template => "test/with_partial", :formats => [:html]
|
||||
render :template => "test/with_html_partial"
|
||||
end
|
||||
|
||||
def render_to_string_and_render_with_different_formats
|
||||
@html = render_to_string :template => "test/with_partial", :formats => [:html]
|
||||
render :template => "test/with_partial", :formats => [:text]
|
||||
end
|
||||
|
||||
def render_template_within_a_template_with_other_format
|
||||
render :template => "test/with_xml_template",
|
||||
:formats => [:html],
|
||||
:layout => "with_html_partial"
|
||||
end
|
||||
|
||||
def partial_with_counter
|
||||
render :partial => "counter", :locals => { :counter_counter => 5 }
|
||||
end
|
||||
|
@ -1268,6 +1285,28 @@ class RenderTest < ActionController::TestCase
|
|||
assert_equal "text/html", @response.content_type
|
||||
end
|
||||
|
||||
def test_render_to_string_with_template_and_html_partial
|
||||
get :render_to_string_with_template_and_html_partial
|
||||
assert_equal "**only partial**\n", assigns(:text)
|
||||
assert_equal "<strong>only partial</strong>\n", assigns(:html)
|
||||
assert_equal "<strong>only html partial</strong>\n", @response.body
|
||||
assert_equal "text/html", @response.content_type
|
||||
end
|
||||
|
||||
def test_render_to_string_and_render_with_different_formats
|
||||
get :render_to_string_and_render_with_different_formats
|
||||
assert_equal "<strong>only partial</strong>\n", assigns(:html)
|
||||
assert_equal "**only partial**\n", @response.body
|
||||
assert_equal "text/plain", @response.content_type
|
||||
end
|
||||
|
||||
def test_render_template_within_a_template_with_other_format
|
||||
get :render_template_within_a_template_with_other_format
|
||||
expected = "only html partial<p>This is grand!</p>"
|
||||
assert_equal expected, @response.body.strip
|
||||
assert_equal "text/html", @response.content_type
|
||||
end
|
||||
|
||||
def test_partial_with_counter
|
||||
get :partial_with_counter
|
||||
assert_equal "5", @response.body
|
||||
|
|
1
actionpack/test/fixtures/layouts/with_html_partial.html.erb
vendored
Normal file
1
actionpack/test/fixtures/layouts/with_html_partial.html.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<%= render :partial => "partial_only_html" %><%= yield %>
|
1
actionpack/test/fixtures/test/_partial_only_html.html
vendored
Normal file
1
actionpack/test/fixtures/test/_partial_only_html.html
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
only html partial
|
1
actionpack/test/fixtures/test/with_html_partial.html.erb
vendored
Normal file
1
actionpack/test/fixtures/test/with_html_partial.html.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<strong><%= render :partial => "partial_only_html" %></strong>
|
1
actionpack/test/fixtures/test/with_partial.html.erb
vendored
Normal file
1
actionpack/test/fixtures/test/with_partial.html.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<strong><%= render :partial => "partial_only" %></strong>
|
1
actionpack/test/fixtures/test/with_partial.text.erb
vendored
Normal file
1
actionpack/test/fixtures/test/with_partial.text.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
**<%= render :partial => "partial_only" %>**
|
1
actionpack/test/fixtures/test/with_xml_template.html.erb
vendored
Normal file
1
actionpack/test/fixtures/test/with_xml_template.html.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<%= render :template => "test/greeting", :formats => :xml %>
|
Loading…
Reference in a new issue