1 require "#{File.dirname(__FILE__)}/../abstract_unit"
4 Post = Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
6 alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
7 alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
8 alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
10 def new_record=(boolean)
22 def save; @id = 1; @post_id = 1 end
23 def new_record?; @id.nil? end
25 @id.nil? ? 'new comment' : "comment ##{@id}"
30 class Comment::Nested < Comment; end
33 class FormHelperTest < Test::Unit::TestCase
34 include ActionView::Helpers::FormHelper
35 include ActionView::Helpers::FormTagHelper
36 include ActionView::Helpers::UrlHelper
37 include ActionView::Helpers::TagHelper
38 include ActionView::Helpers::TextHelper
39 include ActionView::Helpers::ActiveRecordHelper
40 include ActionView::Helpers::RecordIdentificationHelper
41 include ActionController::PolymorphicRoutes
45 @comment = Comment.new
48 def on(field); "can't be empty" if field == "author_name"; end
49 def empty?() false end
51 def full_messages() [ "Author name can't be empty" ] end
54 def @post.id; 123; end
55 def @post.id_before_type_cast; 123; end
56 def @post.to_param; '123'; end
58 @post.title = "Hello World"
59 @post.author_name = ""
60 @post.body = "Back to the hill and over it again!"
62 @post.written_on = Date.new(2004, 6, 15)
64 @controller = Class.new do
65 attr_reader :url_for_options
67 @url_for_options = options
68 "http://www.example.com"
71 @controller = @controller.new
75 assert_dom_equal('<label for="post_title">Title</label>', label("post", "title"))
76 assert_dom_equal('<label for="post_title">The title goes here</label>', label("post", "title", "The title goes here"))
78 '<label class="title_label" for="post_title">Title</label>',
79 label("post", "title", nil, :class => 'title_label')
83 def test_label_with_symbols
84 assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
89 '<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title")
92 '<input id="post_title" name="post[title]" size="30" type="password" value="Hello World" />', password_field("post", "title")
95 '<input id="person_name" name="person[name]" size="30" type="password" />', password_field("person", "name")
99 def test_text_field_with_escapes
100 @post.title = "<b>Hello World</b>"
102 '<input id="post_title" name="post[title]" size="30" type="text" value="<b>Hello World</b>" />', text_field("post", "title")
106 def test_text_field_with_options
107 expected = '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />'
108 assert_dom_equal expected, text_field("post", "title", "size" => 35)
109 assert_dom_equal expected, text_field("post", "title", :size => 35)
112 def test_text_field_assuming_size
113 expected = '<input id="post_title" maxlength="35" name="post[title]" size="35" type="text" value="Hello World" />'
114 assert_dom_equal expected, text_field("post", "title", "maxlength" => 35)
115 assert_dom_equal expected, text_field("post", "title", :maxlength => 35)
118 def test_text_field_removing_size
119 expected = '<input id="post_title" maxlength="35" name="post[title]" type="text" value="Hello World" />'
120 assert_dom_equal expected, text_field("post", "title", "maxlength" => 35, "size" => nil)
121 assert_dom_equal expected, text_field("post", "title", :maxlength => 35, :size => nil)
124 def test_text_field_doesnt_change_param_values
125 object_name = 'post[]'
126 expected = '<input id="post_123_title" name="post[123][title]" size="30" type="text" value="Hello World" />'
127 assert_equal expected, text_field(object_name, "title")
128 assert_equal object_name, "post[]"
131 def test_hidden_field
132 assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
133 hidden_field("post", "title")
136 def test_hidden_field_with_escapes
137 @post.title = "<b>Hello World</b>"
138 assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="<b>Hello World</b>" />',
139 hidden_field("post", "title")
142 def test_text_field_with_options
143 assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Something Else" />',
144 hidden_field("post", "title", :value => "Something Else")
149 '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
150 check_box("post", "secret")
154 '<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
155 check_box("post", "secret")
158 '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
159 check_box("post", "secret" ,{"checked"=>"checked"})
163 '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
164 check_box("post", "secret")
168 def test_check_box_with_explicit_checked_and_unchecked_values
171 '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="on" /><input name="post[secret]" type="hidden" value="off" />',
172 check_box("post", "secret", {}, "on", "off")
176 def test_checkbox_disabled_still_submits_checked_value
178 '<input checked="checked" disabled="disabled" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="1" />',
179 check_box("post", "secret", { :disabled => :true })
183 def test_radio_button
184 assert_dom_equal('<input checked="checked" id="post_title_hello_world" name="post[title]" type="radio" value="Hello World" />',
185 radio_button("post", "title", "Hello World")
187 assert_dom_equal('<input id="post_title_goodbye_world" name="post[title]" type="radio" value="Goodbye World" />',
188 radio_button("post", "title", "Goodbye World")
192 def test_radio_button_is_checked_with_integers
193 assert_dom_equal('<input checked="checked" id="post_secret_1" name="post[secret]" type="radio" value="1" />',
194 radio_button("post", "secret", "1")
198 def test_radio_button_respects_passed_in_id
199 assert_dom_equal('<input checked="checked" id="foo" name="post[secret]" type="radio" value="1" />',
200 radio_button("post", "secret", "1", :id=>"foo")
206 '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
207 text_area("post", "body")
211 def test_text_area_with_escapes
212 @post.body = "Back to <i>the</i> hill and over it again!"
214 '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to <i>the</i> hill and over it again!</textarea>',
215 text_area("post", "body")
219 def test_text_area_with_alternate_value
221 '<textarea cols="40" id="post_body" name="post[body]" rows="20">Testing alternate values.</textarea>',
222 text_area("post", "body", :value => 'Testing alternate values.')
226 def test_text_area_with_size_option
228 '<textarea cols="183" id="post_body" name="post[body]" rows="820">Back to the hill and over it again!</textarea>',
229 text_area("post", "body", :size => "183x820")
233 def test_explicit_name
235 '<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess")
238 '<textarea cols="40" id="post_body" name="really!" rows="20">Back to the hill and over it again!</textarea>',
239 text_area("post", "body", "name" => "really!")
242 '<input checked="checked" id="post_secret" name="i mean it" type="checkbox" value="1" /><input name="i mean it" type="hidden" value="0" />',
243 check_box("post", "secret", "name" => "i mean it")
245 assert_dom_equal text_field("post", "title", "name" => "dont guess"),
246 text_field("post", "title", :name => "dont guess")
247 assert_dom_equal text_area("post", "body", "name" => "really!"),
248 text_area("post", "body", :name => "really!")
249 assert_dom_equal check_box("post", "secret", "name" => "i mean it"),
250 check_box("post", "secret", :name => "i mean it")
255 '<input id="dont guess" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => "dont guess")
258 '<textarea cols="40" id="really!" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
259 text_area("post", "body", "id" => "really!")
262 '<input checked="checked" id="i mean it" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
263 check_box("post", "secret", "id" => "i mean it")
265 assert_dom_equal text_field("post", "title", "id" => "dont guess"),
266 text_field("post", "title", :id => "dont guess")
267 assert_dom_equal text_area("post", "body", "id" => "really!"),
268 text_area("post", "body", :id => "really!")
269 assert_dom_equal check_box("post", "secret", "id" => "i mean it"),
270 check_box("post", "secret", :id => "i mean it")
276 "<label for=\"post_#{pid}_title\">Title</label>",
277 label("post[]", "title")
280 "<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />", text_field("post[]","title")
283 "<textarea cols=\"40\" id=\"post_#{pid}_body\" name=\"post[#{pid}][body]\" rows=\"20\">Back to the hill and over it again!</textarea>",
284 text_area("post[]", "body")
287 "<input checked=\"checked\" id=\"post_#{pid}_secret\" name=\"post[#{pid}][secret]\" type=\"checkbox\" value=\"1\" /><input name=\"post[#{pid}][secret]\" type=\"hidden\" value=\"0\" />",
288 check_box("post[]", "secret")
291 "<input checked=\"checked\" id=\"post_#{pid}_title_hello_world\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Hello World\" />",
292 radio_button("post[]", "title", "Hello World")
294 assert_dom_equal("<input id=\"post_#{pid}_title_goodbye_world\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Goodbye World\" />",
295 radio_button("post[]", "title", "Goodbye World")
302 form_for(:post, @post, :html => { :id => 'create-post' }) do |f|
303 _erbout.concat f.label(:title)
304 _erbout.concat f.text_field(:title)
305 _erbout.concat f.text_area(:body)
306 _erbout.concat f.check_box(:secret)
307 _erbout.concat f.submit('Create post')
311 "<form action='http://www.example.com' id='create-post' method='post'>" +
312 "<label for='post_title'>Title</label>" +
313 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
314 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
315 "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
316 "<input name='post[secret]' type='hidden' value='0' />" +
317 "<input name='commit' id='post_submit' type='submit' value='Create post' />" +
320 assert_dom_equal expected, _erbout
323 def test_form_for_with_method
326 form_for(:post, @post, :html => { :id => 'create-post', :method => :put }) do |f|
327 _erbout.concat f.text_field(:title)
328 _erbout.concat f.text_area(:body)
329 _erbout.concat f.check_box(:secret)
333 "<form action='http://www.example.com' id='create-post' method='post'>" +
334 "<div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>" +
335 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
336 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
337 "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
338 "<input name='post[secret]' type='hidden' value='0' />" +
341 assert_dom_equal expected, _erbout
344 def test_form_for_without_object
347 form_for(:post, :html => { :id => 'create-post' }) do |f|
348 _erbout.concat f.text_field(:title)
349 _erbout.concat f.text_area(:body)
350 _erbout.concat f.check_box(:secret)
354 "<form action='http://www.example.com' id='create-post' method='post'>" +
355 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
356 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
357 "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
358 "<input name='post[secret]' type='hidden' value='0' />" +
361 assert_dom_equal expected, _erbout
364 def test_form_for_with_index
367 form_for("post[]", @post) do |f|
368 _erbout.concat f.label(:title)
369 _erbout.concat f.text_field(:title)
370 _erbout.concat f.text_area(:body)
371 _erbout.concat f.check_box(:secret)
375 "<form action='http://www.example.com' method='post'>" +
376 "<label for=\"post_123_title\">Title</label>" +
377 "<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
378 "<textarea name='post[123][body]' id='post_123_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
379 "<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />" +
380 "<input name='post[123][secret]' type='hidden' value='0' />" +
383 assert_dom_equal expected, _erbout
386 def test_nested_fields_for
388 form_for(:post, @post) do |f|
389 f.fields_for(:comment, @post) do |c|
390 _erbout.concat c.text_field(:title)
394 expected = "<form action='http://www.example.com' method='post'>" +
395 "<input name='post[comment][title]' size='30' type='text' id='post_comment_title' value='Hello World' />" +
398 assert_dom_equal expected, _erbout
404 fields_for(:post, @post) do |f|
405 _erbout.concat f.text_field(:title)
406 _erbout.concat f.text_area(:body)
407 _erbout.concat f.check_box(:secret)
411 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
412 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
413 "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
414 "<input name='post[secret]' type='hidden' value='0' />"
416 assert_dom_equal expected, _erbout
419 def test_fields_for_without_object
421 fields_for(:post) do |f|
422 _erbout.concat f.text_field(:title)
423 _erbout.concat f.text_area(:body)
424 _erbout.concat f.check_box(:secret)
428 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
429 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
430 "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
431 "<input name='post[secret]' type='hidden' value='0' />"
433 assert_dom_equal expected, _erbout
436 def test_fields_for_object_with_bracketed_name
438 fields_for("author[post]", @post) do |f|
439 _erbout.concat f.label(:title)
440 _erbout.concat f.text_field(:title)
443 assert_dom_equal "<label for=\"author_post_title\">Title</label>" +
444 "<input name='author[post][title]' size='30' type='text' id='author_post_title' value='Hello World' />",
448 def test_form_builder_does_not_have_form_for_method
449 assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
452 def test_form_for_and_fields_for
455 form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form|
456 _erbout.concat post_form.text_field(:title)
457 _erbout.concat post_form.text_area(:body)
459 fields_for(:parent_post, @post) do |parent_fields|
460 _erbout.concat parent_fields.check_box(:secret)
465 "<form action='http://www.example.com' id='create-post' method='post'>" +
466 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
467 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
468 "<input name='parent_post[secret]' checked='checked' type='checkbox' id='parent_post_secret' value='1' />" +
469 "<input name='parent_post[secret]' type='hidden' value='0' />" +
472 assert_dom_equal expected, _erbout
475 class LabelledFormBuilder < ActionView::Helpers::FormBuilder
476 (field_helpers - %w(hidden_field)).each do |selector|
478 def #{selector}(field, *args, &proc)
479 "<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>"
482 class_eval src, __FILE__, __LINE__
486 def test_form_for_with_labelled_builder
489 form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
490 _erbout.concat f.text_field(:title)
491 _erbout.concat f.text_area(:body)
492 _erbout.concat f.check_box(:secret)
496 "<form action='http://www.example.com' method='post'>" +
497 "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
498 "<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/>" +
499 "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
500 "<input name='post[secret]' type='hidden' value='0' /><br/>" +
503 assert_dom_equal expected, _erbout
506 def test_default_form_builder
507 old_default_form_builder, ActionView::Base.default_form_builder =
508 ActionView::Base.default_form_builder, LabelledFormBuilder
511 form_for(:post, @post) do |f|
512 _erbout.concat f.text_field(:title)
513 _erbout.concat f.text_area(:body)
514 _erbout.concat f.check_box(:secret)
518 "<form action='http://www.example.com' method='post'>" +
519 "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
520 "<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/>" +
521 "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
522 "<input name='post[secret]' type='hidden' value='0' /><br/>" +
525 assert_dom_equal expected, _erbout
527 ActionView::Base.default_form_builder = old_default_form_builder
530 def test_default_form_builder_with_active_record_helpers
533 form_for(:post, @post) do |f|
534 _erbout.concat f.error_message_on('author_name')
535 _erbout.concat f.error_messages
538 expected = %(<form action='http://www.example.com' method='post'>) +
539 %(<div class='formError'>can't be empty</div>) +
540 %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
543 assert_dom_equal expected, _erbout
547 def test_default_form_builder_no_instance_variable
552 form_for(:post, post) do |f|
553 _erbout.concat f.error_message_on('author_name')
554 _erbout.concat f.error_messages
557 expected = %(<form action='http://www.example.com' method='post'>) +
558 %(<div class='formError'>can't be empty</div>) +
559 %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
562 assert_dom_equal expected, _erbout
566 # Perhaps this test should be moved to prototype helper tests.
567 def test_remote_form_for_with_labelled_builder
568 self.extend ActionView::Helpers::PrototypeHelper
571 remote_form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
572 _erbout.concat f.text_field(:title)
573 _erbout.concat f.text_area(:body)
574 _erbout.concat f.check_box(:secret)
578 %(<form action="http://www.example.com" onsubmit="new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" method="post">) +
579 "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
580 "<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/>" +
581 "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
582 "<input name='post[secret]' type='hidden' value='0' /><br/>" +
585 assert_dom_equal expected, _erbout
588 def test_fields_for_with_labelled_builder
591 fields_for(:post, @post, :builder => LabelledFormBuilder) do |f|
592 _erbout.concat f.text_field(:title)
593 _erbout.concat f.text_area(:body)
594 _erbout.concat f.check_box(:secret)
598 "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
599 "<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/>" +
600 "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
601 "<input name='post[secret]' type='hidden' value='0' /><br/>"
603 assert_dom_equal expected, _erbout
606 def test_form_for_with_html_options_adds_options_to_form_tag
609 form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
610 expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>"
612 assert_dom_equal expected, _erbout
615 def test_form_for_with_string_url_option
618 form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end
620 assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', _erbout
623 def test_form_for_with_hash_url_option
626 form_for(:post, @post, :url => {:controller => 'controller', :action => 'action'}) do |f| end
628 assert_equal 'controller', @controller.url_for_options[:controller]
629 assert_equal 'action', @controller.url_for_options[:action]
632 def test_form_for_with_record_url_option
635 form_for(:post, @post, :url => @post) do |f| end
637 expected = "<form action=\"/posts/123\" method=\"post\"></form>"
638 assert_equal expected, _erbout
641 def test_form_for_with_existing_object
644 form_for(@post) do |f| end
646 expected = "<form action=\"/posts/123\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>"
647 assert_equal expected, _erbout
650 def test_form_for_with_new_object
654 post.new_record = true
655 def post.id() nil end
657 form_for(post) do |f| end
659 expected = "<form action=\"/posts\" class=\"new_post\" id=\"new_post\" method=\"post\"></form>"
660 assert_equal expected, _erbout
663 def test_form_for_with_existing_object_in_list
664 @post.new_record = false
667 form_for([@post, @comment]) {}
669 expected = %(<form action="#{comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>)
670 assert_dom_equal expected, _erbout
673 def test_form_for_with_new_object_in_list
674 @post.new_record = false
676 form_for([@post, @comment]) {}
678 expected = %(<form action="#{comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
679 assert_dom_equal expected, _erbout
682 def test_form_for_with_existing_object_and_namespace_in_list
683 @post.new_record = false
686 form_for([:admin, @post, @comment]) {}
688 expected = %(<form action="#{admin_comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>)
689 assert_dom_equal expected, _erbout
692 def test_form_for_with_new_object_and_namespace_in_list
693 @post.new_record = false
695 form_for([:admin, @post, @comment]) {}
697 expected = %(<form action="#{admin_comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
698 assert_dom_equal expected, _erbout
701 def test_form_for_with_existing_object_and_custom_url
704 form_for(@post, :url => "/super_posts") do |f| end
706 expected = "<form action=\"/super_posts\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>"
707 assert_equal expected, _erbout
710 def test_remote_form_for_with_html_options_adds_options_to_form_tag
711 self.extend ActionView::Helpers::PrototypeHelper
714 remote_form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
715 expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\" onsubmit=\"new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"></form>"
717 assert_dom_equal expected, _erbout
722 def comments_path(post)
723 "/posts/#{post.id}/comments"
725 alias_method :post_comments_path, :comments_path
727 def comment_path(post, comment)
728 "/posts/#{post.id}/comments/#{comment.id}"
730 alias_method :post_comment_path, :comment_path
732 def admin_comments_path(post)
733 "/admin/posts/#{post.id}/comments"
735 alias_method :admin_post_comments_path, :admin_comments_path
737 def admin_comment_path(post, comment)
738 "/admin/posts/#{post.id}/comments/#{comment.id}"
740 alias_method :admin_post_comment_path, :admin_comment_path
750 def protect_against_forgery?