@@ -423,6 +423,90 @@ def test_explicit_id
423
423
check_box ( "post" , "secret" , :id => "i mean it" )
424
424
end
425
425
426
+ def test_nil_id
427
+ assert_dom_equal (
428
+ '<input name="post[title]" size="30" type="text" value="Hello World" />' , text_field ( "post" , "title" , "id" => nil )
429
+ )
430
+ assert_dom_equal (
431
+ '<textarea cols="40" name="post[body]" rows="20">Back to the hill and over it again!</textarea>' ,
432
+ text_area ( "post" , "body" , "id" => nil )
433
+ )
434
+ assert_dom_equal (
435
+ '<input name="post[secret]" type="hidden" value="0" /><input checked="checked" name="post[secret]" type="checkbox" value="1" />' ,
436
+ check_box ( "post" , "secret" , "id" => nil )
437
+ )
438
+ assert_dom_equal (
439
+ '<input type="radio" name="post[secret]" value="0" />' ,
440
+ radio_button ( "post" , "secret" , "0" , "id" => nil )
441
+ )
442
+ assert_dom_equal (
443
+ '<select name="post[secret]"></select>' ,
444
+ select ( "post" , "secret" , [ ] , { } , "id" => nil )
445
+ )
446
+ assert_dom_equal text_field ( "post" , "title" , "id" => nil ) ,
447
+ text_field ( "post" , "title" , :id => nil )
448
+ assert_dom_equal text_area ( "post" , "body" , "id" => nil ) ,
449
+ text_area ( "post" , "body" , :id => nil )
450
+ assert_dom_equal check_box ( "post" , "secret" , "id" => nil ) ,
451
+ check_box ( "post" , "secret" , :id => nil )
452
+ assert_dom_equal radio_button ( "post" , "secret" , "id" => nil ) ,
453
+ radio_button ( "post" , "secret" , :id => nil )
454
+ end
455
+
456
+ def test_index
457
+ assert_dom_equal (
458
+ '<input name="post[5][title]" size="30" id="post_5_title" type="text" value="Hello World" />' ,
459
+ text_field ( "post" , "title" , "index" => 5 )
460
+ )
461
+ assert_dom_equal (
462
+ '<textarea cols="40" name="post[5][body]" id="post_5_body" rows="20">Back to the hill and over it again!</textarea>' ,
463
+ text_area ( "post" , "body" , "index" => 5 )
464
+ )
465
+ assert_dom_equal (
466
+ '<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" id="post_5_secret" />' ,
467
+ check_box ( "post" , "secret" , "index" => 5 )
468
+ )
469
+ assert_dom_equal (
470
+ text_field ( "post" , "title" , "index" => 5 ) ,
471
+ text_field ( "post" , "title" , "index" => 5 )
472
+ )
473
+ assert_dom_equal (
474
+ text_area ( "post" , "body" , "index" => 5 ) ,
475
+ text_area ( "post" , "body" , "index" => 5 )
476
+ )
477
+ assert_dom_equal (
478
+ check_box ( "post" , "secret" , "index" => 5 ) ,
479
+ check_box ( "post" , "secret" , "index" => 5 )
480
+ )
481
+ end
482
+
483
+ def test_index_with_nil_id
484
+ assert_dom_equal (
485
+ '<input name="post[5][title]" size="30" type="text" value="Hello World" />' ,
486
+ text_field ( "post" , "title" , "index" => 5 , 'id' => nil )
487
+ )
488
+ assert_dom_equal (
489
+ '<textarea cols="40" name="post[5][body]" rows="20">Back to the hill and over it again!</textarea>' ,
490
+ text_area ( "post" , "body" , "index" => 5 , 'id' => nil )
491
+ )
492
+ assert_dom_equal (
493
+ '<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" />' ,
494
+ check_box ( "post" , "secret" , "index" => 5 , 'id' => nil )
495
+ )
496
+ assert_dom_equal (
497
+ text_field ( "post" , "title" , "index" => 5 , 'id' => nil ) ,
498
+ text_field ( "post" , "title" , :index => 5 , :id => nil )
499
+ )
500
+ assert_dom_equal (
501
+ text_area ( "post" , "body" , "index" => 5 , 'id' => nil ) ,
502
+ text_area ( "post" , "body" , :index => 5 , :id => nil )
503
+ )
504
+ assert_dom_equal (
505
+ check_box ( "post" , "secret" , "index" => 5 , 'id' => nil ) ,
506
+ check_box ( "post" , "secret" , :index => 5 , :id => nil )
507
+ )
508
+ end
509
+
426
510
def test_auto_index
427
511
pid = @post . id
428
512
assert_dom_equal (
@@ -449,6 +533,29 @@ def test_auto_index
449
533
)
450
534
end
451
535
536
+ def test_auto_index_with_nil_id
537
+ pid = @post . id
538
+ assert_dom_equal (
539
+ "<input name=\" post[#{ pid } ][title]\" size=\" 30\" type=\" text\" value=\" Hello World\" />" ,
540
+ text_field ( "post[]" , "title" , :id => nil )
541
+ )
542
+ assert_dom_equal (
543
+ "<textarea cols=\" 40\" name=\" post[#{ pid } ][body]\" rows=\" 20\" >Back to the hill and over it again!</textarea>" ,
544
+ text_area ( "post[]" , "body" , :id => nil )
545
+ )
546
+ assert_dom_equal (
547
+ "<input name=\" post[#{ pid } ][secret]\" type=\" hidden\" value=\" 0\" /><input checked=\" checked\" name=\" post[#{ pid } ][secret]\" type=\" checkbox\" value=\" 1\" />" ,
548
+ check_box ( "post[]" , "secret" , :id => nil )
549
+ )
550
+ assert_dom_equal (
551
+ "<input checked=\" checked\" name=\" post[#{ pid } ][title]\" type=\" radio\" value=\" Hello World\" />" ,
552
+ radio_button ( "post[]" , "title" , "Hello World" , :id => nil )
553
+ )
554
+ assert_dom_equal ( "<input name=\" post[#{ pid } ][title]\" type=\" radio\" value=\" Goodbye World\" />" ,
555
+ radio_button ( "post[]" , "title" , "Goodbye World" , :id => nil )
556
+ )
557
+ end
558
+
452
559
def test_form_for
453
560
assert_deprecated do
454
561
form_for ( :post , @post , :html => { :id => 'create-post' } ) do |f |
0 commit comments