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
@@ -8,7 +8,6 @@ describe 'select input' do
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 'explicit values' do
@@ -24,10 +23,10 @@ describe 'select input' do
24
23
 
25
24
  it 'should have a option for each key and/or value' do
26
25
  @array_with_values.each do |v|
27
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{v}']", /^#{v}$/)
26
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
28
27
  end
29
28
  @array_with_keys_and_values.each do |v|
30
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{v.second}']", /^#{v.first}$/)
29
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v.second}']", /^#{v.first}$/)
31
30
  end
32
31
  end
33
32
  end
@@ -41,9 +40,9 @@ describe 'select input' do
41
40
  end
42
41
 
43
42
  it 'should draw select options' do
44
- output_buffer.should have_tag('form div.clearfix div.input select')
45
- output_buffer.should have_tag('form div.clearfix div.input select#post_reviewer_id')
46
- output_buffer.should_not have_tag('form div.clearfix div.input select#post_mongoid_reviewer_id')
43
+ output_buffer.should have_tag('form div.control-group div.controls select')
44
+ output_buffer.should have_tag('form div.control-group div.controls select#post_reviewer_id')
45
+ output_buffer.should_not have_tag('form div.control-group div.controls select#post_mongoid_reviewer_id')
47
46
  end
48
47
  end
49
48
 
@@ -57,14 +56,14 @@ describe 'select input' do
57
56
 
58
57
  it 'should have an option for each value' do
59
58
  @range_with_values.each do |v|
60
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{v}']", /^#{v}$/)
59
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
61
60
  end
62
61
  end
63
62
  end
64
63
 
65
64
  describe 'using a string' do
66
65
  before do
67
- @string ="<option value='0'>0</option><option value='1'>1</option>"
66
+ @string ="<option value='0'>0</option><option value='1'>1</option>".html_safe
68
67
  concat(semantic_form_for(@new_post) do |builder|
69
68
  concat(builder.input(:title, :as => :select, :collection => @string))
70
69
  end)
@@ -72,18 +71,53 @@ describe 'select input' do
72
71
 
73
72
  it 'should render select options using provided HTML string' do
74
73
  2.times do |v|
75
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{v}']", /^#{v}$/)
74
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
76
75
  end
77
76
  end
78
77
  end
78
+
79
+ describe 'using a nil name' do
80
+ before do
81
+ concat(semantic_form_for(@new_post) do |builder|
82
+ concat(builder.input(:title, :as => :select, :collection => [], :input_html => {:name => nil}))
83
+ end)
84
+ end
85
+
86
+ it_should_have_select_with_name("post[title]")
87
+ end
79
88
  end
80
89
 
81
90
  describe 'for boolean columns' do
91
+ pending
82
92
  # describe 'default formtastic locale' do
83
93
  # before do
84
94
  # # Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
85
- # ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
86
- # ::I18n.backend.send(:init_translations)
95
+ # # ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
96
+ # # ::I18n.backend.send(:init_translations)
97
+ #
98
+ # concat(semantic_form_for(@new_post) do |builder|
99
+ # concat(builder.input(:published, :as => :select))
100
+ # end)
101
+ # end
102
+ #
103
+ # after do
104
+ # # ::I18n.load_path = []
105
+ # # ::I18n.backend.store_translations :en, {}
106
+ # end
107
+ #
108
+ #
109
+ # it 'should render a select with at least options: true/false' do
110
+ # # I don't wanna deal with this right now.
111
+ # pending
112
+ # # output_buffer.should have_tag("form div.control-group div.controls select option[@value='true']", /^Yes$/)
113
+ # # output_buffer.should have_tag("form div.control-group div.controls select option[@value='false']", /^No$/)
114
+ # end
115
+ # end
116
+ #
117
+ # describe 'custom locale' do
118
+ # before do
119
+ # @boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
120
+ # ::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
87
121
  #
88
122
  # concat(semantic_form_for(@new_post) do |builder|
89
123
  # concat(builder.input(:published, :as => :select))
@@ -95,30 +129,10 @@ describe 'select input' do
95
129
  # end
96
130
  #
97
131
  # it 'should render a select with at least options: true/false' do
