Skip to content

Commit

Permalink
Fix the tests related with single quotes being escaped
Browse files Browse the repository at this point in the history
Closes #9144
Fixes #9145
  • Loading branch information
rafaelfranca committed Feb 2, 2013
1 parent 88331c5 commit c774a46
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
38 changes: 19 additions & 19 deletions actionpack/test/template/active_record_helper_test.rb
Expand Up @@ -213,15 +213,15 @@ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ]
end end


def test_error_for_block def test_error_for_block
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("post")
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1") assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1") assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1") assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
end end


def test_error_messages_for_escapes_html def test_error_messages_for_escapes_html
@dirty_post = DirtyPost.new @dirty_post = DirtyPost.new
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this dirty post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be &lt;em&gt;empty&lt;/em&gt;</li></ul></div>), error_messages_for("dirty_post") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this dirty post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be &lt;em&gt;empty&lt;/em&gt;</li></ul></div>), error_messages_for("dirty_post")
end end


def test_error_messages_for_handles_nil def test_error_messages_for_handles_nil
Expand All @@ -230,51 +230,51 @@ def test_error_messages_for_handles_nil


def test_error_message_on_escapes_html def test_error_message_on_escapes_html
@dirty_post = DirtyPost.new @dirty_post = DirtyPost.new
assert_dom_equal "<div class=\"formError\">can't be &lt;em&gt;empty&lt;/em&gt;</div>", error_message_on(:dirty_post, :author_name) assert_dom_equal "<div class=\"formError\">can&#39;t be &lt;em&gt;empty&lt;/em&gt;</div>", error_message_on(:dirty_post, :author_name)
end end


def test_error_message_on_handles_nil def test_error_message_on_handles_nil
assert_equal "", error_message_on("notthere", "notthere") assert_equal "", error_message_on("notthere", "notthere")
end end


def test_error_message_on def test_error_message_on
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name) assert_dom_equal "<div class=\"formError\">can&#39;t be empty</div>", error_message_on(:post, :author_name)
end end


def test_error_message_on_no_instance_variable def test_error_message_on_no_instance_variable
other_post = @post other_post = @post
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name) assert_dom_equal "<div class=\"formError\">can&#39;t be empty</div>", error_message_on(other_post, :author_name)
end end


def test_error_message_on_with_options_hash def test_error_message_on_with_options_hash
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') assert_dom_equal "<div class=\"differentError\">beforecan&#39;t be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after')
end end


def test_error_messages_for_many_objects def test_error_messages_for_many_objects
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li><li>User email can&#39;t be empty</li></ul></div>), error_messages_for("post", "user")


# reverse the order, error order changes and so does the title # reverse the order, error order changes and so does the title
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("user", "post")


# add the default to put post back in the title # add the default to put post back in the title
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post")


# symbols work as well # symbols work as well
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post) assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post)


# any default works too # any default works too
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")


# should space object name # should space object name
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon")


# hide header and explanation messages with nil or empty string # hide header and explanation messages with nil or empty string
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => nil, :message => "") assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => nil, :message => "")


# override header and explanation messages # override header and explanation messages
header_message = "Yikes! Some errors" header_message = "Yikes! Some errors"
message = "Please fix the following fields and resubmit:" message = "Please fix the following fields and resubmit:"
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message) assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message)
end end


def test_error_messages_for_non_instance_variable def test_error_messages_for_non_instance_variable
Expand All @@ -284,10 +284,10 @@ def test_error_messages_for_non_instance_variable
@post = nil @post = nil


#explicitly set object #explicitly set object
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post) assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("post", :object => actual_post)


#multiple objects #multiple objects
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post]) assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can&#39;t be empty</li><li>Author name can&#39;t be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post])


#nil object #nil object
assert_equal '', error_messages_for('user', :object => nil) assert_equal '', error_messages_for('user', :object => nil)
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/template/erb_util_test.rb
Expand Up @@ -8,7 +8,7 @@ class ErbUtilTest < Test::Unit::TestCase
assert_equal expected, html_escape(given) assert_equal expected, html_escape(given)
end end


unless given == '"' unless given == '"' || given == "'"
define_method "test_json_escape_#{expected.gsub /\W/, ''}" do define_method "test_json_escape_#{expected.gsub /\W/, ''}" do
assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given) assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given)
end end
Expand All @@ -26,10 +26,10 @@ def test_html_escape_passes_html_escpe_unmodified
assert_equal "<p>", escaped assert_equal "<p>", escaped
assert escaped.html_safe? assert escaped.html_safe?
end end

