padrino-helpers 0.9.24 → 0.9.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/lib/padrino-helpers.rb +0 -1
  2. data/lib/padrino-helpers/asset_tag_helpers.rb +2 -2
  3. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +1 -1
  4. data/lib/padrino-helpers/form_helpers.rb +57 -12
  5. data/lib/padrino-helpers/format_helpers.rb +8 -6
  6. data/lib/padrino-helpers/output_helpers.rb +28 -8
  7. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +17 -10
  8. data/lib/padrino-helpers/output_helpers/erb_handler.rb +31 -32
  9. data/lib/padrino-helpers/output_helpers/haml_handler.rb +13 -4
  10. data/lib/padrino-helpers/output_helpers/slim_handler.rb +82 -0
  11. data/lib/padrino-helpers/render_helpers.rb +1 -1
  12. data/lib/padrino-helpers/tag_helpers.rb +1 -1
  13. data/test/fixtures/markup_app/app.rb +6 -4
  14. data/test/fixtures/markup_app/views/capture_concat.slim +13 -0
  15. data/test/fixtures/markup_app/views/content_for.slim +9 -0
  16. data/test/fixtures/markup_app/views/content_tag.slim +9 -0
  17. data/test/fixtures/markup_app/views/current_engine.erb +5 -0
  18. data/test/fixtures/markup_app/views/current_engine.haml +5 -0
  19. data/test/fixtures/markup_app/views/current_engine.slim +5 -0
  20. data/test/fixtures/markup_app/views/fields_for.erb +1 -1
  21. data/test/fixtures/markup_app/views/fields_for.haml +7 -7
  22. data/test/fixtures/markup_app/views/fields_for.slim +15 -0
  23. data/test/fixtures/markup_app/views/form_for.slim +47 -0
  24. data/test/fixtures/markup_app/views/form_tag.slim +45 -0
  25. data/test/fixtures/markup_app/views/link_to.slim +4 -0
  26. data/test/fixtures/markup_app/views/mail_to.slim +3 -0
  27. data/test/fixtures/markup_app/views/meta_tag.slim +3 -0
  28. data/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
  29. data/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
  30. data/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
  31. data/test/fixtures/render_app/app.rb +10 -0
  32. data/test/fixtures/render_app/views/current_engine.haml +5 -0
  33. data/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
  34. data/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
  35. data/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
  36. data/test/helper.rb +1 -12
  37. data/test/test_asset_tag_helpers.rb +48 -0
  38. data/test/test_form_builder.rb +159 -6
  39. data/test/test_form_helpers.rb +165 -4
  40. data/test/test_format_helpers.rb +19 -2
  41. data/test/test_output_helpers.rb +53 -0
  42. data/test/test_render_helpers.rb +11 -0
  43. data/test/test_tag_helpers.rb +20 -0
  44. metadata +27 -9
  45. data/lib/padrino-helpers/dom_helpers.rb +0 -46
  46. data/test/test_dom_helpers.rb +0 -37
@@ -38,7 +38,7 @@ class TestFormBuilder < Test::Unit::TestCase
38
38
  should "display correct form html for namespaced object" do