98
- # output_buffer.should have_tag("form div.clearfix div.input select option[@value='true']", /^Yes$/)
99
- # output_buffer.should have_tag("form div.clearfix div.input select option[@value='false']", /^No$/)
132
+ # output_buffer.should have_tag("form div.control-group div.controls select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
133
+ # output_buffer.should have_tag("form div.control-group div.controls select option[@value='false']", /#{@boolean_select_labels[:no]}/)
100
134
  # end
101
135
  # end
102
-
103
- describe 'custom locale' do
104
- before do
105
- @boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
106
- ::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
107
-
108
- concat(semantic_form_for(@new_post) do |builder|
109
- concat(builder.input(:published, :as => :select))
110
- end)
111
- end
112
-
113
- after do
114
- ::I18n.backend.store_translations :en, {}
115
- end
116
-
117
- it 'should render a select with at least options: true/false' do
118
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
119
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='false']", /#{@boolean_select_labels[:no]}/)
120
- end
121
- end
122
136
  end
123
137
 
124
138
  describe 'for a belongs_to association' do
@@ -129,9 +143,9 @@ describe 'select input' do
129
143
  end)
130
144
  end
131
145
 
146
+ it_should_have_bootstrap_horizontal_wrapping
132
147
  it_should_have_input_wrapper_with_class("select")
133
- it_should_have_input_wrapper_with_class(:clearfix)
134
- it_should_have_input_class_in_the_right_place
148
+ it_should_have_input_wrapper_with_class(:input)
135
149
  it_should_have_input_wrapper_with_id("post_author_input")
136
150
  it_should_have_label_with_text(/Author/)
137
151
  it_should_have_label_for('post_author_id')
@@ -140,38 +154,42 @@ describe 'select input' do
140
154
  it_should_use_the_collection_when_provided(:select, 'option')
141
155
 
142
156
  it 'should have a select inside the wrapper' do
143
- output_buffer.should have_tag('form div.clearfix div.input select')
144
- output_buffer.should have_tag('form div.clearfix div.input select#post_author_id')
145
- output_buffer.should have_tag('form div.clearfix div.input select#post_reviewer_id')
157
+ output_buffer.should have_tag('form div.control-group div.controls select')
158
+ output_buffer.should have_tag('form div.control-group div.controls select#post_author_id')
159
+ output_buffer.should have_tag('form div.control-group div.controls select#post_reviewer_id')
146
160
  end
147
161
 
148
162
  it 'should have a valid name' do
149
- output_buffer.should have_tag("form div.clearfix div.input select[@name='post[author_id]']")
150
- output_buffer.should_not have_tag("form div.clearfix div.input select[@name='post[author_id][]']")
151
- output_buffer.should_not have_tag("form div.clearfix div.input select[@name='post[reviewer_id][]']")
163
+ output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]']")
164
+ output_buffer.should_not have_tag("form div.control-group div.controls select[@name='post[author_id][]']")
165
+ output_buffer.should_not have_tag("form div.control-group div.controls select[@name='post[reviewer_id][]']")
152
166
  end
153
167
 
154
168
  it 'should not create a multi-select' do
155
- output_buffer.should_not have_tag('form div.clearfix div.input select[@multiple]')
169
+ output_buffer.should_not have_tag('form div.control-group div.controls select[@multiple]')
170
+ end
171
+
172
+ it 'should not add a hidden input' do
173
+ output_buffer.should_not have_tag('form li input[@type="hidden"]')
156
174
  end
157
175
 
158
176
  it 'should create a select without size' do
159
- output_buffer.should_not have_tag('form div.clearfix div.input select[@size]')
177
+ output_buffer.should_not have_tag('form div.control-group div.controls select[@size]')
160
178
  end
161
179
 
162
180
  it 'should have a blank option' do
163
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='']")
181
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
164
182
  end
165
183
 
166
184
  it 'should have a select option for each Author' do
167
- output_buffer.should have_tag("form div.clearfix div.input select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
185
+ output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
168
186
  ::Author.all.each do |author|
169
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{author.id}']", /#{author.to_label}/)
187
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
170
188
  end
171
189
  end
172
190
 
173
191
  it 'should have one option with a "selected" attribute (bob)' do
174
- output_buffer.should have_tag("form div.clearfix div.input select[@name='post[author_id]'] option[@selected]", :count => 1)
192
+ output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]'] option[@selected]", :count => 1)
175
193
  end
176
194
 
177
195
  it 'should not singularize the association name' do
@@ -183,7 +201,7 @@ describe 'select input' do
183
201
  concat(builder.input(:author_status, :as => :select))
