formtastic-bootstrap 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/Gemfile +5 -3
  2. data/Gemfile.lock +72 -60
  3. data/README.md +4 -1
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/formtastic-bootstrap.gemspec +49 -16
  7. data/lib/formtastic-bootstrap/actions/base.rb +22 -0
  8. data/lib/formtastic-bootstrap/actions/button_action.rb +13 -0
  9. data/lib/formtastic-bootstrap/actions/input_action.rb +13 -0
  10. data/lib/formtastic-bootstrap/actions/link_action.rb +12 -0
  11. data/lib/formtastic-bootstrap/actions.rb +10 -0
  12. data/lib/formtastic-bootstrap/form_builder.rb +4 -2
  13. data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
  14. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +24 -0
  15. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +2 -4
  16. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -2
  17. data/lib/formtastic-bootstrap/helpers.rb +6 -8
  18. data/lib/formtastic-bootstrap/inputs/base/choices.rb +6 -35
  19. data/lib/formtastic-bootstrap/inputs/base/collections.rb +9 -0
  20. data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +9 -0
  21. data/lib/formtastic-bootstrap/inputs/base/hints.rb +1 -1
  22. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +14 -3
  23. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +9 -0
  24. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +4 -5
  25. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +38 -18
  26. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +22 -34
  27. data/lib/formtastic-bootstrap/inputs/base.rb +29 -6
  28. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +14 -18
  29. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +16 -11
  30. data/lib/formtastic-bootstrap/inputs/date_input.rb +3 -9
  31. data/lib/formtastic-bootstrap/inputs/date_select_input.rb +8 -0
  32. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +3 -12
  33. data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +8 -0
  34. data/lib/formtastic-bootstrap/inputs/email_input.rb +1 -1
  35. data/lib/formtastic-bootstrap/inputs/file_input.rb +1 -1
  36. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +1 -1
  37. data/lib/formtastic-bootstrap/inputs/number_input.rb +3 -3
  38. data/lib/formtastic-bootstrap/inputs/password_input.rb +1 -1
  39. data/lib/formtastic-bootstrap/inputs/phone_input.rb +1 -1
  40. data/lib/formtastic-bootstrap/inputs/radio_input.rb +28 -14
  41. data/lib/formtastic-bootstrap/inputs/range_input.rb +1 -1
  42. data/lib/formtastic-bootstrap/inputs/search_input.rb +1 -1
  43. data/lib/formtastic-bootstrap/inputs/select_input.rb +3 -1
  44. data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -7
  45. data/lib/formtastic-bootstrap/inputs/text_input.rb +1 -1
  46. data/lib/formtastic-bootstrap/inputs/time_input.rb +3 -9
  47. data/lib/formtastic-bootstrap/inputs/time_select_input.rb +8 -0
  48. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +1 -1
  49. data/lib/formtastic-bootstrap/inputs/url_input.rb +1 -1
  50. data/lib/formtastic-bootstrap/inputs.rb +30 -23
  51. data/lib/formtastic-bootstrap.rb +16 -1
  52. data/spec/actions/button_action_spec.rb +63 -0
  53. data/spec/actions/input_action_spec.rb +59 -0
  54. data/spec/actions/link_action_spec.rb +92 -0
  55. data/spec/helpers/action_helper_spec.rb +368 -0
  56. data/spec/helpers/actions_helper_spec.rb +147 -0
  57. data/spec/helpers/input_helper_spec.rb +238 -259
  58. data/spec/helpers/inputs_helper_spec.rb +84 -25
  59. data/spec/inputs/boolean_input_spec.rb +108 -75
  60. data/spec/inputs/check_boxes_input_spec.rb +106 -91
  61. data/spec/inputs/date_select_input_spec.rb +164 -0
  62. data/spec/inputs/datetime_select_input_spec.rb +112 -0
  63. data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +48 -0
  64. data/spec/inputs/email_input_spec.rb +30 -3
  65. data/spec/inputs/file_input_spec.rb +31 -4
  66. data/spec/inputs/hidden_input_spec.rb +63 -32
  67. data/spec/inputs/number_input_spec.rb +37 -8
  68. data/spec/inputs/password_input_spec.rb +30 -3
  69. data/spec/inputs/phone_input_spec.rb +30 -3
  70. data/spec/inputs/radio_input_spec.rb +87 -60
  71. data/spec/inputs/range_input_spec.rb +32 -5
  72. data/spec/inputs/search_input_spec.rb +29 -3
  73. data/spec/inputs/select_input_spec.rb +164 -107
  74. data/spec/inputs/string_input_spec.rb +33 -22
  75. data/spec/inputs/text_input_spec.rb +39 -14
  76. data/spec/inputs/time_select_input_spec.rb +191 -0
  77. data/spec/inputs/time_zone_input_spec.rb +17 -19
  78. data/spec/inputs/url_input_spec.rb +30 -3
  79. data/spec/spec_helper.rb +21 -15
  80. data/spec/support/custom_macros.rb +61 -228
  81. data/spec/support/fb_custom_macros.rb +23 -0
  82. metadata +109 -28
  83. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +0 -52
  84. data/spec/builder/errors_spec.rb +0 -214
  85. data/spec/helpers/buttons_helper_spec.rb +0 -149
  86. data/spec/inputs/date_input_spec.rb +0 -147
  87. data/spec/inputs/datetime_input_spec.rb +0 -101
  88. data/spec/inputs/time_input_spec.rb +0 -206
  89. data/spec/support/depracation.rb +0 -6
  90. data/spec/support/formtastic_spec_helper.rb +0 -382
