formtastic-bootstrap 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -9,109 +9,94 @@ describe 'check_boxes input' do
9
9
  before do
10
10
  @output_buffer = ''
11
11
  mock_everything
12
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
13
-
12
+
14
13
  concat(semantic_form_for(@fred) do |builder|
15
14
  concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :required => true))
16
15
  end)
17
16
  end
18
17
 
18
+ it_should_have_bootstrap_horizontal_wrapping
19
19
  it_should_have_input_wrapper_with_class("check_boxes")
20
- it_should_have_input_wrapper_with_class(:clearfix)
21
- it_should_have_input_class_in_the_right_place
20
+ it_should_have_input_wrapper_with_class(:input)
22
21
  it_should_have_input_wrapper_with_id("author_posts_input")
23
- it_should_have_a_nested_div
24
- it_should_have_a_nested_div_with_class('choices.input')
25
- it_should_have_a_nested_unordered_list_with_class('choices-group.inputs-list')
26
- it_should_apply_error_logic_for_input_type(:check_boxes, :block)
22
+ # it_should_have_a_nested_fieldset
23
+ # it_should_have_a_nested_fieldset_with_class('choices')
24
+ # it_should_have_a_nested_ordered_list_with_class('choices-group')
25
+ it_should_have_bootstrap_controls_label_with("checkbox")
26
+ it_should_apply_error_logic_for_input_type(:check_boxes)
27
27
  it_should_call_find_on_association_class_when_no_collection_is_provided(:check_boxes)
28
28
  it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
29
29
 
30
- # TODO Refactor out the next three tests and their bretheren in radio_input_spec
31
- it 'should generate a \'legend\' containing a label with text for the input' do
32
- output_buffer.should have_tag('form div.clearfix label')
33
- output_buffer.should have_tag('form div.clearfix label', /Posts/)
30
+ it 'should generate a control label with text for the input' do
31
+ output_buffer.should have_tag('form div.control-group > label.control-label')
32
+ output_buffer.should have_tag('form div.control-group > label.control-label', /Posts/)
34
33
  end
35
34
 
36
- it 'should not link the \'legend\' label to any input' do
37
- output_buffer.should_not have_tag('form div.clearfix > label[@for]')
35
+ it 'should not link the label within the legend to any input' do
36
+ output_buffer.should_not have_tag('form div.control-group > label[@for^="author_post_ids_"]')
38
37
  end
39
38
 
40
- it 'should generate an unordered list with a list item for each choice' do
41
- output_buffer.should have_tag('form div.clearfix div.input ul')
42
- output_buffer.should have_tag('form div.clearfix div.input ul li.choice', :count => ::Post.all.size)
39
+ it 'should not generate an ordered list with an li.choice for each choice' do
40
+ output_buffer.should_not have_tag('form li fieldset ol')
41
+ output_buffer.should_not have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
43
42
  end
44
43
 
45
- # it 'should generate a legend containing a label with text for the input' do
46
- # output_buffer.should have_tag('form li fieldset legend.label label')
47
- # output_buffer.should have_tag('form li fieldset legend.label label', /Posts/)
48
- # end
49
- #
50
- # it 'should not link the label within the legend to any input' do
51
- # output_buffer.should_not have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
52
- # end
53
- #
54
- # it 'should generate an ordered list with an li.choice for each choice' do
55
- # output_buffer.should have_tag('form li fieldset ol')
56
- # output_buffer.should have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
57
- # end
58
-
59
44
  it 'should have one option with a "checked" attribute' do
60
- output_buffer.should have_tag('form li input[@checked]', :count => 1)
45
+ output_buffer.should have_tag('form div.control-group div.controls input[@checked]', :count => 1)
61
46
  end
62
47
 
63
48
  it 'should not generate hidden inputs with default value blank' do
64
- output_buffer.should_not have_tag("form div div ul li label input[@type='hidden'][@value='']")
49
+ output_buffer.should_not have_tag("form div.control-group div.controls label input[@type='hidden'][@value='']")
65
50
  end
66
51
 
67
- it 'should not render hidden inputs inside the ol' do
68
- output_buffer.should_not have_tag("form div div ul li input[@type='hidden']")
52
+ it 'should not render hidden inputs inside div.controls' do
53
+ output_buffer.should_not have_tag("form div.controls input[@type='hidden']")
69
54
  end
70
55
 
71
56
  it 'should render one hidden input for each choice outside the ol' do
72
- output_buffer.should have_tag("form div.clearfix > input[@type='hidden']", :count => 1)
57
+ output_buffer.should have_tag("form div.control-group > input[@type='hidden']", :count => 1)
73
58
  end