def test_rest_in_ascii def test_rest_in_ascii
(0..127).to_a.map(&:chr).each do |chr| (0..127).to_a.map(&:chr).each do |chr|
next if %w(& " < >).include?(chr) next if %w(& " < > ').include?(chr)
assert_equal chr, html_escape(chr) assert_equal chr, html_escape(chr)
end end
end end
Expand Down
20 changes: 10 additions & 10 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -743,7 +743,7 @@ def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to


assert_dom_equal expected, output_buffer assert_dom_equal expected, output_buffer
end end

def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement
@post.author = Author.new(321) @post.author = Author.new(321)


Expand All @@ -754,7 +754,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_o
concat af.text_field(:name) concat af.text_field(:name)
end end
end end

expected = '<form action="http://www.example.com" method="post">' + expected = '<form action="http://www.example.com" method="post">' +
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' + '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' + '<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
Expand Down Expand Up @@ -799,7 +799,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collecti
end end
end end
end end

expected = '<form action="http://www.example.com" method="post">' + expected = '<form action="http://www.example.com" method="post">' +
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' + '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' + '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
Expand Down Expand Up @@ -1195,8 +1195,8 @@ def test_default_form_builder_with_active_record_helpers
end end


expected = %(<form action='http://www.example.com' method='post'>) + expected = %(<form action='http://www.example.com' method='post'>) +
%(<div class='formError'>can't be empty</div>) + %(<div class='formError'>can&#39;t be empty</div>) +
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>) +
%(</form>) %(</form>)


assert_dom_equal expected, output_buffer assert_dom_equal expected, output_buffer
Expand All @@ -1213,14 +1213,14 @@ def test_default_form_builder_no_instance_variable
end end


expected = %(<form action='http://www.example.com' method='post'>) + expected = %(<form action='http://www.example.com' method='post'>) +
%(<div class='formError'>can't be empty</div>) + %(<div class='formError'>can&#39;t be empty</div>) +
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>) +
%(</form>) %(</form>)


assert_dom_equal expected, output_buffer assert_dom_equal expected, output_buffer


end end

def test_default_form_builder_without_object def test_default_form_builder_without_object


form_for(:post) do |f| form_for(:post) do |f|
Expand All @@ -1229,8 +1229,8 @@ def test_default_form_builder_without_object
end end


expected = %(<form action='http://www.example.com' method='post'>) + expected = %(<form action='http://www.example.com' method='post'>) +
%(<div class='formError'>can't be empty</div>) + %(<div class='formError'>can&#39;t be empty</div>) +
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can&#39;t be empty</li></ul></div>) +
%(</form>) %(</form>)


assert_dom_equal expected, output_buffer assert_dom_equal expected, output_buffer
Expand Down
6 changes: 5 additions & 1 deletion actionpack/test/template/text_helper_test.rb
Expand Up @@ -259,7 +259,6 @@ def test_auto_link_parsing
http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007 http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
http://www.mail-archive.com/rails@lists.rubyonrails.org/ http://www.mail-archive.com/rails@lists.rubyonrails.org/
http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1 http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
http://en.wikipedia.org/wiki/Texas_hold'em
https://www.google.com/doku.php?id=gps:resource:scs:start https://www.google.com/doku.php?id=gps:resource:scs:start
http://connect.oraclecorp.com/search?search[q]=green+france&search[type]=Group http://connect.oraclecorp.com/search?search[q]=green+france&search[type]=Group
http://of.openfoundry.org/projects/492/download#4th.Release.3 http://of.openfoundry.org/projects/492/download#4th.Release.3
Expand All @@ -269,6 +268,11 @@ def test_auto_link_parsing
urls.each do |url| urls.each do |url|
assert_equal generate_result(url), auto_link(url) assert_equal generate_result(url), auto_link(url)
end end

assert_equal(
%{<a href="http://en.wikipedia.org/wiki/Texas_hold'em">http://en.wikipedia.org/wiki/Texas_hold&#39;em</a>},
auto_link("http://en.wikipedia.org/wiki/Texas_hold'em")
)
end end


def generate_result(link_text, href = nil) def generate_result(link_text, href = nil)
Expand Down

0 comments on commit c774a46

Please sign in to comment.