184
202
  end)
185
203
 
186
- output_buffer.should have_tag('form div.clearfix div.input select#post_author_status_id')
204
+ output_buffer.should have_tag('form div.control-group div.controls select#post_author_status_id')
187
205
  end
188
206
  end
189
207
 
@@ -194,9 +212,11 @@ describe 'select input' do
194
212
  [@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") }
195
213
  @fred.should_receive(:posts)
196
214
 
197
- concat(semantic_form_for(@new_post) do |builder|
198
- concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
199
- end)
215
+ with_deprecation_silenced do
216
+ concat(semantic_form_for(@new_post) do |builder|
217
+ concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
218
+ end)
219
+ end
200
220
  end
201
221
  end
202
222
 
@@ -221,8 +241,10 @@ describe 'select input' do
221
241
  ::Author.should_receive(:scoped).with(:conditions => {:active => true})
222
242
  ::Author.should_receive(:where).with({:publisher => true})
223
243
 
224
- semantic_form_for(@new_post) do |builder|
225
- concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
244
+ with_deprecation_silenced do
245
+ semantic_form_for(@new_post) do |builder|
246
+ concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
247
+ end
226
248
  end
227
249
  end
228
250
  end
@@ -245,12 +267,14 @@ describe 'select input' do
245
267
  continent.stub!(:authors).and_return([@authors[i]])
246
268
  end
247
269
 
248
- concat(semantic_form_for(@new_post) do |builder|
249
- concat(builder.input(:author, :as => :select, :group_by => :continent ) )
250
- concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
251
- concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
252
- concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
253
- end)
270
+ with_deprecation_silenced do
271
+ concat(semantic_form_for(@new_post) do |builder|
272
+ concat(builder.input(:author, :as => :select, :group_by => :continent ) )
273
+ concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
274
+ concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
275
+ concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
276
+ end)
277
+ end
254
278
  end
255
279
 
256
280
  it_should_have_input_wrapper_with_class("select")
@@ -262,36 +286,38 @@ describe 'select input' do
262
286
 
263
287
  0.upto(1) do |i|
264
288
  it 'should have all option groups and the right values' do
265
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
289
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
266
290
  end
267
291
 
268
292
  it 'should have custom group labels' do
269
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
293
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
270
294
  end
271
295
 
272
296
  it 'should have custom author labels' do
273
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
297
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
274
298
  end
275
299
 
276
300
  it 'should have custom author and group labels' do
277
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
301
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
278
302
  end
279
303
  end
280
304
 
281
305
  it 'should have no duplicate groups' do
282
- output_buffer.should have_tag('form div.clearfix div.input select optgroup', :count => 8)
306
+ output_buffer.should have_tag('form div.control-group div.controls select optgroup', :count => 8)
283
307
  end
284
308
 
285
309
  it 'should sort the groups on the label method' do
286
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='Africa']")
287
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='99']")
310
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='Africa']")
311
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='99']")
288
312
  end
289
313
 
290
314
  it 'should call find with :include for more optimized queries' do
291
315
  Author.should_receive(:where).with(:include => :continent)
292
316
 
293
- semantic_form_for(@new_post) do |builder|
294
- concat(builder.input(:author, :as => :select, :group_by => :continent ) )
317
+ with_deprecation_silenced do
318
+ semantic_form_for(@new_post) do |builder|
319
+ concat(builder.input(:author, :as => :select, :group_by => :continent ) )
320
+ end
295
321
  end
296
322
  end
297
323
  end
@@ -312,27 +338,31 @@ describe 'select input' do
312
338
  it_should_use_the_collection_when_provided(:select, 'option')
313
339
 
314
340
  it 'should have a select inside the wrapper' do
315
- output_buffer.should have_tag('form div.clearfix div.input select')
316
- output_buffer.should have_tag('form div.clearfix div.input select#author_post_ids')
341
+ output_buffer.should have_tag('form div.control-group div.controls select')
342
+ output_buffer.should have_tag('form div.control-group div.controls select#author_post_ids')
317
343
  end
318
344
 
319
345
  it 'should have a multi-select select' do
320
- output_buffer.should have_tag('form div.clearfix div.input select[@multiple="multiple"]')
346
+ output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"]')
321
347
  end
322
-
348
+
323
349
  it 'should append [] to the name attribute for multiple select' do