@@ -1,14 +1,13 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Formtastic::FormBuilder#inputs' do
4
+ describe 'FormtasticBootstrap::FormBuilder#inputs' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
  end
13
12
 
14
13
  describe 'with a block (block forms syntax)' do
@@ -33,13 +32,11 @@ describe 'Formtastic::FormBuilder#inputs' do
33
32
  end
34
33
 
35
34
  it 'should not render an ol inside the fieldset' do
36
- # output_buffer.should have_tag("form fieldset.inputs ol")
37
35
  output_buffer.should_not have_tag("form fieldset.inputs ol")
38
36
  end
39
37
 
40
- it 'should render the contents of the block inside the fieldset' do
41
- # output_buffer.should have_tag("form fieldset.inputs ol", /hello/)
42
- output_buffer.should have_tag("form fieldset.inputs", /hello/)
38
+ it 'should not render the contents of the block inside the ol' do
39
+ output_buffer.should_not have_tag("form fieldset.inputs ol", /hello/)
43
40
  end
44
41
 
45
42
  it 'should not render a legend inside the fieldset' do
@@ -125,6 +122,18 @@ describe 'Formtastic::FormBuilder#inputs' do
125
122
  output_buffer.should have_tag("form input[@name='post[authors_attributes][1][login]']")
126
123
  output_buffer.should_not have_tag('form fieldset[@name]')
127
124
  end
125
+
126
+ it 'should include an indexed :label input for each item' do
127
+ concat(semantic_form_for(@new_post) do |post|
128
+ post.inputs :for => :authors do |author, index|
129
+ concat(author.input(:login, :label => "#{index}", :required => false))
130
+ end
131
+ end)
132
+
133
+ output_buffer.should have_tag("form fieldset.inputs label", "1", :count => 1)
134
+ output_buffer.should have_tag("form fieldset.inputs label", "2", :count => 1)
135
+ output_buffer.should_not have_tag('form fieldset legend')
136
+ end
128
137
  end
129
138
 
130
139
  describe 'as an array containing the a symbole for the association name and the associated object' do
@@ -176,7 +185,7 @@ describe 'Formtastic::FormBuilder#inputs' do
176
185
  concat(inputs)
177
186
  end)
178
187
 
179
- output_buffer.should have_tag('form fieldset div.clearfix div.input #post_author_attributes_10_login')
188
+ output_buffer.should have_tag('form fieldset #post_author_attributes_10_login')
180
189
  end
181
190
 
182
191
  it 'should not add builder as a fieldset attribute tag' do
@@ -190,7 +199,7 @@ describe 'Formtastic::FormBuilder#inputs' do
190
199
  output_buffer.should_not have_tag('fieldset[@builder="Formtastic::Helpers::FormHelper"]')
191
200
  end
192
201
 
