Skip to content

Commit

Permalink
Fix rendering html partials from an rjs template
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
sstephenson authored and josh committed Dec 4, 2008
1 parent 566a3dc commit ab211bf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def template_format
if defined? @template_format
@template_format
elsif controller && controller.respond_to?(:request)
@template_format = controller.request.template_format
@template_format = controller.request.template_format.to_sym
else
@template_format = :html
end
Expand Down
24 changes: 24 additions & 0 deletions actionpack/test/controller/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ def render_html_only_partial_within_inline
render :inline => "Hello world <%= helper_method_to_render_to_string :partial => 'test/partial_with_only_html_version' %>"
end

def render_implicit_html_template
end

def render_explicit_html_template
end

def formatted_html_erb
end

Expand Down Expand Up @@ -947,6 +953,24 @@ def test_rendering_html_only_partial_within_inline_with_js
assert_equal "Hello world partial with only html version", @response.body
end

def test_render_in_an_rjs_template_should_pick_html_templates_when_available
[:js, "js"].each do |format|
assert_nothing_raised do
get :render_implicit_html_template, :format => format
assert_equal %(document.write("Hello world\\n");), @response.body
end
end
end

def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template
[:js, "js"].each do |format|
assert_nothing_raised do
get :render_explicit_html_template, :format => format
assert_equal %(document.write("Hello world\\n");), @response.body
end
end
end

def test_should_render_formatted_template
get :formatted_html_erb
assert_equal 'formatted html erb', @response.body
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/fixtures/test/_one.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render :partial => "two" %> world
1 change: 1 addition & 0 deletions actionpack/test/fixtures/test/_two.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
page.call "document.write", render(:partial => "one.html.erb")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
page.call "document.write", render(:partial => "one")

0 comments on commit ab211bf

Please sign in to comment.