diff options
author | Xavier Noria <fxn@hashref.com> | 2010-04-06 15:38:05 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-04-06 15:38:05 -0700 |
commit | 4c4fd1a60ff1c060e76e9ee540074756510f53ea (patch) | |
tree | 77da1c66c127e36c8b00825b676d9267a9ef4cd6 /actionpack/test/template | |
parent | 03cb74b9461293b96ae0add8ff5efda132dabba0 (diff) | |
parent | af130575249571464ec984efa84fcea1267e8cf8 (diff) | |
download | rails-4c4fd1a60ff1c060e76e9ee540074756510f53ea.tar.gz rails-4c4fd1a60ff1c060e76e9ee540074756510f53ea.tar.bz2 rails-4c4fd1a60ff1c060e76e9ee540074756510f53ea.zip |
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/erb/form_for_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 553 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 30 |
3 files changed, 378 insertions, 207 deletions
diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb index 482dbb0287..ec6e872735 100644 --- a/actionpack/test/template/erb/form_for_test.rb +++ b/actionpack/test/template/erb/form_for_test.rb @@ -8,4 +8,4 @@ module ERBTest assert_equal "<form action=\"/blah/update\" method=\"post\"></form>", output end end -end
\ No newline at end of file +end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 4af38e52dd..64dfbde0b0 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -349,6 +349,36 @@ class FormHelperTest < ActionView::TestCase ) end + def test_search_field + expected = %{<input id="contact_notes_query" size="30" name="contact[notes_query]" type="search" />} + assert_dom_equal(expected, search_field("contact", "notes_query")) + end + + def test_telephone_field + expected = %{<input id="user_cell" size="30" name="user[cell]" type="tel" />} + assert_dom_equal(expected, telephone_field("user", "cell")) + end + + def test_url_field + expected = %{<input id="user_homepage" size="30" name="user[homepage]" type="url" />} + assert_dom_equal(expected, url_field("user", "homepage")) + end + + def test_email_field + expected = %{<input id="user_address" size="30" name="user[address]" type="email" />} + assert_dom_equal(expected, email_field("user", "address")) + end + + def test_number_field + expected = %{<input name="order[quantity]" size="30" max="9" id="order_quantity" type="number" min="1" />} + assert_dom_equal(expected, number_field("order", "quantity", :in => 1...10)) + end + + def test_range_input + expected = %{<input name="hifi[volume]" step="0.1" size="30" max="11" id="hifi_volume" type="range" min="0" />} + assert_dom_equal(expected, range_field("hifi", "volume", :in => 0..11, :step => 0.1)) + end + def test_explicit_name assert_dom_equal( '<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess") @@ -416,12 +446,14 @@ class FormHelperTest < ActionView::TestCase end def test_form_for - form_for(:post, @post, :html => { :id => 'create-post' }) do |f| - concat f.label(:title) - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) - concat f.submit('Create post') + assert_deprecated do + form_for(:post, @post, :html => { :id => 'create-post' }) do |f| + concat f.label(:title) + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + concat f.submit('Create post') + end end expected = @@ -437,11 +469,35 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - def test_form_for_with_method - form_for(:post, @post, :html => { :id => 'create-post', :method => :put }) do |f| + def test_form_for_with_symbol_object_name + form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f| + concat f.label(:title) concat f.text_field(:title) concat f.text_area(:body) concat f.check_box(:secret) + 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>" + + "<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>" + + assert_dom_equal expected, output_buffer + end + + def test_form_for_with_method + assert_deprecated do + form_for(:post, @post, :html => { :id => 'create-post', :method => :put }) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end end expected = @@ -457,10 +513,12 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_remote - form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) + assert_deprecated do + form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end end expected = @@ -494,16 +552,18 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_index - form_for("post[]", @post) do |f| - concat f.label(:title) - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) + assert_deprecated do + form_for("post[]", @post) do |f| + concat f.label(:title) + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end end expected = "<form action='http://www.example.com' method='post'>" + - "<label for=\"post_123_title\">Title</label>" + + "<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' />" + @@ -514,10 +574,12 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_nil_index_option_override - form_for("post[]", @post, :index => nil) do |f| - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) + assert_deprecated do + form_for("post[]", @post, :index => nil) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end end expected = @@ -535,8 +597,10 @@ class FormHelperTest < ActionView::TestCase old_locale, I18n.locale = I18n.locale, :submit @post.persisted = false - form_for(:post, @post) do |f| - concat f.submit + assert_deprecated do + form_for(:post, @post) do |f| + concat f.submit + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -550,8 +614,10 @@ class FormHelperTest < ActionView::TestCase def test_submit_with_object_as_existing_record_and_locale_strings old_locale, I18n.locale = I18n.locale, :submit - form_for(:post, @post) do |f| - concat f.submit + assert_deprecated do + form_for(:post, @post) do |f| + concat f.submit + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -580,8 +646,10 @@ class FormHelperTest < ActionView::TestCase def test_submit_with_object_and_nested_lookup old_locale, I18n.locale = I18n.locale, :submit - form_for(:another_post, @post) do |f| - concat f.submit + assert_deprecated do + form_for(:another_post, @post) do |f| + concat f.submit + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -593,10 +661,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for - form_for(:post, @post) do |f| - concat f.fields_for(:comment, @post) { |c| - concat c.text_field(:title) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.fields_for(:comment, @post) { |c| + concat c.text_field(:title) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -607,11 +677,13 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_nested_collections - form_for('post[]', @post) do |f| - concat f.text_field(:title) - concat f.fields_for('comment[]', @comment) { |c| - concat c.text_field(:name) - } + assert_deprecated do + form_for('post[]', @post) do |f| + concat f.text_field(:title) + concat f.fields_for('comment[]', @comment) { |c| + concat c.text_field(:name) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -623,11 +695,13 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_index_and_parent_fields - form_for('post', @post, :index => 1) do |c| - concat c.text_field(:title) - concat c.fields_for('comment', @comment, :index => 1) { |r| - concat r.text_field(:name) - } + assert_deprecated do + form_for('post', @post, :index => 1) do |c| + concat c.text_field(:title) + concat c.fields_for('comment', @comment, :index => 1) { |r| + concat r.text_field(:name) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -639,10 +713,12 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_index_and_nested_fields_for - output_buffer = form_for(:post, @post, :index => 1) do |f| - concat f.fields_for(:comment, @post) { |c| - concat c.text_field(:title) - } + assert_deprecated do + output_buffer = form_for(:post, @post, :index => 1) do |f| + concat f.fields_for(:comment, @post) { |c| + concat c.text_field(:title) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -653,10 +729,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_index_on_both - form_for(:post, @post, :index => 1) do |f| - concat f.fields_for(:comment, @post, :index => 5) { |c| - concat c.text_field(:title) - } + assert_deprecated do + form_for(:post, @post, :index => 1) do |f| + concat f.fields_for(:comment, @post, :index => 5) { |c| + concat c.text_field(:title) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -667,10 +745,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_auto_index - form_for("post[]", @post) do |f| - concat f.fields_for(:comment, @post) { |c| - concat c.text_field(:title) - } + assert_deprecated do + form_for("post[]", @post) do |f| + concat f.fields_for(:comment, @post) { |c| + concat c.text_field(:title) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -681,10 +761,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_index_radio_button - form_for(:post, @post) do |f| - concat f.fields_for(:comment, @post, :index => 5) { |c| - concat c.radio_button(:title, "hello") - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.fields_for(:comment, @post, :index => 5) { |c| + concat c.radio_button(:title, "hello") + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -695,10 +777,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_auto_index_on_both - form_for("post[]", @post) do |f| - concat f.fields_for("comment[]", @post) { |c| - concat c.text_field(:title) - } + assert_deprecated do + form_for("post[]", @post) do |f| + concat f.fields_for("comment[]", @post) { |c| + concat c.text_field(:title) + } + end end expected = "<form action='http://www.example.com' method='post'>" + @@ -709,36 +793,40 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_index_and_auto_index - output_buffer = form_for("post[]", @post) do |f| - concat f.fields_for(:comment, @post, :index => 5) { |c| - concat c.text_field(:title) - } - end + assert_deprecated do + output_buffer = form_for("post[]", @post) do |f| + concat f.fields_for(:comment, @post, :index => 5) { |c| + concat c.text_field(:title) + } + end - output_buffer << form_for(:post, @post, :index => 1) do |f| - concat f.fields_for("comment[]", @post) { |c| - concat c.text_field(:title) - } - end + output_buffer << form_for(:post, @post, :index => 1) do |f| + concat f.fields_for("comment[]", @post) { |c| + concat c.text_field(:title) + } + 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 = "<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>" - assert_dom_equal expected, output_buffer + assert_dom_equal expected, output_buffer + end end def test_nested_fields_for_with_a_new_record_on_a_nested_attributes_one_to_one_association @post.author = Author.new - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.fields_for(:author) { |af| - concat af.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.fields_for(:author) { |af| + concat af.text_field(:name) + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -750,10 +838,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_explicitly_passed_object_on_a_nested_attributes_one_to_one_association - form_for(:post, @post) do |f| - f.fields_for(:author, Author.new(123)) do |af| - assert_not_nil af.object - assert_equal 123, af.object.id + assert_deprecated do + form_for(:post, @post) do |f| + f.fields_for(:author, Author.new(123)) do |af| + assert_not_nil af.object + assert_equal 123, af.object.id + end end end end @@ -761,11 +851,13 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association @post.author = Author.new(321) - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.fields_for(:author) { |af| - concat af.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.fields_for(:author) { |af| + concat af.text_field(:name) + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -780,12 +872,14 @@ class FormHelperTest < ActionView::TestCase 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) - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.fields_for(:author) { |af| - concat af.hidden_field(:id) - concat af.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.fields_for(:author) { |af| + concat af.hidden_field(:id) + concat af.text_field(:name) + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -800,12 +894,14 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association @post.comments = Array.new(2) { |id| Comment.new(id + 1) } - form_for(:post, @post) do |f| - concat f.text_field(:title) - @post.comments.each do |comment| - concat f.fields_for(:comments, comment) { |cf| - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + concat f.fields_for(:comments, comment) { |cf| + concat cf.text_field(:name) + } + end end end @@ -823,13 +919,15 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_explicit_hidden_field_placement @post.comments = Array.new(2) { |id| Comment.new(id + 1) } - form_for(:post, @post) do |f| - concat f.text_field(:title) - @post.comments.each do |comment| - concat f.fields_for(:comments, comment) { |cf| - concat cf.hidden_field(:id) - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + concat f.fields_for(:comments, comment) { |cf| + concat cf.hidden_field(:id) + concat cf.text_field(:name) + } + end end end @@ -847,12 +945,14 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_new_records_on_a_nested_attributes_collection_association @post.comments = [Comment.new, Comment.new] - form_for(:post, @post) do |f| - concat f.text_field(:title) - @post.comments.each do |comment| - concat f.fields_for(:comments, comment) { |cf| - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + concat f.fields_for(:comments, comment) { |cf| + concat cf.text_field(:name) + } + end end end @@ -868,12 +968,14 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_collection_association @post.comments = [Comment.new(321), Comment.new] - form_for(:post, @post) do |f| - concat f.text_field(:title) - @post.comments.each do |comment| - concat f.fields_for(:comments, comment) { |cf| - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + concat f.fields_for(:comments, comment) { |cf| + concat cf.text_field(:name) + } + end end end @@ -888,10 +990,12 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_an_empty_supplied_attributes_collection - form_for(:post, @post) do |f| - concat f.text_field(:title) - f.fields_for(:comments, []) do |cf| - concat cf.text_field(:name) + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:comments, []) do |cf| + concat cf.text_field(:name) + end end end @@ -905,11 +1009,13 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection @post.comments = Array.new(2) { |id| Comment.new(id + 1) } - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.fields_for(:comments, @post.comments) { |cf| - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.fields_for(:comments, @post.comments) { |cf| + concat cf.text_field(:name) + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -927,11 +1033,13 @@ class FormHelperTest < ActionView::TestCase comments = Array.new(2) { |id| Comment.new(id + 1) } @post.comments = [] - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.fields_for(:comments, comments) { |cf| - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.fields_for(:comments, comments) { |cf| + concat cf.text_field(:name) + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -949,12 +1057,14 @@ class FormHelperTest < ActionView::TestCase @post.comments = [Comment.new(321), Comment.new] yielded_comments = [] - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.fields_for(:comments) { |cf| - concat cf.text_field(:name) - yielded_comments << cf.object - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.fields_for(:comments) { |cf| + concat cf.text_field(:name) + yielded_comments << cf.object + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -971,10 +1081,12 @@ class FormHelperTest < ActionView::TestCase def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association @post.comments = [] - form_for(:post, @post) do |f| - concat f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf| - concat cf.text_field(:name) - } + assert_deprecated do + form_for(:post, @post) do |f| + concat f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf| + concat cf.text_field(:name) + } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -991,25 +1103,28 @@ class FormHelperTest < ActionView::TestCase @post.comments[0].relevances = [] @post.tags[0].relevances = [] @post.tags[1].relevances = [] - form_for(:post, @post) do |f| - concat f.fields_for(:comments, @post.comments[0]) { |cf| - concat cf.text_field(:name) - concat cf.fields_for(:relevances, CommentRelevance.new(314)) { |crf| - concat crf.text_field(:value) + + assert_deprecated do + form_for(:post, @post) do |f| + concat f.fields_for(:comments, @post.comments[0]) { |cf| + concat cf.text_field(:name) + concat cf.fields_for(:relevances, CommentRelevance.new(314)) { |crf| + concat crf.text_field(:value) + } } - } - concat f.fields_for(:tags, @post.tags[0]) { |tf| - concat tf.text_field(:value) - concat tf.fields_for(:relevances, TagRelevance.new(3141)) { |trf| - concat trf.text_field(:value) + concat f.fields_for(:tags, @post.tags[0]) { |tf| + concat tf.text_field(:value) + concat tf.fields_for(:relevances, TagRelevance.new(3141)) { |trf| + concat trf.text_field(:value) + } } - } - concat f.fields_for('tags', @post.tags[1]) { |tf| - concat tf.text_field(:value) - concat tf.fields_for(:relevances, TagRelevance.new(31415)) { |trf| - concat trf.text_field(:value) + concat f.fields_for('tags', @post.tags[1]) { |tf| + concat tf.text_field(:value) + concat tf.fields_for(:relevances, TagRelevance.new(31415)) { |trf| + concat trf.text_field(:value) + } } - } + end end expected = '<form action="http://www.example.com" method="post">' + @@ -1153,13 +1268,15 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_and_fields_for - form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| - concat post_form.text_field(:title) - concat post_form.text_area(:body) + assert_deprecated do + form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| + concat post_form.text_field(:title) + concat post_form.text_area(:body) - concat fields_for(:parent_post, @post) { |parent_fields| - concat parent_fields.check_box(:secret) - } + concat fields_for(:parent_post, @post) { |parent_fields| + concat parent_fields.check_box(:secret) + } + end end expected = @@ -1174,13 +1291,15 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_and_fields_for_with_object - form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| - concat post_form.text_field(:title) - concat post_form.text_area(:body) + assert_deprecated do + form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| + concat post_form.text_field(:title) + concat post_form.text_area(:body) - concat post_form.fields_for(@comment) { |comment_fields| - concat comment_fields.text_field(:name) - } + concat post_form.fields_for(@comment) { |comment_fields| + concat comment_fields.text_field(:name) + } + end end expected = @@ -1205,10 +1324,12 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_labelled_builder - form_for(:post, @post, :builder => LabelledFormBuilder) do |f| - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) + assert_deprecated do + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end end expected = @@ -1225,10 +1346,12 @@ class FormHelperTest < ActionView::TestCase old_default_form_builder, ActionView::Base.default_form_builder = ActionView::Base.default_form_builder, LabelledFormBuilder - form_for(:post, @post) do |f| - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) + assert_deprecated do + form_for(:post, @post) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end end expected = @@ -1244,9 +1367,11 @@ class FormHelperTest < ActionView::TestCase end def test_default_form_builder_with_active_record_helpers - form_for(:post, @post) do |f| - concat f.error_message_on('author_name') - concat f.error_messages + assert_deprecated do + form_for(:post, @post) do |f| + concat f.error_message_on('author_name') + concat f.error_messages + end end expected = %(<form action='http://www.example.com' method='post'>) + @@ -1262,9 +1387,11 @@ class FormHelperTest < ActionView::TestCase post = @post @post = nil - form_for(:post, post) do |f| - concat f.error_message_on('author_name') - concat f.error_messages + assert_deprecated do + form_for(:post, post) do |f| + concat f.error_message_on('author_name') + concat f.error_messages + end end expected = %(<form action='http://www.example.com' method='post'>) + @@ -1294,10 +1421,12 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_labelled_builder_with_nested_fields_for_without_options_hash klass = nil - form_for(:post, @post, :builder => LabelledFormBuilder) do |f| - f.fields_for(:comments, Comment.new) do |nested_fields| - klass = nested_fields.class - '' + assert_deprecated do + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + f.fields_for(:comments, Comment.new) do |nested_fields| + klass = nested_fields.class + '' + end end end @@ -1307,10 +1436,12 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_labelled_builder_with_nested_fields_for_with_options_hash klass = nil - form_for(:post, @post, :builder => LabelledFormBuilder) do |f| - f.fields_for(:comments, Comment.new, :index => 'foo') do |nested_fields| - klass = nested_fields.class - '' + assert_deprecated do + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + f.fields_for(:comments, Comment.new, :index => 'foo') do |nested_fields| + klass = nested_fields.class + '' + end end end @@ -1322,10 +1453,12 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_labelled_builder_with_nested_fields_for_with_custom_builder klass = nil - form_for(:post, @post, :builder => LabelledFormBuilder) do |f| - f.fields_for(:comments, Comment.new, :builder => LabelledFormBuilderSubclass) do |nested_fields| - klass = nested_fields.class - '' + assert_deprecated do + form_for(:post, @post, :builder => LabelledFormBuilder) do |f| + f.fields_for(:comments, Comment.new, :builder => LabelledFormBuilderSubclass) do |nested_fields| + klass = nested_fields.class + '' + end end end @@ -1333,27 +1466,35 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_html_options_adds_options_to_form_tag - form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end + 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>" assert_dom_equal expected, output_buffer end def test_form_for_with_string_url_option - form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end + assert_deprecated do + 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 end def test_form_for_with_hash_url_option - form_for(:post, @post, :url => {:controller => 'controller', :action => 'action'}) do |f| end + assert_deprecated do + form_for(:post, @post, :url => {:controller => 'controller', :action => 'action'}) do |f| end + end assert_equal 'controller', @url_for_options[:controller] assert_equal 'action', @url_for_options[:action] end def test_form_for_with_record_url_option - form_for(:post, @post, :url => @post) do |f| end + assert_deprecated do + form_for(:post, @post, :url => @post) do |f| end + end expected = "<form action=\"/posts/123\" method=\"post\"></form>" assert_equal expected, output_buffer diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 3b8760351e..ef612b879b 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -335,6 +335,36 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_search_field_tag + expected = %{<input id="query" name="query" type="search" />} + assert_dom_equal(expected, search_field_tag("query")) + end + + def telephone_field_tag + expected = %{<input id="cell" name="cell" type="tel" />} + assert_dom_equal(expected, telephone_field_tag("cell")) + end + + def test_url_field_tag + expected = %{<input id="homepage" name="homepage" type="url" />} + assert_dom_equal(expected, url_field_tag("homepage")) + end + + def test_email_field_tag + expected = %{<input id="address" name="address" type="email" />} + assert_dom_equal(expected, email_field_tag("address")) + end + + def test_number_field_tag + expected = %{<input name="quantity" max="9" id="quantity" type="number" min="1" />} + assert_dom_equal(expected, number_field_tag("quantity", nil, :in => 1...10)) + end + + def test_range_input_tag + expected = %{<input name="volume" step="0.1" max="11" id="volume" type="range" min="0" />} + assert_dom_equal(expected, range_field_tag("volume", nil, :in => 0..11, :step => 0.1)) + end + def test_pass assert_equal 1, 1 end |