193
- it 'should send parent_builder as an option to allow child index interpolation' do
202
+ it 'should send parent_builder as an option to allow child index interpolation for legends' do
194
203
  concat(semantic_form_for(@new_post) do |builder|
195
204
  builder.instance_variable_set('@nested_child_index', 0)
196
205
  inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
@@ -202,7 +211,7 @@ describe 'Formtastic::FormBuilder#inputs' do
202
211
  output_buffer.should have_tag('fieldset legend', 'Author #1')
203
212
  end
204
213
 
205
- it 'should also provide child index interpolation when nested child index is a hash' do
214
+ it 'should also provide child index interpolation for legends when nested child index is a hash' do
206
215
  concat(semantic_form_for(@new_post) do |builder|
207
216
  builder.instance_variable_set('@nested_child_index', :author => 10)
208
217
  inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
@@ -213,6 +222,30 @@ describe 'Formtastic::FormBuilder#inputs' do
213
222
 
214
223
  output_buffer.should have_tag('fieldset legend', 'Author #11')
215
224
  end
225
+
226
+ it 'should send parent_builder as an option to allow child index interpolation for labels' do
227
+ concat(semantic_form_for(@new_post) do |builder|
228
+ builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 0)
229
+ inputs = builder.inputs :for => [:author, @bob] do |bob_builder, index|
230
+ concat(bob_builder.input(:name, :label => "Author ##{index}", :required => false))
231
+ end
232
+ concat(inputs)
233
+ end)
234
+
235
+ output_buffer.should have_tag('fieldset label', 'Author #1')
236
+ end
237
+
238
+ it 'should also provide child index interpolation for labels when nested child index is a hash' do
239
+ concat(semantic_form_for(@new_post) do |builder|
240
+ builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 10)
241
+ inputs = builder.inputs :for => [:author, @bob] do |bob_builder, index|
242
+ concat(bob_builder.input(:name, :label => "Author ##{index}", :required => false))
243
+ end
244
+ concat(inputs)
245
+ end)
246
+
247
+ output_buffer.should have_tag('fieldset label', 'Author #11')
248
+ end
216
249
  end
217
250
 
218
251
  describe 'when a :name or :title option is provided' do
@@ -346,26 +379,26 @@ describe 'Formtastic::FormBuilder#inputs' do
346
379
  output_buffer.should_not have_tag('form > fieldset.inputs > ol')
347
380
  end
348
381
 
349
- it 'should render a div item in the ol for each column and reflection' do
382
+ it 'should not render a list item in the ol for each column and reflection' do
350
383
  # Remove the :has_many macro and :created_at column
351
384
  count = ::Post.content_columns.size + ::Post.reflections.size - 2
352
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix', :count => count)
385
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li', :count => count)
353
386
  end
354
387
 
355
- it 'should render a string list item for title' do
356
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix.string')
388
+ it 'should not render a string list item for title' do
389
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
357
390
  end
358
-
359
- it 'should render a text list item for body' do
360
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix.text')
391
+
392
+ it 'should not render a text list item for body' do
393
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.text')
361
394
  end
362
395
 
363
- it 'should render a select list item for author_id' do
364
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix.select', :count => 1)
396
+ it 'should not render a select list item for author_id' do
397
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
365
398
  end
366
399
 
367
400
  it 'should not render timestamps inputs by default' do
368
- output_buffer.should_not have_tag('form > fieldset.inputs > div.clearfix.datetime')
401
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.datetime')
369
402
  end
370
403
 
371
404
  context "with a polymorphic association" do
@@ -397,9 +430,12 @@ describe 'Formtastic::FormBuilder#inputs' do
397
430
  concat(builder.inputs(:title, :body))
398
431
  end)
399
432
 
400
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix', :count => 2)
401
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix.string')
402
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix.text')
433
+ output_buffer.should have_tag('form > fieldset.inputs input', :count => 1)
434
+ output_buffer.should have_tag('form > fieldset.inputs textarea', :count => 1)
435
+
436
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li', :count => 2)
437
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
438
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.text')
403
439
  end
404
440
  end
405
441
 
@@ -409,7 +445,9 @@ describe 'Formtastic::FormBuilder#inputs' do
409
445
  concat(builder.inputs(:title, :body))
410
446
  end)
411
447
 
412
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix.string', :count => 2)
448
+ output_buffer.should have_tag('form > fieldset.inputs input', :count => 2)
449
+
450
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
413
451
  end
414
452
  end
415
453
 
@@ -472,8 +510,9 @@ describe 'Formtastic::FormBuilder#inputs' do
472
510
  end)