74
59
 
75
60
  describe "each choice" do
76
61
 
77
- it 'should not give the choice label the .label class' do
78
- output_buffer.should_not have_tag('li.choice label.label')
62
+ it 'should not give the choice label the label class' do
63
+ output_buffer.should_not have_tag('div.controls label.label')
79
64
  end
80
65
 
81
66
  it 'should not be marked as required' do
82
- output_buffer.should_not have_tag('li.choice input[@required]')
67
+ output_buffer.should_not have_tag('div.controls input[@required]')
83
68
  end
84
69
 
85
70
  it 'should contain a label for the radio input with a nested input and label text' do
86
71
  ::Post.all.each do |post|
87
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{post.to_label}/)
88
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='author_post_ids_#{post.id}']")
72
+ output_buffer.should have_tag('form div.control-group div.controls label', /#{post.to_label}/)
73
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='author_post_ids_#{post.id}']")
89
74
  end
90
75
  end
91
76
 
92
- it 'should use values as li.class when value_as_class is true' do
77
+ it 'should use values as label.class when value_as_class is true' do
93
78
  ::Post.all.each do |post|
94
- output_buffer.should have_tag("form div.clearfix div.input ul li.post_#{post.id} label")
79
+ output_buffer.should have_tag("form div.control-group div.controls label.post_#{post.id}")
95
80
  end
96
81
  end
97
82
 
98
83
  it 'should have a checkbox input but no hidden field for each post' do
99
84
  ::Post.all.each do |post|
100
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#author_post_ids_#{post.id}")
101
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='author[post_ids][]']", :count => 1)
85
+ output_buffer.should have_tag("form div.control-group div.controls label input#author_post_ids_#{post.id}")
86
+ output_buffer.should have_tag("form div.control-group div.controls label input[@name='author[post_ids][]']", :count => 1)
102
87
  end
103
88
  end
104
89
 
105
90
  it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
106
- output_buffer.should have_tag("form div.clearfix > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
91
+ output_buffer.should have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
107
92
  end
108
93
 
109
- it 'the hidden field with an empty array value should be followed by the div.input and the ul' do
110
- output_buffer.should have_tag("form div.clearfix > input[@type=hidden][@name='author[post_ids][]'][@value=''] + div.input ul", :count => 1)
94
+ it 'the hidden field with an empty array value should be followed by the div.controls' do
95
+ output_buffer.should have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids][]'][@value=''] + div.controls", :count => 1)
111
96
  end
112
97
 
113
98
  it 'should not have a hidden field with an empty string value for the collection' do
114
- output_buffer.should_not have_tag("form div.clearfix > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
99
+ output_buffer.should_not have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
115
100
  end
116
101
 
117
102
  it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
@@ -122,15 +107,15 @@ describe 'check_boxes input' do
122
107
  end)
123
108
 
124
109
  ::Post.all.each do |post|
125
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#author_post_ids_#{post.id}")
126
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='author[post_ids][]']", :count => 2)
110
+ output_buffer.should have_tag("form div.control-group div.controls label input#author_post_ids_#{post.id}")
111
+ output_buffer.should have_tag("form div.control-group div.controls label input[@name='author[post_ids][]']", :count => 2)
127
112
  end
128
113
 
129
114
  end
130
115
 
131
116
  it "should mark input as checked if it's the the existing choice" do
132
117
  ::Post.all.include?(@fred.posts.first).should be_true
133
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@checked='checked']")
118
+ output_buffer.should have_tag("form div.control-group div.controls label input[@checked='checked']")
134
119
  end
135
120
  end
136
121
 
@@ -142,27 +127,31 @@ describe 'check_boxes input' do
142
127
  end)
143
128
  end
144
129
 
145
- it 'should generate a top-level div with \'legend\'' do
146
- output_buffer.should have_tag('form div.clearfix > label', /Author/)
130
+ it 'should not generate a fieldset with legend' do
131
+ output_buffer.should_not have_tag('form li fieldset legend', /Author/)
147
132
  end
148
133
 
149
- it 'shold generate an li tag for each item in the collection' do
150
- output_buffer.should have_tag('form div.clearfix div.input ul li input[@type=checkbox]', :count => ::Author.all.size)
134
+ it 'should generate a div.control-group with a label' do
135
+ output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
136
+ end
137
+
138
+ it 'should not generate an li tag for each item in the collection' do
139
+ output_buffer.should_not have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
151
140
  end
152
141
 
153
142
  it 'should generate labels for each item' do
154
143
  ::Author.all.each do |author|