324
- output_buffer.should have_tag('form div.clearfix div.input select[@multiple="multiple"][@name="author[post_ids][]"]')
350
+ output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"][@name="author[post_ids][]"]')
351
+ end
352
+
353
+ it 'should have a hidden field' do
354
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="author[post_ids][]"]')
325
355
  end
326
356
 
327
357
  it 'should have a select option for each Post' do
328
- output_buffer.should have_tag('form div.clearfix div.input select option', :count => ::Post.all.size)
358
+ output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Post.all.size)
329
359
  ::Post.all.each do |post|
330
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{post.id}']", /#{post.to_label}/)
360
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{post.id}']", /#{post.to_label}/)
331
361
  end
332
362
  end
333
363
 
334
364
  it 'should not have a blank option by default' do
335
- output_buffer.should_not have_tag("form div.clearfix div.input select option[@value='']")
365
+ output_buffer.should_not have_tag("form div.control-group div.controls select option[@value='']")
336
366
  end
337
367
 
338
368
  it 'should respect the :include_blank option for single selects' do
@@ -340,7 +370,7 @@ describe 'select input' do
340
370
  concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
341
371
  end)
342
372
 
343
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='']")
373
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
344
374
  end
345
375
 
346
376
  it 'should respect the :include_blank option for multiple selects' do
@@ -348,11 +378,11 @@ describe 'select input' do
348
378
  concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
349
379
  end)
350
380
 
351
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='']")
381
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
352
382
  end
353
383
 
354
384
  it 'should have one option with a "selected" attribute' do
355
- output_buffer.should have_tag('form div.clearfix div.input select option[@selected]', :count => 1)
385
+ output_buffer.should have_tag('form div.control-group div.controls select option[@selected]', :count => 1)
356
386
  end
357
387
  end
358
388
 
@@ -372,23 +402,23 @@ describe 'select input' do
372
402
  it_should_use_the_collection_when_provided(:select, 'option')
373
403
 
374
404
  it 'should have a select inside the wrapper' do
375
- output_buffer.should have_tag('form div.clearfix div.input select')
376
- output_buffer.should have_tag('form div.clearfix div.input select#post_author_ids')
405
+ output_buffer.should have_tag('form div.control-group div.controls select')
406
+ output_buffer.should have_tag('form div.control-group div.controls select#post_author_ids')
377
407
  end
378
408
 
379
409
  it 'should have a multi-select select' do
380
- output_buffer.should have_tag('form div.clearfix div.input select[@multiple="multiple"]')
410
+ output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"]')
381
411
  end
382
412
 
383
413
  it 'should have a select option for each Author' do
384
- output_buffer.should have_tag('form div.clearfix div.input select option', :count => ::Author.all.size)
414
+ output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Author.all.size)
385
415
  ::Author.all.each do |author|
386
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{author.id}']", /#{author.to_label}/)
416
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
387
417
  end
388
418
  end
389
419
 
390
420
  it 'should not have a blank option by default' do
391
- output_buffer.should_not have_tag("form div.clearfix div.input select option[@value='']")
421
+ output_buffer.should_not have_tag("form div.control-group div.controls select option[@value='']")
392
422
  end
393
423
 
394
424
  it 'should respect the :include_blank option for single selects' do
@@ -396,7 +426,7 @@ describe 'select input' do
396
426
  concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
397
427
  end)
398
428
 
399
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='']")
429
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
400
430
  end
401
431
 
402
432
  it 'should respect the :include_blank option for multiple selects' do
@@ -404,11 +434,11 @@ describe 'select input' do
404
434
  concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
405
435
  end)
406
436
 
407
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='']")
437
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
408
438
  end
409
439
 
410
440
  it 'should have one option with a "selected" attribute' do
411
- output_buffer.should have_tag('form div.clearfix div.input select option[@selected]', :count => 1)
441
+ output_buffer.should have_tag('form div.control-group div.controls select option[@selected]', :count => 1)
412
442
  end
413
443
  end
414
444
 
@@ -421,11 +451,11 @@ describe 'select input' do
421
451
  end
422
452
 
423
453
  it 'should have a select with prompt' do
424
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='']", /choose author/, :count => 1)
454
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']", /choose author/, :count => 1)
425
455
  end
426
456
 