473
511
  end
474
512
 
475
- it 'should render a form with a fieldset containing two list items' do
476
- output_buffer.should have_tag('form > fieldset.inputs > div.clearfix', :count => 4)
513
+ it 'should not render a form with a fieldset containing two list items' do
514
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li', :count => 4)
515
+ output_buffer.should_not have_tag('form > fieldset.inputs input', :count => 4)
477
516
  end
478
517
 
479
518
  it 'should pass the options down to the fieldset' do
@@ -508,6 +547,7 @@ describe 'Formtastic::FormBuilder#inputs' do
508
547
  end)
509
548
  end)
510
549
  end)
550
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
511
551
  output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
512
552
  end
513
553
  end
@@ -520,6 +560,7 @@ describe 'Formtastic::FormBuilder#inputs' do
520
560
  end)
521
561
  end)
522
562
  end)
563
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
523
564
  output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
524
565
  end
525
566
  end
@@ -531,6 +572,7 @@ describe 'Formtastic::FormBuilder#inputs' do
531
572
  concat(builder.inputs(:title))
532
573
  end)
533
574
  end)
575
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
534
576
  output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
535
577
  end
536
578
  end
@@ -542,6 +584,7 @@ describe 'Formtastic::FormBuilder#inputs' do
542
584
  concat(builder.inputs(:name, :for => :author))
543
585
  end)
544
586
  end)
587
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
545
588
  output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
546
589
  end
547
590
  end
@@ -556,9 +599,25 @@ describe 'Formtastic::FormBuilder#inputs' do
556
599
  end)
557
600
  end)
558
601
  end)
602
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol > li > fieldset.inputs > ol')
559
603
  output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs > fieldset.inputs')
560
604
  end
561
605
  end
606
+
607
+ context "when several are nested" do
608
+ it "should wrap each of the nested inputs in an li block to maintain HTML validity" do
609
+ concat(semantic_form_for(@new_post) do |builder|
610
+ concat(builder.inputs do
611
+ concat(builder.inputs do
612
+ end)
613
+ concat(builder.inputs do
614
+ end)
615
+ end)
616
+ end)
617
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
618
+ output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs', :count => 2)
619
+ end
620
+ end
562
621
 
563
622
  end
564
623
 
@@ -8,149 +8,152 @@ describe 'boolean input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
 
13
12
  concat(semantic_form_for(@new_post) do |builder|
14
13
  concat(builder.input(:allow_comments, :as => :boolean))
15
14
  end)
16
15
  end
17
16
 
17
+ it_should_have_bootstrap_horizontal_wrapping
18
+ it_should_have_bootstrap_controls_label_with("checkbox")
18
19
  it_should_have_input_wrapper_with_class("boolean")
19
- it_should_have_input_wrapper_with_class(:clearfix)
20
- it_should_have_input_class_in_the_right_place
20
+ it_should_have_input_wrapper_with_class(:input)
21
21
  it_should_have_input_wrapper_with_id("post_allow_comments_input")
22
- it_should_apply_error_logic_for_input_type(:boolean, :block)
23
-
22
+ it_should_apply_error_logic_for_input_type(:boolean)
23
+
24
24
  it 'should generate a label containing the input' do
25
25
  output_buffer.should_not have_tag('label.label')
26
-
27
-
28
- output_buffer.should have_tag('form div.clearfix div.input ul li label', :count => 1)
29
- output_buffer.should have_tag('form div.clearfix div.input ul li label[@for="post_allow_comments"]')
30
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /Allow comments/)
31
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]', :count => 1)
32
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"]', :count => 1)
33
- output_buffer.should_not have_tag('form div.clearfix label input[@type="hidden"]', :count => 1) # invalid HTML5
34
- end
35
-
26
+ output_buffer.should have_tag('form div.control-group div.controls label', :count => 1)
27
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', :count => 1)
28
+ output_buffer.should have_tag('form div.control-group div.controls label[@for="post_allow_comments"]')
29
+ output_buffer.should have_tag('form div.control-group div.controls label', /Allow comments/)
30
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]', :count => 1)
31
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"]', :count => 1)
32
+ output_buffer.should_not have_tag('form div.control-group div.controls label input[@type="hidden"]', :count => 1) # invalid HTML5
33
+ end
34
+
35
+ it 'should not add a "name" attribute to the label' do
36
+ output_buffer.should_not have_tag('form div.control-group div.controls label[@name]')
37
+ end
38
+
36
39
  it 'should generate a checkbox input' do