39
39
  actual_html = form_for(Outer::UserAccount.new, '/register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
40
40
  assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
41
- assert_has_tag('form input', :type => 'text', :name => 'outer-user_account[username]') { actual_html }
41
+ assert_has_tag('form input', :type => 'text', :name => 'outer_user_account[username]') { actual_html }
42
42
  end
43
43
 
44
44
  should "display correct form html with remote option" do
@@ -97,6 +97,13 @@ class TestFormBuilder < Test::Unit::TestCase
97
97
  assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
98
98
  end
99
99
 
100
+ should "display correct form in slim" do
101
+ visit '/slim/form_for'
102
+ assert_have_selector :form, :action => '/demo', :id => 'demo'
103
+ assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
104
+ assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
105
+ end
106
+
100
107
  should "have a class of 'invalid' for fields with errors" do
101
108
  actual_html = form_for(@user, '/register') {|f| f.text_field(:email) }
102
109
  assert_has_tag(:input, :type => 'text', :name => 'user[email]', :id => 'user_email', :class => 'invalid') {actual_html }
@@ -138,6 +145,14 @@ class TestFormBuilder < Test::Unit::TestCase
138
145
  assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
139
146
  assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
140
147
  end
148
+
149
+ should "display correct simple fields in slim" do
150
+ visit '/slim/fields_for'
151
+ assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
152
+ assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
153
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
154
+ assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
155
+ end
141
156
  end
142
157
 
143
158
  # ===========================
@@ -184,6 +199,19 @@ class TestFormBuilder < Test::Unit::TestCase
184
199
  assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
185
200
  assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
186
201
  end
202
+
203
+ should "display correct form in slim" do
204
+ visit '/slim/form_for'
205
+ assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
206
+ assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
207
+ assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
208
+ assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
209
+ assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
210
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
211
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
212
+ assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
213
+ assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
214
+ end
187
215
  end
188
216
 
189
217
  context 'for #error_message_on method' do
@@ -223,6 +251,13 @@ class TestFormBuilder < Test::Unit::TestCase
223
251
  assert_have_selector '#demo label', :content => "About Me: "
224
252
  assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
225
253
  end
254
+
255
+ should "display correct label in slim" do
256
+ visit '/slim/form_for'
257
+ assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
258
+ assert_have_selector '#demo label', :content => "About Me: "
259
+ assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
260
+ end
226
261
  end
227
262
 
228
263
  context 'for #hidden_field method' do
@@ -242,6 +277,12 @@ class TestFormBuilder < Test::Unit::TestCase
242
277
  assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
243
278
  assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
244
279
  end
280
+
281
+ should "display correct hidden field in slim" do
282
+ visit '/slim/form_for'
283
+ assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
284
+ assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
285
+ end
245
286
  end
246
287
 
247
288
  context 'for #text_field method' do
@@ -261,6 +302,12 @@ class TestFormBuilder < Test::Unit::TestCase
261
302
  assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
262
303
  assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
263
304
  end
305
+
306
+ should "display correct text field in slim" do
307
+ visit '/slim/form_for'
308
+ assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
309
+ assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
310
+ end
264
311
  end
265
312
 
266
313
  context 'for #check_box method' do
@@ -313,6 +360,11 @@ class TestFormBuilder < Test::Unit::TestCase
313
360
  visit '/erb/form_for'
314
361
  assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
315
362
  end
363
+
364
+ should "display correct checkbox in slim" do
365
+ visit '/slim/form_for'
366
+ assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
367
+ end
316
368
  end
317
369
 
318
370
  context 'for #radio_button method' do
@@ -351,17 +403,24 @@ class TestFormBuilder < Test::Unit::TestCase
351
403
  assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
352
404
  assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
353
405
  end
406
+
407
+ should "display correct radio button in slim" do
408
+ visit '/slim/form_for'
409
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
410
+ assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
411
+ assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
412
+ end
354
413
  end
355
414
 
356
415
  context 'for #text_area method' do
357
416
  should "display correct text_area html" do
358
417
  actual_html = standard_builder.text_area(:about, :class => 'large')
359
- assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]') { actual_html }
418
+ assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]', :rows => '', :cols => '') { actual_html }
360
419
  end
361
420
 
362
421
  should "display correct text_area html and content" do
363
- actual_html = standard_builder.text_area(:about, :value => "Demo")
364
- assert_has_tag('textarea', :id => 'user_about', :content => 'Demo') { actual_html }
422
+ actual_html = standard_builder.text_area(:about, :value => "Demo", :rows => '5', :cols => '6')
423
+ assert_has_tag('textarea', :id => 'user_about', :content => 'Demo', :rows => '5', :cols => '6') { actual_html }
365
424
  end
366
425
 
367
426
  should "display correct text_area in haml" do
@@ -375,6 +434,12 @@ class TestFormBuilder < Test::Unit::TestCase
375
434
  assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
376
435
  assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
377
436
  end
437
+
438
+ should "display correct text_area in slim" do
439
+ visit '/slim/form_for'
440
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
441
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
442
+ end
378
443
  end
379
444
 
380
445
  context 'for #password_field method' do
@@ -394,6 +459,12 @@ class TestFormBuilder < Test::Unit::TestCase
394
459
  assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
395
460
  assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
396
461
  end
462
+
463
+ should "display correct password_field in slim" do
464
+ visit '/slim/form_for'
465
+ assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
466
+ assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
467
+ end
397
468
  end