427
- it 'should not have a blank select option' do
428
- output_buffer.should_not have_tag("form div.clearfix div.input select option[@value='']", "")
457
+ it 'should not have a second blank select option' do
458
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='']", :count => 1)
429
459
  end
430
460
  end
431
461
 
@@ -437,18 +467,18 @@ describe 'select input' do
437
467
  end
438
468
 
439
469
  it 'should generate label' do
440
- output_buffer.should have_tag('form div.clearfix label', /Author/)
441
- output_buffer.should have_tag("form div.clearfix label[@for='project_author']")
470
+ output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
471
+ output_buffer.should have_tag("form div.control-group label.control-label[@for='project_author']")
442
472
  end
443
473
 
444
474
  it 'should generate select inputs' do
445
- output_buffer.should have_tag('form div.clearfix div.input select#project_author')
446
- output_buffer.should have_tag('form div.clearfix div.input select option', :count => ::Author.all.size + 1)
475
+ output_buffer.should have_tag('form div.control-group div.controls select#project_author')
476
+ output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Author.all.size + 1)
447
477
  end
448
478
 
449
479
  it 'should generate an option to each item' do
450
480
  ::Author.all.each do |author|
451
- output_buffer.should have_tag("form div.clearfix div.input select option[@value='#{author.id}']", /#{author.to_label}/)
481
+ output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
452
482
  end
453
483
  end
454
484
  end
@@ -459,27 +489,27 @@ describe 'select input' do
459
489
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
460
490
  concat(builder.input(:author_name, :as => :select, :collection => ::Author.all))
461
491
  end)
462
- output_buffer.should have_tag("form div.clearfix div.input select[@name='project[author_name]']")
492
+ output_buffer.should have_tag("form div.control-group div.controls select[@name='project[author_name]']")
463
493
  end
464
-
494
+
465
495
  describe 'and :multiple is set to true through :input_html' do
466
496
  it "should make the select a multi-select" do
467
497
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
468
498
  concat(builder.input(:author_name, :as => :select, :input_html => {:multiple => true} ))
469
499
  end)
470
- output_buffer.should have_tag("form div.clearfix div.input select[@multiple]")
500
+ output_buffer.should have_tag("form div.control-group div.controls select[@multiple]")
471
501
  end
472
502
  end
473
-
503
+
474
504
  describe 'and :multiple is set to true' do
475
505
  it "should make the select a multi-select" do
476
506
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
477
507
  concat(builder.input(:author_name, :as => :select, :multiple => true, :collection => ["Fred", "Bob"]))
478
508
  end)
479
- output_buffer.should have_tag("form div.clearfix div.input select[@multiple]")
509
+ output_buffer.should have_tag("form div.control-group div.controls select[@multiple]")
480
510
  end
481
511
  end
482
-
512
+
483
513
  end
484
514
 
485
515
  describe 'when a grouped collection collection is given' do
@@ -494,12 +524,12 @@ describe 'select input' do
494
524
 
495
525
  it 'should generate an option to each item' do
496
526
  @grouped_opts.each do |opt_pair|
497
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='#{opt_pair[0]}']")
527
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{opt_pair[0]}']")
498
528
  opt_pair[1].each do |v|
499
- output_buffer.should have_tag("form div.clearfix div.input select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
529
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
500
530
  end
501
531
  end
502
- output_buffer.should have_tag("form div.clearfix div.input select optgroup option[@selected]","hands")
532
+ output_buffer.should have_tag("form div.control-group div.controls select optgroup option[@selected]","hands")
503
533
  end
504
534
  end
505
535
 
@@ -521,7 +551,7 @@ describe 'select input' do
521
551
  end
522
552
 
523
553
  it "should render a select field" do
524
- output_buffer.should have_tag("form div.clearfix div.input select", :count => 2)
554
+ output_buffer.should have_tag("form div.control-group div.controls select", :count => 2)
525
555
  end
526
556
  end
527
557
 
@@ -537,7 +567,7 @@ describe 'select input' do
537
567
  end
538
568
 
539
569
  it "should render a text field" do
540
- output_buffer.should have_tag("form div.clearfix div.input input[@type='text']", :count => 2)
570
+ output_buffer.should have_tag("form div.control-group div.controls input[@type='text']", :count => 2)
541
571
  end
542
572
  end
543
573
  end
@@ -552,6 +582,33 @@ describe 'select input' do
552
582
  it_should_have_select_with_id("context2_post_author_ids")
553
583
  it_should_have_label_for("context2_post_author_ids")
554
584
  end
585
+
586
+ describe "when index is provided" do
587
+
588
+ before do
589
+ @output_buffer = ''
590
+ mock_everything
591
+
592
+ concat(semantic_form_for(@new_post) do |builder|
593
+ concat(builder.fields_for(:author, :index => 3) do |author|
594
+ concat(author.input(:name, :as => :select))
595
+ end)
596
+ end)
597
+ end
598
+
599
+ it 'should index the id of the control-group' do
600
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
601
+ end
602
+
603
+ it 'should index the id of the select tag' do
604
+ output_buffer.should have_tag("select#post_author_attributes_3_name")
605
+ end
606
+
607
+ it 'should index the name of the select' do
608
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
609
+ end
610
+
611
+ end
555
612
 
556
613
  context "when required" do
557
614
  it "should add the required attribute to the select's html options" do
@@ -8,7 +8,6 @@ describe 'string input' do
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 "when object is provided" do
@@ -17,11 +16,11 @@ describe 'string input' do
17
16
  concat(builder.input(:title, :as => :string))
18
17
  end)