37
- output_buffer.should have_tag('form div.clearfix div.input ul li label input')
38
- output_buffer.should have_tag('form div.clearfix div.input ul li label input#post_allow_comments')
39
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]')
40
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@name="post[allow_comments]"]')
41
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="1"]')
40
+ output_buffer.should have_tag('form div.control-group div.controls label input')
41
+ output_buffer.should have_tag('form div.control-group div.controls label input#post_allow_comments')
42
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]')
43
+ output_buffer.should have_tag('form div.control-group div.controls label input[@name="post[allow_comments]"]')
44
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="1"]')
42
45
  end
43
-
46
+
44
47
  it 'should generate a checked input if object.method returns true' do
45
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@checked="checked"]')
46
- output_buffer.should have_tag('form div.clearfix input[@name="post[allow_comments]"]', :count => 2)
47
- output_buffer.should have_tag('form div.clearfix div.input ul li input#post_allow_comments', :count => 1)
48
+ output_buffer.should have_tag('form div.control-group div.controls label input[@checked="checked"]')
49
+ output_buffer.should have_tag('form div.control-group input[@name="post[allow_comments]"]', :count => 2)
50
+ output_buffer.should have_tag('form div.control-group div.controls input#post_allow_comments', :count => 1)
48
51
  end
49
-
52
+
50
53
  it 'should generate a checked input if :input_html is passed :checked => checked' do
51
54
  concat(semantic_form_for(@new_post) do |builder|
52
55
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
53
56
  end)
54
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@checked="checked"]')
57
+ output_buffer.should have_tag('form div.control-group div.controls label input[@checked="checked"]')
55
58
  end
56
-
59
+
57
60
  it 'should name the hidden input with the :name html_option' do
58
61
  concat(semantic_form_for(@new_post) do |builder|
59
62
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
60
63
  end)
61
-
62
- output_buffer.should have_tag('form div.clearfix div.input ul li input[@type="checkbox"][@name="foo"]', :count => 1)
63
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@name="foo"]', :count => 1)
64
+
65
+ output_buffer.should have_tag('form div.control-group input[@type="checkbox"][@name="foo"]', :count => 1)
66
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="foo"]', :count => 1)
64
67
  end
65
-
68
+
66
69
  it 'should name the hidden input with the :name html_option' do
67
70
  concat(semantic_form_for(@new_post) do |builder|
68
71
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
69
72
  end)
70
-
71
- output_buffer.should have_tag('form div.clearfix div.input ul li input[@type="checkbox"][@name="foo"]', :count => 1)
72
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@name="foo"]', :count => 1)
73
+
74
+ output_buffer.should have_tag('form div.control-group input[@type="checkbox"][@name="foo"]', :count => 1)
75
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="foo"]', :count => 1)
73
76
  end
74
77
 
75
78
  it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
76
79
  concat(semantic_form_for(@new_post) do |builder|
77
80
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
78
81
  end)
79
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@disabled="disabled"]', :count => 1)
80
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@disabled="disabled"]', :count => 1)
82
+ output_buffer.should have_tag('form div.control-group label.checkbox input[@disabled="disabled"]', :count => 1)
83
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@disabled="disabled"]', :count => 1)
81
84
  end
82
85
 
83
86
  it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
84
87
  concat(semantic_form_for(@new_post) do |builder|
85
88
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
86
89
  end)
87
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@id="custom_id"]')
88
- output_buffer.should have_tag('form div.clearfix div.input ul li label[@for="custom_id"]')
90
+ output_buffer.should have_tag('form div.control-group div.controls label input[@id="custom_id"]')
91
+ output_buffer.should have_tag('form div.control-group div.controls label[@for="custom_id"]')
89
92
  end
90
-
93
+
91
94
  it 'should allow checked and unchecked values to be sent' do
92
95
  concat(semantic_form_for(@new_post) do |builder|
93
96
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
94
97
  end)
95
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
96
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@value="unchecked"]')
97
- output_buffer.should_not have_tag('form div.clearfix label input[@type="hidden"]') # invalid HTML5
98
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
99
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@value="unchecked"]')
100
+ output_buffer.should_not have_tag('form div.control-group div.controls label input[@type="hidden"]') # invalid HTML5
98
101
  end