398
469
 
399
470
  context 'for #file_field method' do
@@ -413,6 +484,12 @@ class TestFormBuilder < Test::Unit::TestCase
413
484
  assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
414
485
  assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
415
486
  end
487
+
488
+ should "display correct file_field in slim" do
489
+ visit '/slim/form_for'
490
+ assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
491
+ assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
492
+ end
416
493
  end
417
494
 
418
495
  context 'for #select method' do
@@ -486,6 +563,12 @@ class TestFormBuilder < Test::Unit::TestCase
486
563
  assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
487
564
  assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
488
565
  end
566
+
567
+ should "display correct select in slim" do
568
+ visit '/slim/form_for'
569
+ assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
570
+ assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
571
+ end
489
572
  end
490
573
 
491
574
  context 'for #submit method' do
@@ -510,6 +593,12 @@ class TestFormBuilder < Test::Unit::TestCase
510
593
  assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
511
594
  assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
512
595
  end
596
+
597
+ should "display correct submit button in slim" do
598
+ visit '/slim/form_for'
599
+ assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
600
+ assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
601
+ end
513
602
  end
514
603
 
515
604
  context 'for #image_submit method' do
@@ -538,6 +627,12 @@ class TestFormBuilder < Test::Unit::TestCase
538
627
  assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
539
628
  assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
540
629
  end
630
+
631
+ should "display correct image submit button in slim" do
632
+ visit '/slim/form_for'
633
+ assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
634
+ assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
635
+ end
541
636
  end
542
637
 
543
638
  context 'for #fields_for method' do
@@ -658,6 +753,23 @@ class TestFormBuilder < Test::Unit::TestCase
658
753
  assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
659
754
  assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
660
755
  end
756
+
757
+ should "display nested children fields in slim" do
758
+ visit '/slim/fields_for'
759
+ # Telephone
760
+ assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
761
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
762
+ # Address 1 (Saved)
763
+ assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
764
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
765
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
766
+ assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
767
+ # Address 2 (New)
768
+ assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
769
+ assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
770
+ assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
771
+ assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
772
+ end
661
773
  end
662
774
 
663
775
  # ===========================
@@ -682,6 +794,12 @@ class TestFormBuilder < Test::Unit::TestCase
682
794
  assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
683
795
  assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
684
796
  end
797
+
798
+ should "display correct text field block in slim" do
799
+ visit '/slim/form_for'
800
+ assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
801
+ assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
802
+ end
685
803
  end
686
804
 
687
805
  context 'for #text_area_block method' do
@@ -702,6 +820,12 @@ class TestFormBuilder < Test::Unit::TestCase
702
820
  assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
703
821
  assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
704
822
  end
823
+
824
+ should "display correct text area block in slim" do
825
+ visit '/slim/form_for'
826
+ assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
827
+ assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
828
+ end
705
829
  end
706
830
 
707
831
  context 'for #password_field_block method' do
@@ -722,6 +846,12 @@ class TestFormBuilder < Test::Unit::TestCase
722
846
  assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
723
847
  assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
724
848
  end
849
+
850
+ should "display correct password field block in slim" do
851
+ visit '/slim/form_for'
852
+ assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
853
+ assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
854
+ end
725
855
  end
726
856
 
727
857
  context 'for #file_field_block method' do
@@ -742,6 +872,12 @@ class TestFormBuilder < Test::Unit::TestCase
742
872
  assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
743
873
  assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
744
874
  end
875
+
876
+ should "display correct file field block in slim" do
877
+ visit '/slim/form_for'
878
+ assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
879
+ assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
880
+ end
745
881
  end
746
882
 
747
883
  context 'for #check_box_block method' do
@@ -762,6 +898,12 @@ class TestFormBuilder < Test::Unit::TestCase
762
898
  assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
763
899
  assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
764
900
  end
901
+
902
+ should "display correct check box block in slim" do
903
+ visit '/slim/form_for'
904
+ assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
905
+ assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
906
+ end
765
907
  end
766
908
 
767
909
  context 'for #select_block method' do
@@ -786,6 +928,12 @@ class TestFormBuilder < Test::Unit::TestCase
786
928
  assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
787
929
  assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