19
18
  end
20
-
19
+
20
+ it_should_have_bootstrap_horizontal_wrapping
21
21
  it_should_have_input_wrapper_with_class(:string)
22
- it_should_have_input_wrapper_with_class(:clearfix)
22
+ it_should_have_input_wrapper_with_class(:input)
23
23
  it_should_have_input_wrapper_with_class(:stringish)
24
- it_should_have_input_class_in_the_right_place
25
24
  it_should_have_input_wrapper_with_id("post_title_input")
26
25
  it_should_have_label_with_text(/Title/)
27
26
  it_should_have_label_for("post_title")
@@ -35,6 +34,7 @@ describe 'string input' do
35
34
  it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
36
35
  it_should_apply_error_logic_for_input_type(:string)
37
36
 
37
+ # This doesn't get called anywhere!
38
38
  def input_field_for_method_should_have_maxlength(method, maxlength)
39
39
  concat(semantic_form_for(@new_post) do |builder|
40
40
  concat(builder.input(method))
@@ -63,7 +63,7 @@ describe 'string input' do
63
63
  concat(builder.input(:title))
64
64
  end)
65
65
 
66
- output_buffer.should have_tag("form div.clearfix div.input input##{@new_post.class.name.underscore}_title[@maxlength='#{maxlength}']")
66
+ output_buffer.should have_tag("form div.control-group div.controls input##{@new_post.class.name.underscore}_title[@maxlength='#{maxlength}']")
67
67
  end
68
68
 
69
69
  it 'should have maxlength if the optional :if or :unless options are not supplied' do
@@ -126,6 +126,34 @@ describe 'string input' do
126
126
 
127
127
  end
128
128
 
129
+ describe "when index is provided" do
130
+
131
+ before do
132
+ @output_buffer = ''
133
+ mock_everything
134
+
135
+ concat(semantic_form_for(@new_post) do |builder|
136
+ concat(builder.fields_for(:author, :index => 3) do |author|
137
+ concat(author.input(:name, :as => :string))
138
+ end)
139
+ end)
140
+ end
141
+
142
+ it 'should index the id of the wrapper' do
143
+ output_buffer.should have_tag("div#post_author_attributes_3_name_input")
144
+ end
145
+
146
+ it 'should index the id of the select tag' do
147
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
148
+ end
149
+
150
+ it 'should index the name of the select tag' do
151
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
152
+ end
153
+
154
+ end
155
+
156
+
129
157
  describe "when no object is provided" do
130
158
  before do
131
159
  concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
@@ -178,22 +206,5 @@ describe 'string input' do
178
206
 
179
207
  end
180
208
 
181
- describe "with string prepended", :now => true do
182
-
183
- before do
184
- concat(semantic_form_for(:user) do |builder|
185
- concat(builder.input(:handle, :as => :string, :prepend => '@'))
186
- end)
187
- end
188
-
189
- it "should generate span with desired prepend string" do
190
- output_buffer.should have_tag('form div.input div.input-prepend span.add-on', '@')
191
- end
192
-
193
- it "should wrap input in div.input-prepend" do
194
- output_buffer.should have_tag('form div.input div.input-prepend input[name="user[handle]"]')
195
- end
196
- end
197
-
198
209
  end
199
210