99
-
102
+
100
103
  it 'should generate a checked input if object.method returns checked value' do
101
104
  @new_post.stub!(:allow_comments).and_return('yes')
102
-
105
+
103
106
  concat(semantic_form_for(@new_post) do |builder|
104
107
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
105
108
  end)
106
-
107
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
109
+
110
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"][@checked="checked"]')
108
111
  end
109
-
112
+
110
113
  it 'should not generate a checked input if object.method returns unchecked value' do
111
114
  @new_post.stub!(:allow_comments).and_return('no')
112
-
115
+
113
116
  concat(semantic_form_for(@new_post) do |builder|
114
117
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
115
118
  end)
116
-
117
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="yes"]:not([@checked])')
119
+
120
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"]:not([@checked])')
118
121
  end
119
-
122
+
120
123
  it 'should generate a checked input if object.method returns checked value' do
121
124
  @new_post.stub!(:allow_comments).and_return('yes')
122
-
125
+
123
126
  concat(semantic_form_for(@new_post) do |builder|
124
127
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
125
128
  end)
126
-
127
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
129
+
130
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"][@checked="checked"]')
128
131
  end
129
-
132
+
130
133
  it 'should not generate a checked input if object.method returns unchecked value' do
131
134
  @new_post.stub!(:allow_comments).and_return('no')
132
-
135
+
133
136
  concat(semantic_form_for(@new_post) do |builder|
134
137
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
135
138
  end)
136
-
137
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="yes"]:not([@checked])')
139
+
140
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"]:not([@checked])')
138
141
  end
139
-
142
+
140
143
  it 'should generate a label and a checkbox even if no object is given' do
141
144
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
142
145
  concat(builder.input(:allow_comments, :as => :boolean))
143
146
  end)
144
-
145
- output_buffer.should have_tag('form div.clearfix div.input ul li label[@for="project_allow_comments"]')
146
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /Allow comments/)
147
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]')
148
-
149
- output_buffer.should have_tag('form div.clearfix div.input ul li label input#project_allow_comments')
150
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]')
151
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@name="project[allow_comments]"]')
152
- end
153
-
147
+
148
+ output_buffer.should have_tag('form div.control-group div.controls label[@for="project_allow_comments"]')
149
+ output_buffer.should have_tag('form div.control-group div.controls label', /Allow comments/)
150
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]')
151
+
152
+ output_buffer.should have_tag('form div.control-group div.controls label input#project_allow_comments')
153
+ output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]')
154
+ output_buffer.should have_tag('form div.control-group div.controls label input[@name="project[allow_comments]"]')
155
+ end
156
+
154
157
  context "when required" do
155
158
 
156
159
  it "should add the required attribute to the input's html options" do
@@ -172,22 +175,52 @@ describe 'boolean input' do
172
175
  end
173
176
 
174
177
  end
175
-
178
+
176
179
  describe "when namespace is provided" do
177
-
180
+
178
181
  before do
179
182
  @output_buffer = ''
180
183
  mock_everything
181
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
182
-
184
+
183
185
  concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
184
186
  concat(builder.input(:allow_comments, :as => :boolean))
185
187
  end)
186
188
  end
187
-
189
+
188
190
  it_should_have_input_wrapper_with_id("context2_post_allow_comments_input")
189
191
  it_should_have_an_inline_label_for("context2_post_allow_comments")
190
-
192
+
193
+ end
194
+
195
+ describe "when index is provided" do
196
+
197
+ before do
198
+ @output_buffer = ''
199
+ mock_everything
200
+
201
+ concat(semantic_form_for(@new_post) do |builder|
202
+ concat(builder.fields_for(:author, :index => 3) do |author|
203
+ concat(author.input(:name, :as => :boolean))
204
+ end)
205
+ end)
206
+ end
207
+
208
+ it 'should index the id of the wrapper' do
209
+ output_buffer.should have_tag("div#post_author_attributes_3_name_input")
210
+ end
211
+
212
+ it 'should index the id of the input tag' do
213
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
214
+ end
215
+
216
+ it 'should index the name of the hidden input' do
217
+ output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
218
+ end
219
+
220
+ it 'should index the name of the checkbox input' do
221
+ output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
222
+ end
223
+
191
224
  end
192
225
 
193
226
  end