155
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{author.to_label}/)
156
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='project_author_id_#{author.id}']")
144
+ output_buffer.should have_tag('form div.control-group div.controls label', /#{author.to_label}/)
145
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='project_author_id_#{author.id}']")
157
146
  end
158
147
  end
159
148
 
160
149
  it 'should generate inputs for each item' do
161
150
  ::Author.all.each do |author|
162
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#project_author_id_#{author.id}")
163
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@type='checkbox']")
164
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='#{author.id}']")
165
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='project[author_id][]']")
151
+ output_buffer.should have_tag("form div.control-group div.controls label input#project_author_id_#{author.id}")
152
+ output_buffer.should have_tag("form div.control-group div.controls label input[@type='checkbox']")
153
+ output_buffer.should have_tag("form div.control-group div.controls label input[@value='#{author.id}']")
154
+ output_buffer.should have_tag("form div.control-group div.controls label input[@name='project[author_id][]']")
166
155
  end
167
156
  end
168
157
 
@@ -171,9 +160,8 @@ describe 'check_boxes input' do
171
160
  concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
172
161
  end)
173
162
 
174
- output_buffer.should have_tag('form div.clearfix div.input ul li label') do |label|
175
- # label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
176
- label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;/
163
+ output_buffer.should have_tag('form div.control-group div.controls label') do |label|
164
+ label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
177
165
  end
178
166
  end
179
167
  end
@@ -190,18 +178,18 @@ describe 'check_boxes input' do
190
178
 
191
179
  it 'should have a checkbox input for each post' do
192
180
  ::Post.all.each do |post|
193
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#author_post_ids_#{post.id}")
194
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
181
+ output_buffer.should have_tag("form div.control-group div.controls label input#author_post_ids_#{post.id}")
182
+ output_buffer.should have_tag("form div.control-group div.controls label input[@name='author[post_ids][]']", :count => ::Post.all.length)
195
183
  end
196
184
  end
197
185
 
198
186
  it "should mark input as checked if it's the the existing choice" do
199
187
  ::Post.all.include?(@fred.posts.first).should be_true
200
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@checked='checked']")
188
+ output_buffer.should have_tag("form div.control-group div.controls label input[@checked='checked']")
201
189
  end
202
190
 
203
191
  it 'should not generate empty hidden inputs' do
204
- output_buffer.should_not have_tag("form div.clearfix div.input ul li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
192
+ output_buffer.should_not have_tag("form div.control-group div.controls label input[@type='hidden'][@value='']", :count => ::Post.all.length)
205
193
  end
206
194
  end
207
195
 
@@ -220,7 +208,7 @@ describe 'check_boxes input' do
220
208
  end
221
209
 
222
210
  it 'should not have any disabled item(s)' do
223
- output_buffer.should_not have_tag("form div.clearfix div.input ul li label input[@disabled='disabled']")
211
+ output_buffer.should_not have_tag("form div.control-group div.controls label input[@disabled='disabled']")
224
212
  end
225
213
  end
226
214
 
@@ -234,9 +222,9 @@ describe 'check_boxes input' do
234
222
  end
235
223
 
236
224
  it "should have one item disabled; the specified one" do
237
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled']", :count => 1)
238
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
239
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled'][@value='#{@fred.id}']")
225
+ output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled']", :count => 1)
226
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_ids_#{@fred.id}']", /fred/i)
227
+ output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled'][@value='#{@fred.id}']")
240
228
  end
241
229
  end
242
230
 
@@ -250,11 +238,11 @@ describe 'check_boxes input' do
250
238
  end
251
239
 
252
240
  it "should have multiple items disabled; the specified ones" do
253
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled']", :count => 2)
254
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
255
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled'][@value='#{@bob.id}']")
256
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
257
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled'][@value='#{@fred.id}']")
241
+ output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled']", :count => 2)
242
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_ids_#{@bob.id}']", /bob/i)
243
+ output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled'][@value='#{@bob.id}']")
244
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_ids_#{@fred.id}']", /fred/i)
245
+ output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled'][@value='#{@fred.id}']")
258
246
  end
259
247
  end
260
248
 
@@ -277,7 +265,7 @@ describe 'check_boxes input' do
277
265
  end
278
266
 
279
267
  it "should do foo" do
280
- output_buffer.should have_tag("div.clearfix > label", /Translated/)
268
+ output_buffer.should have_tag("label.control-label", /Translated/)
281
269
  end
282
270
 
283
271
  end
@@ -291,7 +279,7 @@ describe 'check_boxes input' do
291
279
  end
292
280
 
293
281
  it "should output the correct label title" do
294
- output_buffer.should have_tag("div.clearfix > label", /The authors/)
282
+ output_buffer.should have_tag("label.control-label", /The authors/)
295
283
  end
296
284
  end
297
285
 
@@ -304,8 +292,8 @@ describe 'check_boxes input' do
304
292
  end)
