aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2008-12-04 16:35:13 -0600
committerJoshua Peek <josh@joshpeek.com>2008-12-04 16:35:13 -0600
commitab211bf592f52fbde7853961030046ea1d387851 (patch)
tree7af69666251d6ef6f32cbfd9a16792127f0e6f08 /actionpack
parent566a3dce6753eb71554d54e8883204e4868aa393 (diff)
downloadrails-ab211bf592f52fbde7853961030046ea1d387851.tar.gz
rails-ab211bf592f52fbde7853961030046ea1d387851.tar.bz2
rails-ab211bf592f52fbde7853961030046ea1d387851.zip
Fix rendering html partials from an rjs template
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/test/controller/render_test.rb24
-rw-r--r--actionpack/test/fixtures/test/_one.html.erb1
-rw-r--r--actionpack/test/fixtures/test/_two.html.erb1
-rw-r--r--actionpack/test/fixtures/test/render_explicit_html_template.js.rjs1
-rw-r--r--actionpack/test/fixtures/test/render_implicit_html_template.js.rjs1
6 files changed, 29 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index da1f283deb..a731fa3e1d 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -275,7 +275,7 @@ module ActionView #:nodoc:
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
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 972e425e35..795ad97863 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -255,6 +255,12 @@ class TestController < ActionController::Base
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
@@ -947,6 +953,24 @@ class RenderTest < ActionController::TestCase
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
diff --git a/actionpack/test/fixtures/test/_one.html.erb b/actionpack/test/fixtures/test/_one.html.erb
new file mode 100644
index 0000000000..f796291cb4
--- /dev/null
+++ b/actionpack/test/fixtures/test/_one.html.erb
@@ -0,0 +1 @@
+<%= render :partial => "two" %> world
diff --git a/actionpack/test/fixtures/test/_two.html.erb b/actionpack/test/fixtures/test/_two.html.erb
new file mode 100644
index 0000000000..5ab2f8a432
--- /dev/null
+++ b/actionpack/test/fixtures/test/_two.html.erb
@@ -0,0 +1 @@
+Hello \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs b/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs
new file mode 100644
index 0000000000..4eb12fd6af
--- /dev/null
+++ b/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs
@@ -0,0 +1 @@
+page.call "document.write", render(:partial => "one.html.erb")
diff --git a/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs b/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs
new file mode 100644
index 0000000000..3d68041756
--- /dev/null
+++ b/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs
@@ -0,0 +1 @@
+page.call "document.write", render(:partial => "one")