aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-04-08 20:22:07 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-04-08 20:22:07 -0700
commit4691c696b0cda985c5d868312555cd538328a99c (patch)
tree54de65952509e791ddb542879fa270e3384fc0aa /actionpack/test
parentbd2bf5390d892a1c11bcaa2143f557b82611015e (diff)
downloadrails-4691c696b0cda985c5d868312555cd538328a99c.tar.gz
rails-4691c696b0cda985c5d868312555cd538328a99c.tar.bz2
rails-4691c696b0cda985c5d868312555cd538328a99c.zip
Expect an incompatible encoding exception when a template with a magic comment renders a partial without one and its source encoding doesn't match the default external encoding
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/fixtures/test/_utf8_partial.html.erb1
-rw-r--r--actionpack/test/fixtures/test/_utf8_partial_magic.html.erb2
-rw-r--r--actionpack/test/fixtures/test/utf8.html.erb2
-rw-r--r--actionpack/test/fixtures/test/utf8_magic.html.erb2
-rw-r--r--actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb5
-rw-r--r--actionpack/test/template/render_test.rb15
6 files changed, 23 insertions, 4 deletions
diff --git a/actionpack/test/fixtures/test/_utf8_partial.html.erb b/actionpack/test/fixtures/test/_utf8_partial.html.erb
new file mode 100644
index 0000000000..8d717fd427
--- /dev/null
+++ b/actionpack/test/fixtures/test/_utf8_partial.html.erb
@@ -0,0 +1 @@
+<%= "текст" %>
diff --git a/actionpack/test/fixtures/test/_utf8_partial_magic.html.erb b/actionpack/test/fixtures/test/_utf8_partial_magic.html.erb
new file mode 100644
index 0000000000..4e2224610a
--- /dev/null
+++ b/actionpack/test/fixtures/test/_utf8_partial_magic.html.erb
@@ -0,0 +1,2 @@
+<%# encoding: utf-8 -%>
+<%= "текст" %>
diff --git a/actionpack/test/fixtures/test/utf8.html.erb b/actionpack/test/fixtures/test/utf8.html.erb
index 551c24e354..ac98c2f012 100644
--- a/actionpack/test/fixtures/test/utf8.html.erb
+++ b/actionpack/test/fixtures/test/utf8.html.erb
@@ -1,4 +1,4 @@
-Русский <%= "текст" %>
+Русский <%= render :partial => 'test/utf8_partial' %>
<%= "日".encoding %>
<%= @output_buffer.encoding %>
<%= __ENCODING__ %>
diff --git a/actionpack/test/fixtures/test/utf8_magic.html.erb b/actionpack/test/fixtures/test/utf8_magic.html.erb
index e2aa85e66a..257279c29f 100644
--- a/actionpack/test/fixtures/test/utf8_magic.html.erb
+++ b/actionpack/test/fixtures/test/utf8_magic.html.erb
@@ -1,5 +1,5 @@
<%# encoding: utf-8 -%>
-Русский <%= "текст" %>
+Русский <%= render :partial => 'test/utf8_partial_magic' %>
<%= "日".encoding %>
<%= @output_buffer.encoding %>
<%= __ENCODING__ %>
diff --git a/actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb b/actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb
new file mode 100644
index 0000000000..cb22692f9a
--- /dev/null
+++ b/actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb
@@ -0,0 +1,5 @@
+<%# encoding: utf-8 -%>
+Русский <%= render :partial => 'test/utf8_partial' %>
+<%= "日".encoding %>
+<%= @output_buffer.encoding %>
+<%= __ENCODING__ %>
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 647c673902..c9a50da418 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -283,7 +283,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
with_external_encoding Encoding::ASCII_8BIT do
result = @view.render(:file => "test/utf8_magic.html.erb", :layouts => "layouts/yield")
assert_equal Encoding::UTF_8, result.encoding
- assert_equal "Русский текст\nUTF-8\nUTF-8\nUTF-8\n", result
+ assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result
end
end
@@ -291,7 +291,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
with_external_encoding Encoding::UTF_8 do
result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
assert_equal Encoding::UTF_8, result.encoding
- assert_equal "Русский текст\nUTF-8\nUTF-8\nUTF-8\n", result
+ assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result
end
end
@@ -306,6 +306,17 @@ class LazyViewRenderTest < ActiveSupport::TestCase
end
end
+ def test_render_utf8_template_with_partial_with_incompatible_encoding
+ with_external_encoding Encoding::SJIS do
+ begin
+ result = @view.render(:file => "test/utf8_magic_with_bare_partial.html.erb", :layouts => "layouts/yield")
+ flunk 'Should have raised incompatible encoding error'
+ rescue ActionView::Template::Error => error
+ assert_match 'invalid byte sequence in Shift_JIS', error.original_exception.message
+ end
+ end
+ end
+
def with_external_encoding(encoding)
old, Encoding.default_external = Encoding.default_external, encoding
yield