305
293
  end
306
294
 
307
- it "should output an empty \'legend\'" do
308
- output_buffer.should have_tag("div.clearfix > label", "")
295
+ it "should not output the legend" do
296
+ output_buffer.should_not have_tag("label.control-label")
309
297
  end
310
298
 
311
299
  it "should not cause escaped HTML" do
@@ -323,7 +311,7 @@ describe 'check_boxes input' do
323
311
  end
324
312
 
325
313
  it "should output the correct label title" do
326
- output_buffer.should have_tag("div.clearfix > label abbr")
314
+ output_buffer.should have_tag("label.control-label abbr")
327
315
  end
328
316
  end
329
317
 
@@ -366,7 +354,7 @@ describe 'check_boxes input' do
366
354
  item.should_not_receive(:id)
367
355
  item.stub!(:custom_value).and_return('custom_value')
368
356
  item.should_receive(:custom_value).exactly(3).times
369
- @new_post.author.should_receive(:custom_value).exactly(3).times
357
+ @new_post.author.should_receive(:custom_value).exactly(1).times
370
358
  concat(semantic_form_for(@new_post) do |builder|
371
359
  concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
372
360
  end)
@@ -387,8 +375,8 @@ describe 'check_boxes input' do
387
375
  end
388
376
 
389
377
  it 'should check the correct checkboxes' do
390
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='fiction'][@checked='checked']")
391
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='biography'][@checked='checked']")
378
+ output_buffer.should have_tag("form div.control-group div.controls label input[@value='fiction'][@checked='checked']")
379
+ output_buffer.should have_tag("form div.control-group div.controls label input[@value='biography'][@checked='checked']")
392
380
  end
393
381
  end
394
382
 
@@ -404,20 +392,47 @@ describe 'check_boxes input' do
404
392
  end
405
393
 
406
394
  it "should have a label for #context2_author_post_ids_19" do
407
- output_buffer.should have_tag("form li label[@for='context2_author_post_ids_19']")
395
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='context2_author_post_ids_19']")
408
396
  end
409
397
 
410
398
  it_should_have_input_with_id('context2_author_post_ids_19')
411
399
  it_should_have_input_wrapper_with_id("context2_author_posts_input")
412
400
  end
401
+
402
+ describe "when index is provided" do
403
+
404
+ before do
405
+ @output_buffer = ''
406
+ mock_everything
407
+
408
+ concat(semantic_form_for(@fred) do |builder|
409
+ concat(builder.fields_for(@fred.posts.first, :index => 3) do |author|
410
+ concat(author.input(:authors, :as => :check_boxes))
411
+ end)
412
+ end)
413
+ end
414
+
415
+ it 'should index the id of the control-group wrapper' do
416
+ output_buffer.should have_tag("div.control-group#author_post_3_authors_input")
417
+ end
418
+
419
+ it 'should index the id of the input tag' do
420
+ output_buffer.should have_tag("input#author_post_3_author_ids_42")
421
+ end
422
+
423
+ it 'should index the name of the checkbox input' do
424
+ output_buffer.should have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
425
+ end
426
+
427
+ end
428
+
413
429
 
414
430
  describe "when collection is an array" do
415
431
  before do
416
432
  @output_buffer = ''
417
433
  @_collection = [["First", 1], ["Second", 2]]
418
434
  mock_everything
419
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
420
-
435
+
421
436
  concat(semantic_form_for(@fred) do |builder|
422
437
  concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
423
438
  end)
@@ -425,8 +440,8 @@ describe 'check_boxes input' do
425
440
 
426
441
  it "should use array items for labels and values" do
427
442
  @_collection.each do |post|
428
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{post.first}/)
429
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='author_post_ids_#{post.last}']")
443
+ output_buffer.should have_tag('form div.control-group div.controls label', /#{post.first}/)
444
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='author_post_ids_#{post.last}']")
430
445
  end
431
446
  end
432
447
 