788
930
  end
931
+
932
+ should "display correct select_block block in slim" do
933
+ visit '/slim/form_for'
934
+ assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
935
+ assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
936
+ end
789
937
  end
790
938
 
791
939
  context 'for #submit_block method' do
@@ -803,6 +951,11 @@ class TestFormBuilder < Test::Unit::TestCase
803
951
  visit '/erb/form_for'
804
952
  assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
805
953
  end
954
+
955
+ should "display correct submit block in slim" do
956
+ visit '/slim/form_for'
957
+ assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
958
+ end
806
959
  end
807
960
 
808
961
  context 'for #image_submit_block method' do
@@ -820,8 +973,8 @@ class TestFormBuilder < Test::Unit::TestCase
820
973
  assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
821
974
  end
822
975
 
823
- should "display correct image submit block in erb" do
824
- visit '/erb/form_for'
976
+ should "display correct image submit block in slim" do
977
+ visit '/slim/form_for'
825
978
  assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
826
979
  end
827
980
  end
@@ -65,6 +65,12 @@ class TestFormHelpers < Test::Unit::TestCase
65
65
  assert_have_selector 'form.simple-form', :action => '/simple'
66
66
  assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
67
67
  end
68
+
69
+ should "display correct forms in slim" do
70
+ visit '/slim/form_tag'
71
+ assert_have_selector 'form.simple-form', :action => '/simple'
72
+ assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
73
+ end
68
74
  end
69
75
 
70
76
  context 'for #field_set_tag method' do
@@ -89,6 +95,14 @@ class TestFormHelpers < Test::Unit::TestCase
89
95
  assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
90
96
  assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
91
97
  end
98
+
99
+ should "display correct field_sets in slim" do
100
+ visit '/slim/form_tag'
101
+ assert_have_selector 'form.simple-form fieldset', :count => 1
102
+ assert_have_no_selector 'form.simple-form fieldset legend'
103
+ assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
104
+ assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
105
+ end
92
106
  end
93
107
 
94
108
  context 'for #error_messages_for method' do
@@ -129,6 +143,20 @@ class TestFormHelpers < Test::Unit::TestCase
129
143
  assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
130
144
  assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
131
145
  end
146
+
147
+ should "display correct error messages list in slim" do
148
+ visit '/slim/form_tag'
149
+ assert_have_no_selector 'form.simple-form .field-errors'
150
+ assert_have_selector 'form.advanced-form .field-errors'
151
+ assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
152
+ assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
153
+ assert_have_selector 'form.advanced-form .field-errors ul'
154
+ assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
155
+ assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be a email"
156
+ assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
157
+ assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
158
+ assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
159
+ end
132
160
  end
133
161
 
134
162
  context 'for #error_message_on method' do
@@ -187,6 +215,7 @@ class TestFormHelpers < Test::Unit::TestCase
187
215
  assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
188
216
  assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
189
217
  end
218
+
190
219
  should "display label tag in haml for advanced form" do
191
220
  visit '/haml/form_tag'
192
221
  assert_have_selector 'form.advanced-form label', :count => 6
@@ -196,6 +225,24 @@ class TestFormHelpers < Test::Unit::TestCase
196
225
  assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
197
226
  assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
198
227
  end
228
+
229
+ should "display label tag in slim for simple form" do
230
+ visit '/slim/form_tag'
231
+ assert_have_selector 'form.simple-form label', :count => 4
232
+ assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
233
+ assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
234
+ assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
235
+ end
236
+
237
+ should "display label tag in slim for advanced form" do
238
+ visit '/slim/form_tag'
239
+ assert_have_selector 'form.advanced-form label', :count => 6
240
+ assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
241
+ assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
242
+ assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
243
+ assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
244
+ assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
245
+ end
199
246
  end
200
247
 
201
248
  context 'for #hidden_field_tag method' do
@@ -215,6 +262,12 @@ class TestFormHelpers < Test::Unit::TestCase
215
262
  assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
216
263
  assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
217
264
  end
265
+
266
+ should "display hidden field in slim" do
267
+ visit '/slim/form_tag'
268
+ assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
269
+ assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
270
+ end
218
271
  end
219
272
 
220
273
  context 'for #text_field_tag method' do
