aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2010-06-30 23:01:30 +0100
committerGonçalo Silva <goncalossilva@gmail.com>2010-06-30 23:01:30 +0100
commitd2c633ba0bfb7baacdee89a46d7d036d24c68817 (patch)
tree8f0974852b51597652e6ae73da26f3eb80fe878b /actionpack/test/template
parent92c0f17d6d2a958d3a6285b0e5408e9e0e7122e1 (diff)
parentc63cf7bf0db708fe46a929cf57649ab5a92034af (diff)
downloadrails-d2c633ba0bfb7baacdee89a46d7d036d24c68817.tar.gz
rails-d2c633ba0bfb7baacdee89a46d7d036d24c68817.tar.bz2
rails-d2c633ba0bfb7baacdee89a46d7d036d24c68817.zip
Merge branch 'master' of http://github.com/rails/rails
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/active_model_helper_test.rb7
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb22
-rw-r--r--actionpack/test/template/date_helper_test.rb27
-rw-r--r--actionpack/test/template/erb/form_for_test.rb2
-rw-r--r--actionpack/test/template/erb/tag_helper_test.rb4
-rw-r--r--actionpack/test/template/form_helper_test.rb412
-rw-r--r--actionpack/test/template/form_options_helper_test.rb30
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb56
-rw-r--r--actionpack/test/template/html-scanner/sanitizer_test.rb4
-rw-r--r--actionpack/test/template/log_subscriber_test.rb10
-rw-r--r--actionpack/test/template/tag_helper_test.rb4
-rw-r--r--actionpack/test/template/test_case_test.rb49
-rw-r--r--actionpack/test/template/text_helper_test.rb1
-rw-r--r--actionpack/test/template/url_helper_test.rb55
14 files changed, 421 insertions, 262 deletions
diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb
index b1705072c2..6ab244d178 100644
--- a/actionpack/test/template/active_model_helper_test.rb
+++ b/actionpack/test/template/active_model_helper_test.rb
@@ -39,6 +39,13 @@ class ActiveModelHelperTest < ActionView::TestCase
)
end
+ def test_hidden_field_does_not_render_errors
+ assert_dom_equal(
+ %(<input id="post_author_name" name="post[author_name]" type="hidden" value="" />),
+ hidden_field("post", "author_name")
+ )
+ end
+
def test_field_error_proc
old_proc = ActionView::Base.field_error_proc
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 633641514e..6d5e4893c4 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -44,7 +44,7 @@ class AssetTagHelperTest < ActionView::TestCase
@controller.request = @request
- ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :defaults => ['prototype', 'effects', 'dragdrop', 'controls', 'rails']
end
def url_for(*args)
@@ -256,19 +256,6 @@ class AssetTagHelperTest < ActionView::TestCase
assert javascript_include_tag("prototype").html_safe?
end
- def test_register_javascript_include_default
- ENV["RAILS_ASSET_ID"] = ""
- ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'bank'
- assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/rails.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
- end
-
- def test_register_javascript_include_default_mixed_defaults
- ENV["RAILS_ASSET_ID"] = ""
- ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'bank'
- ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'robber', '/elsewhere/cools.js'
- assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/rails.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
- end
-
def test_custom_javascript_expansions
ENV["RAILS_ASSET_ID"] = ""
ActionView::Helpers::AssetTagHelper::register_javascript_expansion :robbery => ["bank", "robber"]
@@ -286,6 +273,11 @@ class AssetTagHelperTest < ActionView::TestCase
assert_raise(ArgumentError) { javascript_include_tag('first', :monkey, 'last') }
end
+ def test_reset_javascript_expansions
+ ActionView::Helpers::AssetTagHelper.javascript_expansions.clear
+ assert_raise(ArgumentError) { javascript_include_tag(:defaults) }
+ end
+
def test_stylesheet_path
ENV["RAILS_ASSET_ID"] = ""
StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
@@ -923,7 +915,7 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase
@request = Struct.new(:protocol).new("gopher://")
@controller.request = @request
- ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
+ ActionView::Helpers::AssetTagHelper.javascript_expansions.clear
end
def url_for(options)
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
index 053fcc4d24..a1db49d4d0 100644
--- a/actionpack/test/template/date_helper_test.rb
+++ b/actionpack/test/template/date_helper_test.rb
@@ -882,6 +882,33 @@ class DateHelperTest < ActionView::TestCase
assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :start_year => 2003, :end_year => 2005, :prefix => "date[first]"})
end
+ def test_select_date_with_separator_and_discard_day
+ expected = %(<select id="date_first_year" name="date[first][year]">\n)
+ expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n)
+ expected << "</select>\n"
+
+ expected << " / "
+
+ expected << %(<select id="date_first_month" name="date[first][month]">\n)
+ expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n)
+ expected << "</select>\n"
+
+ expected << %(<input type="hidden" id="date_first_day" name="date[first][day]" value="1" />\n)
+
+ assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :discard_day => true, :start_year => 2003, :end_year => 2005, :prefix => "date[first]"})
+ end
+
+ def test_select_date_with_separator_discard_month_and_day
+ expected = %(<select id="date_first_year" name="date[first][year]">\n)
+ expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n)
+ expected << "</select>\n"
+
+ expected << %(<input type="hidden" id="date_first_month" name="date[first][month]" value="8" />\n)
+ expected << %(<input type="hidden" id="date_first_day" name="date[first][day]" value="16" />\n)
+
+ assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :discard_month => true, :discard_day => true, :start_year => 2003, :end_year => 2005, :prefix => "date[first]"})
+ end
+
def test_select_datetime
expected = %(<select id="date_first_year" name="date[first][year]">\n)
expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n)
diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb
index ec6e872735..e722b40a9a 100644
--- a/actionpack/test/template/erb/form_for_test.rb
+++ b/actionpack/test/template/erb/form_for_test.rb
@@ -5,7 +5,7 @@ module ERBTest
class TagHelperTest < BlockTestCase
test "form_for works" do
output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", ""
- assert_equal "<form action=\"/blah/update\" method=\"post\"></form>", output
+ assert_match %r{<form.*action="/blah/update".*method="post">.*</form>}, output
end
end
end
diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb
index 64a88bde1d..d073100986 100644
--- a/actionpack/test/template/erb/tag_helper_test.rb
+++ b/actionpack/test/template/erb/tag_helper_test.rb
@@ -28,8 +28,8 @@ module ERBTest
end
test "percent equals works with form tags" do
- expected_output = "<form action=\"foo\" method=\"post\">hello</form>"
- maybe_deprecated { assert_equal expected_output, render_content("form_tag('foo')", "<%= 'hello' %>") }
+ expected_output = %r{<form.*action="foo".*method="post">.*hello*</form>}
+ maybe_deprecated { assert_match expected_output, render_content("form_tag('foo')", "<%= 'hello' %>") }
end
test "percent equals works with fieldset tags" do
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 2f3869994c..4b9e41803f 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -188,6 +188,11 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, text_field("post", "title", :maxlength => 35, :size => nil)
end
+ def test_text_field_with_nil_value
+ expected = '<input id="post_title" name="post[title]" size="30" type="text" />'
+ assert_dom_equal expected, text_field("post", "title", :value => nil)
+ end
+
def test_text_field_doesnt_change_param_values
object_name = 'post[]'
expected = '<input id="post_123_title" name="post[123][title]" size="30" type="text" value="Hello World" />'
@@ -208,6 +213,11 @@ class FormHelperTest < ActionView::TestCase
hidden_field("post", "title")
end
+ def test_hidden_field_with_nil_value
+ expected = '<input id="post_title" name="post[title]" type="hidden" />'
+ assert_dom_equal expected, hidden_field("post", "title", :value => nil)
+ end
+
def test_text_field_with_options
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Something Else" />',
hidden_field("post", "title", :value => "Something Else")
@@ -300,6 +310,11 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_radio_button_with_negative_integer_value
+ assert_dom_equal('<input id="post_secret_-1" name="post[secret]" type="radio" value="-1" />',
+ radio_button("post", "secret", "-1"))
+ end
+
def test_radio_button_respects_passed_in_id
assert_dom_equal('<input checked="checked" id="foo" name="post[secret]" type="radio" value="1" />',
radio_button("post", "secret", "1", :id=>"foo")
@@ -568,7 +583,8 @@ class FormHelperTest < ActionView::TestCase
end
expected =
- "<form action='http://www.example.com' id='create-post' method='post'>" +
+ "<form accept-charset='UTF-8' action='http://www.example.com' id='create-post' method='post'>" +
+ snowman +
"<label for='post_title'>The Title</label>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
@@ -589,15 +605,14 @@ class FormHelperTest < ActionView::TestCase
concat f.submit('Create post')
end
- expected =
- "<form class='other_name_edit' method='post' action='/posts/123' id='create-post'>" +
- "<div style='margin:0;padding:0;display:inline'><input name='_method' value='put' type='hidden' /></div>" +
+ expected = whole_form("/posts/123", "create-post", "other_name_edit", :method => "put") do
"<label for='other_name_title'>Title</label>" +
"<input name='other_name[title]' size='30' id='other_name_title' value='Hello World' type='text' />" +
"<textarea name='other_name[body]' id='other_name_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='other_name[secret]' value='0' type='hidden' />" +
"<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />" +
- "<input name='commit' id='other_name_submit' value='Create post' type='submit' /></form>"
+ "<input name='commit' id='other_name_submit' value='Create post' type='submit' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -611,14 +626,12 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
- "<form action='http://www.example.com' id='create-post' method='post'>" +
- "<div style='margin:0;padding:0;display:inline'><input name='_method' type='hidden' value='put' /></div>" +
+ expected = whole_form("http://www.example.com", "create-post", nil, "put") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
- "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
- "</form>"
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -632,14 +645,31 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
- "<form action='http://www.example.com' id='create-post' method='post' data-remote='true'>" +
- "<div style='margin:0;padding:0;display:inline'><input name='_method' type='hidden' value='put' /></div>" +
+ expected = whole_form("http://www.example.com", "create-post", nil, :method => "put", :remote => true) do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
- "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
- "</form>"
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
+ def test_form_for_with_remote_without_html
+ assert_deprecated do
+ form_for(:post, @post, :remote => true) do |f|
+ concat f.text_field(:title)
+ concat f.text_area(:body)
+ concat f.check_box(:secret)
+ end
+ end
+
+ expected = whole_form("http://www.example.com", nil, nil, :remote => true) do
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
+ "<input name='post[secret]' type='hidden' value='0' />" +
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -651,13 +681,12 @@ class FormHelperTest < ActionView::TestCase
concat f.check_box(:secret)
end
- expected =
- "<form action='http://www.example.com' id='create-post' method='post'>" +
+ expected = whole_form("http://www.example.com", "create-post") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
- "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
- "</form>"
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -672,14 +701,13 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
- "<form action='http://www.example.com' method='post'>" +
+ expected = whole_form do
"<label for='post_123_title'>Title</label>" +
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
"<textarea name='post[123][body]' id='post_123_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[123][secret]' type='hidden' value='0' />" +
- "<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />" +
- "</form>"
+ "<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -693,13 +721,12 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
- "<form action='http://www.example.com' method='post'>" +
+ expected = whole_form do
"<input name='post[][title]' size='30' type='text' id='post__title' value='Hello World' />" +
"<textarea name='post[][body]' id='post__body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[][secret]' type='hidden' value='0' />" +
- "<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />" +
- "</form>"
+ "<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -714,9 +741,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='commit' id='post_submit' type='submit' value='Create Post' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='commit' id='post_submit' type='submit' value='Create Post' />"
+ end
+
assert_dom_equal expected, output_buffer
ensure
I18n.locale = old_locale
@@ -731,9 +759,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='commit' id='post_submit' type='submit' value='Confirm Post changes' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='commit' id='post_submit' type='submit' value='Confirm Post changes' />"
+ end
+
assert_dom_equal expected, output_buffer
ensure
I18n.locale = old_locale
@@ -746,9 +775,10 @@ class FormHelperTest < ActionView::TestCase
concat f.submit :class => "extra"
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='commit' class='extra' id='post_submit' type='submit' value='Save changes' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='commit' class='extra' id='post_submit' type='submit' value='Save changes' />"
+ end
+
assert_dom_equal expected, output_buffer
ensure
I18n.locale = old_locale
@@ -763,9 +793,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='commit' id='another_post_submit' type='submit' value='Update your Post' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='commit' id='another_post_submit' type='submit' value='Update your Post' />"
+ end
+
assert_dom_equal expected, output_buffer
ensure
I18n.locale = old_locale
@@ -780,9 +811,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[comment][title]' size='30' type='text' id='post_comment_title' value='Hello World' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[comment][title]' size='30' type='text' id='post_comment_title' value='Hello World' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -797,10 +828,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
- "<input name='post[123][comment][][name]' size='30' type='text' id='post_123_comment__name' value='new comment' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
+ "<input name='post[123][comment][][name]' size='30' type='text' id='post_123_comment__name' value='new comment' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -815,10 +846,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />" +
- "<input name='post[1][comment][1][name]' size='30' type='text' id='post_1_comment_1_name' value='new comment' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />" +
+ "<input name='post[1][comment][1][name]' size='30' type='text' id='post_1_comment_1_name' value='new comment' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -832,9 +863,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[1][comment][title]' size='30' type='text' id='post_1_comment_title' value='Hello World' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[1][comment][title]' size='30' type='text' id='post_1_comment_title' value='Hello World' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -848,9 +879,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[1][comment][5][title]' size='30' type='text' id='post_1_comment_5_title' value='Hello World' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[1][comment][5][title]' size='30' type='text' id='post_1_comment_5_title' value='Hello World' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -864,9 +895,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[123][comment][title]' size='30' type='text' id='post_123_comment_title' value='Hello World' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[123][comment][title]' size='30' type='text' id='post_123_comment_title' value='Hello World' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -880,9 +911,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -896,9 +927,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[123][comment][123][title]' size='30' type='text' id='post_123_comment_123_title' value='Hello World' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[123][comment][123][title]' size='30' type='text' id='post_123_comment_123_title' value='Hello World' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -917,12 +948,11 @@ class FormHelperTest < ActionView::TestCase
}
end
- expected = "<form action='http://www.example.com' method='post'>" +
- "<input name='post[123][comment][5][title]' size='30' type='text' id='post_123_comment_5_title' value='Hello World' />" +
- "</form>" +
- "<form action='http://www.example.com' method='post'>" +
- "<input name='post[1][comment][123][title]' size='30' type='text' id='post_1_comment_123_title' value='Hello World' />" +
- "</form>"
+ expected = whole_form do
+ "<input name='post[123][comment][5][title]' size='30' type='text' id='post_123_comment_5_title' value='Hello World' />"
+ end + whole_form do
+ "<input name='post[1][comment][123][title]' size='30' type='text' id='post_1_comment_123_title' value='Hello World' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -940,10 +970,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="new author" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="new author" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -971,11 +1001,11 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
- '<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
+ '<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -993,11 +1023,11 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<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_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
- '</form>'
+ expected = whole_form do
+ '<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_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1016,13 +1046,13 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
- '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
- '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1042,13 +1072,13 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<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_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
- '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
- '</form>'
+ expected = whole_form do
+ '<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_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1067,11 +1097,11 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="new comment" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="new comment" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1090,12 +1120,12 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
- '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1110,9 +1140,9 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1129,13 +1159,13 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
- '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
- '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1153,13 +1183,13 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
- '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
- '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1178,12 +1208,12 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
- '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
- '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />' +
- '</form>'
+ expected = whole_form do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />'
+ end
assert_dom_equal expected, output_buffer
assert_equal yielded_comments, @post.comments
@@ -1200,10 +1230,10 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" size="30" type="text" value="comment #321" />' +
- '<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />' +
- '</form>'
+ expected = whole_form do
+ '<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" size="30" type="text" value="comment #321" />' +
+ '<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1238,20 +1268,20 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = '<form action="http://www.example.com" method="post">' +
- '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
- '<input id="post_comments_attributes_0_relevances_attributes_0_value" name="post[comments_attributes][0][relevances_attributes][0][value]" size="30" type="text" value="commentrelevance #314" />' +
- '<input id="post_comments_attributes_0_relevances_attributes_0_id" name="post[comments_attributes][0][relevances_attributes][0][id]" type="hidden" value="314" />' +
- '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
- '<input id="post_tags_attributes_0_value" name="post[tags_attributes][0][value]" size="30" type="text" value="tag #123" />' +
- '<input id="post_tags_attributes_0_relevances_attributes_0_value" name="post[tags_attributes][0][relevances_attributes][0][value]" size="30" type="text" value="tagrelevance #3141" />' +
- '<input id="post_tags_attributes_0_relevances_attributes_0_id" name="post[tags_attributes][0][relevances_attributes][0][id]" type="hidden" value="3141" />' +
- '<input id="post_tags_attributes_0_id" name="post[tags_attributes][0][id]" type="hidden" value="123" />' +
- '<input id="post_tags_attributes_1_value" name="post[tags_attributes][1][value]" size="30" type="text" value="tag #456" />' +
- '<input id="post_tags_attributes_1_relevances_attributes_0_value" name="post[tags_attributes][1][relevances_attributes][0][value]" size="30" type="text" value="tagrelevance #31415" />' +
- '<input id="post_tags_attributes_1_relevances_attributes_0_id" name="post[tags_attributes][1][relevances_attributes][0][id]" type="hidden" value="31415" />' +
- '<input id="post_tags_attributes_1_id" name="post[tags_attributes][1][id]" type="hidden" value="456" />' +
- '</form>'
+ expected = whole_form do
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
+ '<input id="post_comments_attributes_0_relevances_attributes_0_value" name="post[comments_attributes][0][relevances_attributes][0][value]" size="30" type="text" value="commentrelevance #314" />' +
+ '<input id="post_comments_attributes_0_relevances_attributes_0_id" name="post[comments_attributes][0][relevances_attributes][0][id]" type="hidden" value="314" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
+ '<input id="post_tags_attributes_0_value" name="post[tags_attributes][0][value]" size="30" type="text" value="tag #123" />' +
+ '<input id="post_tags_attributes_0_relevances_attributes_0_value" name="post[tags_attributes][0][relevances_attributes][0][value]" size="30" type="text" value="tagrelevance #3141" />' +
+ '<input id="post_tags_attributes_0_relevances_attributes_0_id" name="post[tags_attributes][0][relevances_attributes][0][id]" type="hidden" value="3141" />' +
+ '<input id="post_tags_attributes_0_id" name="post[tags_attributes][0][id]" type="hidden" value="123" />' +
+ '<input id="post_tags_attributes_1_value" name="post[tags_attributes][1][value]" size="30" type="text" value="tag #456" />' +
+ '<input id="post_tags_attributes_1_relevances_attributes_0_value" name="post[tags_attributes][1][relevances_attributes][0][value]" size="30" type="text" value="tagrelevance #31415" />' +
+ '<input id="post_tags_attributes_1_relevances_attributes_0_id" name="post[tags_attributes][1][relevances_attributes][0][id]" type="hidden" value="31415" />' +
+ '<input id="post_tags_attributes_1_id" name="post[tags_attributes][1][id]" type="hidden" value="456" />'
+ end
assert_dom_equal expected, output_buffer
end
@@ -1391,7 +1421,8 @@ class FormHelperTest < ActionView::TestCase
end
expected =
- "<form action='http://www.example.com' id='create-post' method='post'>" +
+ "<form accept-charset='UTF-8' action='http://www.example.com' id='create-post' method='post'>" +
+ snowman +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='parent_post[secret]' type='hidden' value='0' />" +
@@ -1414,11 +1445,11 @@ class FormHelperTest < ActionView::TestCase
end
expected =
- "<form action='http://www.example.com' id='create-post' method='post'>" +
- "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
- "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
- "<input name='post[comment][name]' type='text' id='post_comment_name' value='new comment' size='30' />" +
- "</form>"
+ whole_form("http://www.example.com", "create-post") do
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
+ "<input name='post[comment][name]' type='text' id='post_comment_name' value='new comment' size='30' />"
+ end
assert_dom_equal expected, output_buffer
end
@@ -1442,16 +1473,42 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
- "<form action='http://www.example.com' method='post'>" +
- "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
- "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
- "<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>" +
- "</form>"
+ expected = whole_form do
+ "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
+ "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
+ "<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
+ end
assert_dom_equal expected, output_buffer
end
+ def snowman(method = nil)
+ txt = %{<div style="margin:0;padding:0;display:inline">}
+ txt << %{<input name="_snowman" type="hidden" value="&#9731;" />}
+ txt << %{<input name="_method" type="hidden" value="#{method}" />} if method
+ txt << %{</div>}
+ end
+
+ def form_text(action = "http://www.example.com", id = nil, html_class = nil, remote = nil)
+ txt = %{<form accept-charset="UTF-8" action="#{action}"}
+ txt << %{ data-remote="true"} if remote
+ txt << %{ class="#{html_class}"} if html_class
+ txt << %{ id="#{id}"} if id
+ txt << %{ method="post">}
+ end
+
+ def whole_form(action = "http://www.example.com", id = nil, html_class = nil, options = nil)
+ contents = block_given? ? yield : ""
+
+ if options.is_a?(Hash)
+ method, remote = options.values_at(:method, :remote)
+ else
+ method = options
+ end
+
+ form_text(action, id, html_class, remote) + snowman(method) + contents + "</form>"
+ end
+
def test_default_form_builder
old_default_form_builder, ActionView::Base.default_form_builder =
ActionView::Base.default_form_builder, LabelledFormBuilder
@@ -1464,12 +1521,11 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
- "<form action='http://www.example.com' method='post'>" +
+ expected = whole_form do
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
- "<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>" +
- "</form>"
+ "<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
+ end
assert_dom_equal expected, output_buffer
ensure
@@ -1542,7 +1598,7 @@ class FormHelperTest < ActionView::TestCase
assert_deprecated do
form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
end
- expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>"
+ expected = whole_form("http://www.example.com", "some_form", "some_class")
assert_dom_equal expected, output_buffer
end
@@ -1552,7 +1608,8 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end
end
- assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', output_buffer
+ assert_equal whole_form("http://www.otherdomain.com"), output_buffer
+ # assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', output_buffer
end
def test_form_for_with_hash_url_option
@@ -1569,14 +1626,15 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post, :url => @post) do |f| end
end
- expected = "<form action=\"/posts/123\" method=\"post\"></form>"
+ expected = whole_form("/posts/123")
+ # expected = "<form action=\"/posts/123\" method=\"post\"></form>"
assert_equal expected, output_buffer
end
def test_form_for_with_existing_object
form_for(@post) do |f| end
- expected = "<form action=\"/posts/123\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>"
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put")
assert_equal expected, output_buffer
end
@@ -1587,7 +1645,7 @@ class FormHelperTest < ActionView::TestCase
form_for(post) do |f| end
- expected = "<form action=\"/posts\" class=\"new_post\" id=\"new_post\" method=\"post\"></form>"
+ expected = whole_form("/posts", "new_post", "new_post")
assert_equal expected, output_buffer
end
@@ -1595,14 +1653,14 @@ class FormHelperTest < ActionView::TestCase
@comment.save
form_for([@post, @comment]) {}
- expected = %(<form action="#{comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div></form>)
+ expected = whole_form(comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put")
assert_dom_equal expected, output_buffer
end
def test_form_for_with_new_object_in_list
form_for([@post, @comment]) {}
- expected = %(<form action="#{comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
+ expected = whole_form(comments_path(@post), "new_comment", "new_comment")
assert_dom_equal expected, output_buffer
end
@@ -1610,21 +1668,21 @@ class FormHelperTest < ActionView::TestCase
@comment.save
form_for([:admin, @post, @comment]) {}
- expected = %(<form action="#{admin_comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div></form>)
+ expected = whole_form(admin_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put")
assert_dom_equal expected, output_buffer
end
def test_form_for_with_new_object_and_namespace_in_list
form_for([:admin, @post, @comment]) {}
- expected = %(<form action="#{admin_comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
+ expected = whole_form(admin_comments_path(@post), "new_comment", "new_comment")
assert_dom_equal expected, output_buffer
end
def test_form_for_with_existing_object_and_custom_url
form_for(@post, :url => "/super_posts") do |f| end
- expected = "<form action=\"/super_posts\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>"
+ expected = whole_form("/super_posts", "edit_post_123", "edit_post", "put")
assert_equal expected, output_buffer
end
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 19b73aa810..65b5f5ccc1 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -177,17 +177,16 @@ class FormOptionsHelperTest < ActionView::TestCase
end
def test_option_groups_from_collection_for_select
- @continents = [
- Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
- Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
- ]
-
assert_dom_equal(
"<optgroup label=\"&lt;Africa&gt;\"><option value=\"&lt;sa&gt;\">&lt;South Africa&gt;</option>\n<option value=\"so\">Somalia</option></optgroup><optgroup label=\"Europe\"><option value=\"dk\" selected=\"selected\">Denmark</option>\n<option value=\"ie\">Ireland</option></optgroup>",
- option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk")
+ option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk")
)
end
+ def test_option_groups_from_collection_for_select_returns_html_safe_string
+ assert option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk").html_safe?
+ end
+
def test_grouped_options_for_select_with_array
assert_dom_equal(
"<optgroup label=\"North America\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>",
@@ -824,31 +823,21 @@ class FormOptionsHelperTest < ActionView::TestCase
end
def test_grouped_collection_select
- @continents = [
- Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
- Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
- ]
-
@post = Post.new
@post.origin = 'dk'
assert_dom_equal(
%Q{<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk" selected="selected">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
- grouped_collection_select("post", "origin", @continents, :countries, :continent_name, :country_id, :country_name)
+ grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name)
)
end
def test_grouped_collection_select_under_fields_for
- @continents = [
- Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
- Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
- ]
-
@post = Post.new
@post.origin = 'dk'
output_buffer = fields_for :post, @post do |f|
- concat f.grouped_collection_select("origin", @continents, :countries, :continent_name, :country_id, :country_name)
+ concat f.grouped_collection_select("origin", dummy_continents, :countries, :continent_name, :country_id, :country_name)
end
assert_dom_equal(
@@ -864,4 +853,9 @@ class FormOptionsHelperTest < ActionView::TestCase
Post.new("Babe went home", "Babe", "To a little house", "shh!"),
Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ]
end
+
+ def dummy_continents
+ [ Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
+ Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] ) ]
+ end
end
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index b75863bb6a..8a0f352bc0 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -8,6 +8,36 @@ class FormTagHelperTest < ActionView::TestCase
@controller = BasicController.new
end
+ def snowman(options = {})
+ method = options[:method]
+
+ txt = %{<div style="margin:0;padding:0;display:inline">}
+ txt << %{<input name="_snowman" type="hidden" value="&#9731;" />}
+ txt << %{<input name="_method" type="hidden" value="#{method}" />} if method
+ txt << %{</div>}
+ end
+
+ def form_text(action = "http://www.example.com", options = {})
+ remote, enctype, html_class, id = options.values_at(:remote, :enctype, :html_class, :id)
+
+ txt = %{<form accept-charset="UTF-8" action="#{action}"}
+ txt << %{ enctype="multipart/form-data"} if enctype
+ txt << %{ data-remote="true"} if remote
+ txt << %{ class="#{html_class}"} if html_class
+ txt << %{ id="#{id}"} if id
+ txt << %{ method="post">}
+ end
+
+ def whole_form(action = "http://www.example.com", options = {})
+ out = form_text(action, options) + snowman(options)
+
+ if block_given?
+ out << yield << "</form>"
+ end
+
+ out
+ end
+
def url_for(options)
if options.is_a?(Hash)
"http://www.example.com"
@@ -31,51 +61,57 @@ class FormTagHelperTest < ActionView::TestCase
def test_form_tag
actual = form_tag
- expected = %(<form action="http://www.example.com" method="post">)
+ expected = whole_form
assert_dom_equal expected, actual
end
def test_form_tag_multipart
actual = form_tag({}, { 'multipart' => true })
- expected = %(<form action="http://www.example.com" enctype="multipart/form-data" method="post">)
+ expected = whole_form("http://www.example.com", :enctype => true)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_put
actual = form_tag({}, { :method => :put })
- expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0;display:inline'><input type="hidden" name="_method" value="put" /></div>)
+ expected = whole_form("http://www.example.com", :method => :put)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_delete
actual = form_tag({}, { :method => :delete })
- expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0;display:inline'><input type="hidden" name="_method" value="delete" /></div>)
+
+ expected = whole_form("http://www.example.com", :method => :delete)
assert_dom_equal expected, actual
end
def test_form_tag_with_remote
actual = form_tag({}, :remote => true)
- expected = %(<form action="http://www.example.com" method="post" data-remote="true">)
+
+ expected = whole_form("http://www.example.com", :remote => true)
assert_dom_equal expected, actual
end
def test_form_tag_with_remote_false
actual = form_tag({}, :remote => false)
- expected = %(<form action="http://www.example.com" method="post">)
+
+ expected = whole_form
assert_dom_equal expected, actual
end
def test_form_tag_with_block_in_erb
- output_buffer = form_tag("http://example.com") { concat "Hello world!" }
+ output_buffer = form_tag("http://www.example.com") { concat "Hello world!" }
- expected = %(<form action="http://example.com" method="post">Hello world!</form>)
+ expected = whole_form { "Hello world!" }
assert_dom_equal expected, output_buffer
end
def test_form_tag_with_block_and_method_in_erb
- output_buffer = form_tag("http://example.com", :method => :put) { concat "Hello world!" }
+ output_buffer = form_tag("http://www.example.com", :method => :put) { concat "Hello world!" }
+
+ expected = whole_form("http://www.example.com", :method => "put") do
+ "Hello world!"
+ end
- expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0;display:inline'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
assert_dom_equal expected, output_buffer
end
diff --git a/actionpack/test/template/html-scanner/sanitizer_test.rb b/actionpack/test/template/html-scanner/sanitizer_test.rb
index a6e760b0b6..c9edde8892 100644
--- a/actionpack/test/template/html-scanner/sanitizer_test.rb
+++ b/actionpack/test/template/html-scanner/sanitizer_test.rb
@@ -257,6 +257,10 @@ class SanitizerTest < ActionController::TestCase
assert_sanitized %{<a href=\"http://www.domain.com?var1=1&amp;var2=2\">my link</a>}
end
+ def test_should_sanitize_neverending_attribute
+ assert_sanitized "<span class=\"\\", "<span class=\"\\\">"
+ end
+
protected
def assert_sanitized(input, expected = nil)
@sanitizer ||= HTML::WhiteListSanitizer.new
diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb
index 5076dfa70f..eb1e548672 100644
--- a/actionpack/test/template/log_subscriber_test.rb
+++ b/actionpack/test/template/log_subscriber_test.rb
@@ -1,22 +1,22 @@
require "abstract_unit"
-require "rails/log_subscriber/test_helper"
-require "action_view/railties/log_subscriber"
+require "active_support/log_subscriber/test_helper"
+require "action_view/log_subscriber"
require "controller/fake_models"
class AVLogSubscriberTest < ActiveSupport::TestCase
- include Rails::LogSubscriber::TestHelper
+ include ActiveSupport::LogSubscriber::TestHelper
def setup
super
@old_logger = ActionController::Base.logger
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
- Rails::LogSubscriber.add(:action_view, ActionView::Railties::LogSubscriber.new)
+ ActionView::LogSubscriber.attach_to :action_view
end
def teardown
super
- Rails::LogSubscriber.log_subscribers.clear
+ ActiveSupport::LogSubscriber.log_subscribers.clear
ActionController::Base.logger = @old_logger
end
diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb
index ec5fe3d1d7..507cdca8d0 100644
--- a/actionpack/test/template/tag_helper_test.rb
+++ b/actionpack/test/template/tag_helper_test.rb
@@ -95,9 +95,9 @@ class TagHelperTest < ActionView::TestCase
assert_equal '1 &lt; 2 &amp; 3', escape_once('1 < 2 &amp; 3')
end
- def test_double_escaping_attributes
+ def test_tag_honors_html_safe_for_param_values
['1&amp;2', '1 &lt; 2', '&#8220;test&#8220;'].each do |escaped|
- assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped)
+ assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped.html_safe)
end
end
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index 9b50ea8a42..a0c46f8a59 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -37,8 +37,12 @@ module ActionView
include SharedTests
test_case = self
- test "memoizes the _view" do
- assert_same _view, _view
+ test "memoizes the view" do
+ assert_same view, view
+ end
+
+ test "exposes view as _view for backwards compatibility" do
+ assert_same _view, view
end
test "works without testing a helper module" do
@@ -61,13 +65,13 @@ module ActionView
end
test "delegates notice to request.flash" do
- _view.request.flash.expects(:notice).with("this message")
- _view.notice("this message")
+ view.request.flash.expects(:notice).with("this message")
+ view.notice("this message")
end
test "delegates alert to request.flash" do
- _view.request.flash.expects(:alert).with("this message")
- _view.alert("this message")
+ view.request.flash.expects(:alert).with("this message")
+ view.alert("this message")
end
end
@@ -136,7 +140,7 @@ module ActionView
helper HelperThatInvokesProtectAgainstForgery
test "protect_from_forgery? in any helpers returns false" do
- assert !_view.help_me
+ assert !view.help_me
end
end
@@ -200,6 +204,15 @@ module ActionView
assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end
+ test "is able to render partials from templates and also use instance variables after view has been referenced" do
+ @controller.controller_path = "test"
+
+ view
+
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
+ assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
+ end
+
end
class AssertionsTest < ActionView::TestCase
@@ -218,4 +231,26 @@ module ActionView
end
end
end
+
+ class RenderTemplateTest < ActionView::TestCase
+ test "supports specifying partials" do
+ controller.controller_path = "test"
+ render(:template => "test/calling_partial_with_layout")
+ assert_template :partial => "_partial_for_use_in_layout"
+ end
+
+ test "supports specifying locals (passing)" do
+ controller.controller_path = "test"
+ render(:template => "test/calling_partial_with_layout")
+ assert_template :partial => "_partial_for_use_in_layout", :locals => { :name => "David" }
+ end
+
+ test "supports specifying locals (failing)" do
+ controller.controller_path = "test"
+ render(:template => "test/calling_partial_with_layout")
+ assert_raise ActiveSupport::TestCase::Assertion, /Somebody else.*David/m do
+ assert_template :partial => "_partial_for_use_in_layout", :locals => { :name => "Somebody Else" }
+ end
+ end
+ end
end
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index d173c5be0a..d22b9fe406 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -435,6 +435,7 @@ class TextHelperTest < ActionView::TestCase
z39_scheme = 'z39.50r://host:696/db'
chrome_scheme = 'chrome://package/section/path'
view_source = 'view-source:http://en.wikipedia.org/wiki/URI_scheme'
+ assert_equal generate_result(file_scheme), auto_link(file_scheme)
assert_equal generate_result(z39_scheme), auto_link(z39_scheme)
assert_equal generate_result(chrome_scheme), auto_link(chrome_scheme)
assert_equal generate_result(view_source), auto_link(view_source)
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 299d6dd5bd..765beebfa3 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -40,19 +40,8 @@ class UrlHelperTest < ActiveSupport::TestCase
end
alias url_hash hash_for
- def test_url_for_escapes_urls
+ def test_url_for_does_not_escape_urls
assert_equal "/?a=b&c=d", url_for(abcd)
- assert_equal "/?a=b&amp;c=d", url_for(abcd(:escape => true))
- assert_equal "/?a=b&c=d", url_for(abcd(:escape => false))
- end
-
- def test_url_for_escaping_is_safety_aware
- assert url_for(abcd(:escape => true)).html_safe?, "escaped urls should be html_safe?"
- assert !url_for(abcd(:escape => false)).html_safe?, "non-escaped urls should not be html_safe?"
- end
-
- def test_url_for_escapes_url_once
- assert_equal "/?a=b&amp;c=d", url_for("/?a=b&amp;c=d")
end
def test_url_for_with_back
@@ -67,11 +56,6 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_equal 'javascript:history.back()', url_for(:back)
end
- def test_url_for_from_hash_doesnt_escape_ampersand
- path = url_for(hash_for(:foo => :bar, :baz => :quux))
- assert_equal '/?baz=quux&foo=bar', sort_query_string_params(path)
- end
-
# todo: missing test cases
def test_button_to_with_straight_url
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com")
@@ -81,8 +65,8 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&q2=v2")
end
- def test_button_to_with_escaped_query
- assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&amp;q2=v2")
+ def test_button_to_with_html_safe_URL
+ assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&amp;q2=v2".html_safe)
end
def test_button_to_with_query_and_no_name
@@ -151,13 +135,12 @@ class UrlHelperTest < ActiveSupport::TestCase
def test_link_tag_with_query
expected = %{<a href="http://www.example.com?q1=v1&amp;q2=v2">Hello</a>}
- assert_dom_equal expected, link_to("Hello", "http://www.example.com?q1=v1&amp;q2=v2")
+ assert_dom_equal expected, link_to("Hello", "http://www.example.com?q1=v1&q2=v2")
end
def test_link_tag_with_query_and_no_name
- link = link_to(nil, "http://www.example.com?q1=v1&amp;q2=v2")
expected = %{<a href="http://www.example.com?q1=v1&amp;q2=v2">http://www.example.com?q1=v1&amp;q2=v2</a>}
- assert_dom_equal expected, link
+ assert_dom_equal expected, link_to(nil, "http://www.example.com?q1=v1&q2=v2")
end
def test_link_tag_with_back
@@ -312,7 +295,7 @@ class UrlHelperTest < ActiveSupport::TestCase
@request = request_for_url("/?order=desc&page=1")
assert current_page?(hash_for(:order => "desc", :page => "1"))
- assert current_page?("http://www.example.com/?order=desc&amp;page=1")
+ assert current_page?("http://www.example.com/?order=desc&page=1")
end
def test_link_unless_current
@@ -345,7 +328,7 @@ class UrlHelperTest < ActiveSupport::TestCase
link_to_unless_current("Showing", "http://www.example.com/?order=asc")
@request = request_for_url("/?order=desc")
- assert_equal %{<a href="/?order=desc&page=2\">Showing</a>},
+ assert_equal %{<a href="/?order=desc&amp;page=2\">Showing</a>},
link_to_unless_current("Showing", hash_for(:order => "desc", :page => 2))
assert_equal %{<a href="http://www.example.com/?order=desc&amp;page=2">Showing</a>},
link_to_unless_current("Showing", "http://www.example.com/?order=desc&page=2")
@@ -415,7 +398,7 @@ class UrlHelperTest < ActiveSupport::TestCase
private
def sort_query_string_params(uri)
path, qs = uri.split('?')
- qs = qs.split('&').sort.join('&') if qs
+ qs = qs.split('&amp;').sort.join('&amp;') if qs
qs ? "#{path}?#{qs}" : path
end
end
@@ -429,6 +412,10 @@ class UrlHelperControllerTest < ActionController::TestCase
map.connect ":controller/:action/:id"
# match "/:controller(/:action(/:id))"
+
+ match 'url_helper_controller_test/url_helper/normalize_recall_params',
+ :to => UrlHelperController.action(:normalize_recall),
+ :as => :normalize_recall_params
end
def show_url_for
@@ -447,6 +434,14 @@ class UrlHelperControllerTest < ActionController::TestCase
render :inline => '<%= url_for(nil) %>'
end
+ def normalize_recall_params
+ render :inline => '<%= normalize_recall_params_path %>'
+ end
+
+ def recall_params_not_changed
+ render :inline => '<%= url_for(:action => :show_url_for) %>'
+ end
+
def rescue_action(e) raise e end
end
@@ -488,6 +483,16 @@ class UrlHelperControllerTest < ActionController::TestCase
get :show_named_route, :kind => 'url'
assert_equal 'http://testtwo.host/url_helper_controller_test/url_helper/show_named_route', @response.body
end
+
+ def test_recall_params_should_be_normalized_when_using_block_route
+ get :normalize_recall_params
+ assert_equal '/url_helper_controller_test/url_helper/normalize_recall_params', @response.body
+ end
+
+ def test_recall_params_should_not_be_changed_when_using_normal_route
+ get :recall_params_not_changed
+ assert_equal '/url_helper_controller_test/url_helper/show_url_for', @response.body
+ end
end
class TasksController < ActionController::Base