@@ -0,0 +1,164 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'date select input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "general" do
14
+
15
+ before do
16
+ output_buffer.replace ''
17
+ concat(semantic_form_for(@new_post) do |builder|
18
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month, :day]))
19
+ end)
20
+ end
21
+
22
+ it_should_have_bootstrap_horizontal_wrapping
23
+ it_should_have_input_wrapper_with_class("date_select")
24
+ it_should_have_input_wrapper_with_class(:input)
25
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
26
+ it_should_apply_error_logic_for_input_type(:date_select)
27
+
28
+ it 'should have a label with the label text inside the control-group' do
29
+ output_buffer.should have_tag('form div.control-group > label.control-label', /Publish at/)
30
+ output_buffer.should have_tag('form div.control-group label.control-label[@for="post_publish_at"]')
31
+ end
32
+
33
+ it 'should not associate the legend label with the first select' do
34
+ output_buffer.should_not have_tag('form div.control-group label.control-label[@for="post_publish_at_1i"]')
35
+ end
36
+
37
+ it 'should not have three labels for year, month and day' do
38
+ output_buffer.should_not have_tag('form div.control-group div.controls label', :count => 3)
39
+ output_buffer.should_not have_tag('form div.control-group div.controls label', /year/i)
40
+ output_buffer.should_not have_tag('form div.control-group div.controls label', /month/i)
41
+ output_buffer.should_not have_tag('form div.control-group div.controls label', /day/i)
42
+ end
43
+
44
+ it 'should have three selects for year, month and day' do
45
+ output_buffer.should have_tag('form div.control-group div.controls select', :count => 3)
46
+ end
47
+ end
48
+
49
+ describe "when namespace is provided" do
50
+
51
+ before do
52
+ output_buffer.replace ''
53
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
54
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month, :day]))
55
+ end)
56
+ end
57
+
58
+ it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
59
+ it_should_have_select_with_id("context2_post_publish_at_1i")
60
+ it_should_have_select_with_id("context2_post_publish_at_2i")
61
+ it_should_have_select_with_id("context2_post_publish_at_3i")
62
+
63
+ end
64
+
65
+ describe "when index is provided" do
66
+
67
+ before do
68
+ @output_buffer = ''
69
+ mock_everything
70
+
71
+ concat(semantic_form_for(@new_post) do |builder|
72
+ concat(builder.fields_for(:author, :index => 3) do |author|
73
+ concat(author.input(:created_at, :as => :date_select))
74
+ end)
75
+ end)
76
+ end
77
+
78
+ it 'should index the id of the control-group' do
79
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_created_at_input")
80
+ end
81
+
82
+ it 'should index the id of the select tag' do
83
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_1i")
84
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_2i")
85
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_3i")
86
+ end
87
+
88
+ it 'should index the name of the select tag' do
89
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(1i)]']")
90
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(2i)]']")
91
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(3i)]']")
92
+ end
93
+
94
+ end
95
+
96
+ describe ':labels option' do
97
+ it "should provide a message that :labels is not supported" do
98
+ pending ':labels is not supported'
99
+ end
100
+ end
101
+
102
+ describe "when required" do
103
+ it "should add the required attribute to the input's html options" do
104
+ with_config :use_required_attribute, true do
105
+ concat(semantic_form_for(@new_post) do |builder|
106
+ concat(builder.input(:title, :as => :date_select, :required => true))
107
+ end)
108
+ output_buffer.should have_tag("select[@required]", :count => 3)
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "when order does not include day" do
114
+ before do
115
+ output_buffer.replace ''
116
+ concat(semantic_form_for(@new_post) do |builder|
117
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month]))
118
+ end)
119
+ end
120
+
121
+ it "should include a hidden input for day" do
122
+ output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(3i)]"][@value="1"]')
123
+ end
124
+
125
+ it "should not include a select for day" do
126
+ output_buffer.should_not have_tag('select[@name="post[publish_at(3i)]"]')
127
+ end
128
+ end
129
+
130
+ describe "when order does not include month" do
131
+ before do
132
+ output_buffer.replace ''
133
+ concat(semantic_form_for(@new_post) do |builder|
134
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :day]))
135
+ end)
136
+ end
137
+
138
+ it "should include a hidden input for month" do
139
+ output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(2i)]"][@value="1"]')
140
+ end
141
+
142
+ it "should not include a select for month" do
143
+ output_buffer.should_not have_tag('select[@name="post[publish_at(2i)]"]')
144
+ end
145
+ end
146
+
147
+ describe "when order does not include year" do
148
+ before do
149
+ output_buffer.replace ''
150
+ concat(semantic_form_for(@new_post) do |builder|
151
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:month, :day]))
152
+ end)
153
+ end
154
+
155
+ it "should include a hidden input for month" do
156
+ output_buffer.should have_tag("input[@type=\"hidden\"][@name=\"post[publish_at(1i)]\"][@value=\"#{Time.now.year}\"]")
157
+ end
158
+
159
+ it "should not include a select for month" do
160
+ output_buffer.should_not have_tag('select[@name="post[publish_at(1i)]"]')
161
+ end
162
+ end
163
+
164
+ end