@@ -234,17 +287,23 @@ class TestFormHelpers < Test::Unit::TestCase
234
287
  assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
235
288
  assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
236
289
  end
290
+
291
+ should "display text field in slim" do
292
+ visit '/slim/form_tag'
293
+ assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
294
+ assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
295
+ end
237
296
  end
238
297
 
239
298
  context 'for #text_area_tag method' do
240
299
  should "display text area in ruby" do
241
300
  actual_html = text_area_tag(:about, :class => 'long')
242
- assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
301
+ assert_has_tag(:textarea, :class => "long", :name => 'about', :rows => '', :cols => '') { actual_html }
243
302
  end
244
303
 
245
304
  should "display text area in ruby with specified content" do
246
- actual_html = text_area_tag(:about, :value => "a test")
247
- assert_has_tag(:textarea, :content => "a test", :name => 'about') { actual_html }
305
+ actual_html = text_area_tag(:about, :value => "a test", :rows => 5, :cols => 6)
306
+ assert_has_tag(:textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6") { actual_html }
248
307
  end
249
308
 
250
309
  should "display text area in erb" do
@@ -256,6 +315,11 @@ class TestFormHelpers < Test::Unit::TestCase
256
315
  visit '/haml/form_tag'
257
316
  assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
258
317
  end
318
+
319
+ should "display text area in slim" do
320
+ visit '/slim/form_tag'
321
+ assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
322
+ end
259
323
  end
260
324
 
261
325
  context 'for #password_field_tag method' do
@@ -275,6 +339,12 @@ class TestFormHelpers < Test::Unit::TestCase
275
339
  assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
276
340
  assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
277
341
  end
342
+
343
+ should "display password field in slim" do
344
+ visit '/slim/form_tag'
345
+ assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
346
+ assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
347
+ end
278
348
  end
279
349
 
280
350
  context 'for #file_field_tag method' do
@@ -292,6 +362,11 @@ class TestFormHelpers < Test::Unit::TestCase
292
362
  visit '/haml/form_tag'
293
363
  assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
294
364
  end
365
+
366
+ should "display file field in slim" do
367
+ visit '/slim/form_tag'
368
+ assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
369
+ end
295
370
  end
296
371
 
297
372
  context "for #check_box_tag method" do
@@ -317,6 +392,12 @@ class TestFormHelpers < Test::Unit::TestCase
317
392
  assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
318
393
  assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
319
394
  end
395
+
396
+ should "display check_box tag in slim" do
397
+ visit '/slim/form_tag'
398
+ assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
399
+ assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
400
+ end
320
401
  end
321
402
 
322
403
  context "for #radio_button_tag method" do
@@ -345,6 +426,14 @@ class TestFormHelpers < Test::Unit::TestCase
345
426
  assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
346
427
  assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
347
428
  end
429
+
430
+ should "display radio_button tag in slim" do
431
+ visit '/slim/form_tag'
432
+ assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
433
+ assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
434
+ assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
435
+ assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
436
+ end
348
437
  end
349
438
 
350
439
  context "for #select_tag method" do
@@ -353,7 +442,7 @@ class TestFormHelpers < Test::Unit::TestCase
353
442
  assert_has_tag(:select, :name => 'favorite_color') { actual_html }
354
443
  assert_has_tag('select option:first-child', :content => '') { actual_html }
355
444
  assert_has_tag('select option', :content => 'green', :value => 'green') { actual_html }
356
- assert_has_tag('select option', :content => 'blue', :value => 'blue') { actual_html }
445
+ assert_has_tag('select option', :content => 'blue', :value => 'blue') { actual_html }
357
446
  assert_has_tag('select option', :content => 'black', :value => 'black') { actual_html }
358
447
  end
359
448
 
@@ -362,6 +451,50 @@ class TestFormHelpers < Test::Unit::TestCase
362
451
  assert_has_tag(:select, :disabled => 'disabled') { actual_html }
363
452
  end
364
453
 
454
+ should "take a range as a collection for options" do
455
+ actual_html = select_tag(:favorite_color, :options => (1..3))
456
+ assert_has_tag(:select) { actual_html }
457
+ assert_has_tag('select option', :value => '1') { actual_html }
458
+ assert_has_tag('select option', :value => '2') { actual_html }
459
+ assert_has_tag('select option', :value => '3') { actual_html }
460
+ end
461
+
462
+ should "include blank for grouped options" do
463
+ opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
464
+ actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => true )
465
+ assert_has_tag('select option:first-child', :value => "", :content => "") { actual_html }
466
+ end
467
+
468
+ should "return a select tag with grouped options for an nested array" do
469
+ opts = [
470
+ ["Friends",["Yoda",["Obiwan",2]]],
471
+ ["Enemies", ["Palpatine",['Darth Vader',3]]]
472
+ ]
473
+ actual_html = select_tag( 'name', :grouped_options => opts )
474
+ assert_has_tag(:select, :name => "name") { actual_html }
475
+ assert_has_tag(:optgroup, :label => "Friends") { actual_html }
476
+ assert_has_tag(:option, :value => "Yoda", :content => "Yoda") { actual_html }
477
+ assert_has_tag(:option, :value => "2", :content => "Obiwan") { actual_html }
478
+ assert_has_tag(:optgroup, :label => "Enemies") { actual_html }
479
+ assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine") { actual_html }
480
+ assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html }
481
+ end
482
+
483
+ should "return a select tag with grouped options for a hash" do
484
+ opts = {
485
+ "Friends" => ["Yoda",["Obiwan",2]],
486
+ "Enemies" => ["Palpatine",['Darth Vader',3]]
487
+ }
488
+ actual_html = select_tag( 'name', :grouped_options => opts )
489
+ assert_has_tag(:select, :name => "name") { actual_html }
490
+ assert_has_tag(:optgroup, :label => "Friends") { actual_html }
491
+ assert_has_tag(:option, :value => "Yoda", :content => "Yoda") { actual_html }
492
+ assert_has_tag(:option, :value => "2", :content => "Obiwan") { actual_html }
493
+ assert_has_tag(:optgroup, :label => "Enemies") { actual_html }
494
+ assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine") { actual_html }
495
+ assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html }
496
+ end
497
+
365
498
  should "display select tag in ruby with multiple attribute" do
366
499
  actual_html = select_tag(:favorite_color, :multiple => true, :options => ['only', 'option'])
367
500
  assert_has_tag(:select, :multiple => 'multiple', :name => 'favorite_color[]') { actual_html }
@@ -418,6 +551,18 @@ class TestFormHelpers < Test::Unit::TestCase
418
551
  assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
419
552
  assert_have_selector('select option', :content => 'purple', :value => '3')
420
553
  end
554
+
555
+ should "display select tag in slim" do
556
+ visit '/slim/form_tag'
557
+ assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
558
+ assert_have_selector('select option', :content => 'green', :value => 'green')
559
+ assert_have_selector('select option', :content => 'orange', :value => 'orange')
560
+ assert_have_selector('select option', :content => 'purple', :value => 'purple')
561
+ assert_have_selector 'form.advanced-form select', :name => 'fav_color'
562
+ assert_have_selector('select option', :content => 'green', :value => '1')
563
+ assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
564
+ assert_have_selector('select option', :content => 'purple', :value => '3')
565
+ end
421
566
  end
422
567
 
423
568
  context 'for #submit_tag method' do
@@ -437,6 +582,12 @@ class TestFormHelpers < Test::Unit::TestCase
437
582
  assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
438
583
  assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
439
584
  end
585
+
586
+ should "display submit tag in slim" do
587
+ visit '/slim/form_tag'
588
+ assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
589
+ assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
590
+ end
440
591
  end
441
592
 
442
593
  context 'for #button_tag method' do
@@ -454,6 +605,11 @@ class TestFormHelpers < Test::Unit::TestCase
454
605
  visit '/haml/form_tag'
455
606
  assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
456
607
  end
608
+
609
+ should "display submit tag in slim" do
610
+ visit '/slim/form_tag'
611
+ assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
612
+ end
457
613
  end
458
614
 
459
615
  context 'for #image_submit_tag method' do
@@ -480,5 +636,10 @@ class TestFormHelpers < Test::Unit::TestCase
480
636
  visit '/haml/form_tag'
481
637
  assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
482
638
  end
639
+
640
+ should "display image submit tag in slim" do
641
+ visit '/slim/form_tag'
642
+ assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
643
+ end
483
644
  end
484
645
  end