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
@@ -14,15 +14,6 @@ module CustomMacros
14
14
  end
15
15
  end
16
16
 
17
- # This is one of the things we move for Bootstrap. In vanilla Formtastic
18
- # it's located on the outer wrapper. We move it to the inner wrapper.
19
- def it_should_have_input_class_in_the_right_place
20
- it "should have 'input' class in the right place" do
21
- output_buffer.should have_tag("form div.clearfix div.input")
22
- output_buffer.should_not have_tag("form div.clearfix.input")
23
- end
24
- end
25
-
26
17
  def it_should_have_input_wrapper_with_id(id_string)
27
18
  it "should have input wrapper with id '#{id_string}'" do
28
19
  output_buffer.should have_tag("form div##{id_string}")
@@ -47,91 +38,76 @@ module CustomMacros
47
38
  end
48
39
  end
49
40
 
50
- def it_should_have_a_nested_div
51
- it "should have a nested div" do
52
- output_buffer.should have_tag("form div.clearfix div")
53
- end
54
- end
55
-
56
- def it_should_have_a_nested_div_with_class(klass)
57
- it "should have a nested div with class #{klass}" do
58
- output_buffer.should have_tag("form div.clearfix div.#{klass}")
59
- end
60
- end
61
-
62
41
  def it_should_have_a_nested_ordered_list_with_class(klass)
63
42
  it "should have a nested fieldset with class #{klass}" do
64
43
  output_buffer.should have_tag("form li ol.#{klass}")
65
44
  end
66
45
  end
67
46
 
68
- def it_should_have_a_nested_unordered_list_with_class(klass)
69
- it "should have a nested unordered list with class #{klass}" do
70
- output_buffer.should have_tag("form div.clearfix div ul.#{klass}")
71
- end
72
- end
73
-
74
47
  def it_should_have_label_with_text(string_or_regex)
75
48
  it "should have a label with text '#{string_or_regex}'" do
76
- output_buffer.should have_tag("form div.clearfix label", string_or_regex)
49
+ output_buffer.should have_tag("form div.control-group label.control-label", string_or_regex)
77
50
  end
78
51
  end
79
52
 
80
53
  def it_should_have_label_for(element_id)
81
54
  it "should have a label for ##{element_id}" do
82
- # output_buffer.should have_tag("form div label.label[@for='#{element_id}']")
83
- output_buffer.should have_tag("form div.clearfix label[@for='#{element_id}']")
84
- output_buffer.should_not have_tag("form div.clearfix label.label")
55
+ output_buffer.should have_tag("form div.control-group label.control-label[@for='#{element_id}']")
85
56
  end
86
57
  end
87
58
 
88
59
  def it_should_have_an_inline_label_for(element_id)
89
60
  it "should have a label for ##{element_id}" do
90
- output_buffer.should have_tag("form li label[@for='#{element_id}']")
61
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='#{element_id}']")
91
62
  end
92
63
  end
93
64
 
94
65
  def it_should_have_input_with_id(element_id)
95
66
  it "should have an input with id '#{element_id}'" do
96
- # output_buffer.should have_tag("form div.clearfix div.input input##{element_id}")
97
- output_buffer.should have_tag("form div.clearfix div.input input[@id=\"#{element_id}\"]")
67
+ output_buffer.should have_tag("form div.control-group div.controls input[@id=\"#{element_id}\"]")
98
68
  end
99
69
  end
100
70
 
101
71
  def it_should_have_select_with_id(element_id)
102
72
  it "should have a select box with id '#{element_id}'" do
103
- output_buffer.should have_tag("form div.clearfix div.input select##{element_id}")
73
+ output_buffer.should have_tag("form div.control-group div.controls select##{element_id}")
104
74
  end
105
75
  end
106
76
 
107
77
  def it_should_have_input_with_type(input_type)
108
78
  it "should have a #{input_type} input" do
109
- output_buffer.should have_tag("form div.clearfix div.input input[@type=\"#{input_type}\"]")
79
+ output_buffer.should have_tag("form div.control-group div.controls input[@type=\"#{input_type}\"]")
110
80
  end
111
81
  end
112
82
 
113
83
  def it_should_have_input_with_name(name)
114
84
  it "should have an input named #{name}" do
115
- output_buffer.should have_tag("form div.clearfix div.input input[@name=\"#{name}\"]")
85
+ output_buffer.should have_tag("form div.control-group div.controls input[@name=\"#{name}\"]")
86
+ end
87
+ end
88
+
89
+ def it_should_have_select_with_name(name)
90
+ it "should have an input named #{name}" do
91
+ output_buffer.should have_tag("form div.control-group div.controls select[@name=\"#{name}\"]")
116
92
  end
117
93
  end
118
94
 
119
95
  def it_should_have_textarea_with_name(name)
120
96
  it "should have an input named #{name}" do
121
- output_buffer.should have_tag("form div.clearfix div.input textarea[@name=\"#{name}\"]")
97
+ output_buffer.should have_tag("form div.control-group div.controls textarea[@name=\"#{name}\"]")
122
98
  end
123
99
  end
124
100
 
125
101
  def it_should_have_textarea_with_id(element_id)
126
102
  it "should have an input with id '#{element_id}'" do
127
- output_buffer.should have_tag("form div.clearfix div.input textarea##{element_id}")
103
+ output_buffer.should have_tag("form div.control-group div.controls textarea##{element_id}")
128
104
  end
129
105
  end
130
106
 
131
107
  def it_should_have_label_and_input_with_id(element_id)
132
108
  it "should have an input with id '#{element_id}'" do
133
- output_buffer.should have_tag("form div.clearfix div.input input##{element_id}")
134
- output_buffer.should have_tag("form div.clearfix label[@for='#{element_id}']")
109
+ output_buffer.should have_tag("form div.control-group div.controls input##{element_id}")
110
+ output_buffer.should have_tag("form div.control-group label.control-label[@for='#{element_id}']")
135
111
  end
136
112
  end
137
113
 
@@ -141,7 +117,7 @@ module CustomMacros
141
117
  concat(semantic_form_for(@new_post) do |builder|
142
118
  concat(builder.input(:title, :as => as))
143
119
  end)
144
- output_buffer.should have_tag("form div.clearfix div.input input[@size='#{FormtasticBootstrap::FormBuilder.default_text_field_size}']")
120
+ output_buffer.should have_tag("form div.control-group div.controls input[@size='#{Formtastic::FormBuilder.default_text_field_size}']")
145
121
  end
146
122
  end
147
123
  end
@@ -152,8 +128,8 @@ module CustomMacros
152
128
  concat(semantic_form_for(@new_post) do |builder|
153
129
  concat(builder.input(:title, :as => as))
154
130
  end)
155
- output_buffer.should have_tag("form div.clearfix div.input input")
156
- output_buffer.should_not have_tag("form div.clearfix div.input input[@size]")
131
+ output_buffer.should have_tag("form div.control-group div.controls input")
132
+ output_buffer.should_not have_tag("form div.control-group div.controls input[@size]")
157
133
  end
158
134
  end
159
135
  end
@@ -163,7 +139,7 @@ module CustomMacros
163
139
  concat(semantic_form_for(@new_post) do |builder|
164
140
  concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
165
141
  end)
166
- output_buffer.should have_tag("form div.clearfix div.input input.myclass")
142
+ output_buffer.should have_tag("form div.control-group div.controls input.myclass")
167
143
  end
168
144
  end
169
145
 
@@ -172,14 +148,14 @@ module CustomMacros
172
148
  concat(semantic_form_for(@new_post) do |builder|
173
149
  concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
174
150
  end)
175
- output_buffer.should have_tag('form div.clearfix label[@for="myid"]')
151
+ output_buffer.should have_tag('form div.control-group label.control-label[@for="myid"]')
176
152
  end
177
153
  end
178
154
 
179
155
  def it_should_have_maxlength_matching_column_limit
180
156
  it 'should have a maxlength matching column limit' do
181
157
  @new_post.column_for_attribute(:title).limit.should == 50
182
- output_buffer.should have_tag("form div.clearfix div.input input[@maxlength='50']")
158
+ output_buffer.should have_tag("form div.control-group div.controls input[@maxlength='50']")
183
159
  end
184
160
  end
185
161
 
@@ -198,25 +174,14 @@ module CustomMacros
198
174
 
199
175
  def it_should_apply_error_logic_for_input_type(type, inline_or_block = :inline)
200
176
  describe 'when there are errors on the object for this method' do
201
-
202
- before(:each) do
177
+ before do
203
178
  @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
204
179
  @errors = mock('errors')
205
- @errors.stub!(:[]).with(:title).and_return(@title_errors)
180
+ @errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
206
181
  Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
207
- @errors.stub!(:[]).with("title_#{suffix}".to_sym).and_return(nil)
182
+ @errors.stub!(:[]).with(errors_matcher("title_#{suffix}".to_sym)).and_return(nil)
208
183
  end
209
184
  @new_post.stub!(:errors).and_return(@errors)
210
-
211
- @orig_inline_errors = FormtasticBootstrap::FormBuilder.inline_errors
212
- @orig_inline_error_class = FormtasticBootstrap::FormBuilder.default_inline_error_class
213
- @orig_error_list_class = FormtasticBootstrap::FormBuilder.default_error_list_class
214
- end
215
-
216
- after(:each) do
217
- FormtasticBootstrap::FormBuilder.inline_errors = @orig_inline_errors
218
- FormtasticBootstrap::FormBuilder.default_inline_error_class = @orig_inline_error_class
219
- FormtasticBootstrap::FormBuilder.default_error_list_class = @orig_error_list_class
220
185
  end
221
186
 
222
187
  it 'should apply an errors class to the list item' do
@@ -263,16 +228,15 @@ module CustomMacros
263
228
  end
264
229
 
265
230
  it 'should not apply an errors class to the list item' do
266
- output_buffer.should_not have_tag('form div.error')
231
+ output_buffer.should_not have_tag('form li.error')
267
232
  end
268
233
 
269
234
  it 'should not render a paragraph for the errors' do
270
- # output_buffer.should_not have_tag('form div.error p.inline-errors')
271
- output_buffer.should_not have_tag('form div.error span.help-inline')
235
+ output_buffer.should_not have_tag('form li.error p.inline-errors')
272
236
  end
273
237
 
274
238
  it 'should not display an error list' do
275
- output_buffer.should_not have_tag('form div.error ul.errors')
239
+ output_buffer.should_not have_tag('form li.error ul.errors')
276
240
  end
277
241
  end
278
242
 
@@ -284,16 +248,15 @@ module CustomMacros
284
248
  end
285
249
 
286
250
  it 'should not apply an errors class to the list item' do
287
- output_buffer.should_not have_tag('form div.error')
251
+ output_buffer.should_not have_tag('form li.error')
288
252
  end
289
253
 
290
254
  it 'should not render a paragraph for the errors' do
291
- # output_buffer.should_not have_tag('form div.error p.inline-errors')
292
- output_buffer.should_not have_tag('form div.error span.help-inline')
255
+ output_buffer.should_not have_tag('form li.error p.inline-errors')
293
256
  end
294
257
 
295
258
  it 'should not display an error list' do
296
- output_buffer.should_not have_tag('form div.error ul.errors')
259
+ output_buffer.should_not have_tag('form li.error ul.errors')
297
260
  end
298
261
  end
299
262
  end
@@ -308,6 +271,10 @@ module CustomMacros
308
271
  end
309
272
 
310
273
  def it_should_use_the_collection_when_provided(as, countable)
274
+
275
+ # Set control-div 'as' class.
276
+ cd_as = (as == :radio) ? :radio_buttons : as
277
+
311
278
  describe 'when the :collection option is provided' do
312
279
 
313
280
  before do
@@ -319,7 +286,7 @@ module CustomMacros
319
286
  concat(semantic_form_for(@new_post) do |builder|
320
287
  concat(builder.input(:author, :as => as, :collection => @authors))
321
288
  end)
322
- output_buffer.should have_tag("form div.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
289
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
323
290
  end
324
291
 
325
292
  describe 'and the :collection is an array of strings' do
@@ -333,8 +300,8 @@ module CustomMacros
333
300
  end)
334
301
 
335
302
  @categories.each do |value|
336
- output_buffer.should have_tag("form div.#{as}", /#{value}/)
337
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{value}']")
303
+ output_buffer.should have_tag("form div.#{cd_as}", /#{value}/)
304
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value}']")
338
305
  end
339
306
  end
340
307
 
@@ -347,10 +314,10 @@ module CustomMacros
347
314
  end
348
315
  concat(fields)
349
316
  end)
350
- output_buffer.should have_tag("form div div ul li label[@for='post_author_category_name_general']")
351
- output_buffer.should have_tag("form div div ul li label[@for='post_author_category_name_design']")
352
- output_buffer.should have_tag("form div div ul li label[@for='post_author_category_name_development']")
353
- output_buffer.should have_tag("form div div ul li label[@for='post_author_category_name_quasi-serious_inventions']")
317
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_general']")
318
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_design']")
319
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_development']")
320
+ output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_quasi-serious_inventions']")
354
321
  end
355
322
  end
356
323
  end
@@ -366,8 +333,8 @@ module CustomMacros
366
333
  end)
367
334
 
368
335
  @categories.each do |label, value|
369
- output_buffer.should have_tag("form div.#{as}", /#{label}/)
370
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{value}']")
336
+ output_buffer.should have_tag("form div.#{cd_as}", /#{label}/)
337
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value}']")
371
338
  end
372
339
  end
373
340
  end
@@ -384,9 +351,9 @@ module CustomMacros
384
351
 
385
352
  @categories.each do |text, value|
386
353
  label = as == :select ? :option : :label
387
- output_buffer.should have_tag("form div.#{as} #{label}", /#{text}/i)
388
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{value.to_s}']")
389
- output_buffer.should have_tag("form div.#{as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
354
+ output_buffer.should have_tag("form div.#{cd_as} #{label}", /#{text}/i)
355
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value.to_s}']")
356
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
390
357
  end
391
358
  end
392
359
  end
@@ -402,8 +369,8 @@ module CustomMacros
402
369
  concat(builder.input(:category_name, :as => as, :collection => @choices))
403
370
  end)
404
371
 
405
- output_buffer.should have_tag("form div.#{as} #{countable}#post_category_name_true")
406
- output_buffer.should have_tag("form div.#{as} #{countable}#post_category_name_false")
372
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}#post_category_name_true")
373
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}#post_category_name_false")
407
374
  end
408
375
  end
409
376
  end
@@ -420,8 +387,8 @@ module CustomMacros
420
387
 
421
388
  @categories.each do |value|
422
389
  label = as == :select ? :option : :label
423
- output_buffer.should have_tag("form div.#{as} #{label}", /#{value}/i)
424
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{value.to_s}']")
390
+ output_buffer.should have_tag("form div.#{cd_as} #{label}", /#{value}/i)
391
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value.to_s}']")
425
392
  end
426
393
  end
427
394
  end
@@ -437,8 +404,8 @@ module CustomMacros
437
404
  end)
438
405
 
439
406
  @categories.each do |label, value|
440
- output_buffer.should have_tag("form div.#{as}", /#{label}/)
441
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{value}']")
407
+ output_buffer.should have_tag("form div.#{cd_as}", /#{label}/)
408
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value}']")
442
409
  end
443
410
  end
444
411
 
@@ -455,7 +422,7 @@ module CustomMacros
455
422
 
456
423
  it 'should have options with text content from the specified method' do
457
424
  ::Author.all.each do |author|
458
- output_buffer.should have_tag("form div.#{as}", /#{author.login}/)
425
+ output_buffer.should have_tag("form div.#{cd_as}", /#{author.login}/)
459
426
  end
460
427
  end
461
428
  end
@@ -469,7 +436,7 @@ module CustomMacros
469
436
 
470
437
  it 'should have options with the proc applied to each' do
471
438
  ::Author.all.each do |author|
472
- output_buffer.should have_tag("form div.#{as}", /#{author.login.reverse}/)
439
+ output_buffer.should have_tag("form div.#{cd_as}", /#{author.login.reverse}/)
473
440
  end
474
441
  end
475
442
  end
@@ -486,7 +453,7 @@ module CustomMacros
486
453
 
487
454
  it 'should have options with the proc applied to each' do
488
455
  ::Author.all.each do |author|
489
- output_buffer.should have_tag("form div.#{as}", /#{author.login.reverse}/)
456
+ output_buffer.should have_tag("form div.#{cd_as}", /#{author.login.reverse}/)
490
457
  end
491
458
  end
492
459
  end
@@ -507,7 +474,7 @@ module CustomMacros
507
474
 
508
475
  it "should render the options with #{label_method} as the label" do
509
476
  ::Author.all.each do |author|
510
- output_buffer.should have_tag("form div.#{as}", /The Label Text/)
477
+ output_buffer.should have_tag("form div.#{cd_as}", /The Label Text/)
511
478
  end
512
479
  end
513
480
  end
@@ -526,7 +493,7 @@ module CustomMacros
526
493
 
527
494
  it 'should have options with values from specified method' do
528
495
  ::Author.all.each do |author|
529
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{author.login}']")
496
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{author.login}']")
530
497
  end
531
498
  end
532
499
  end
@@ -540,7 +507,7 @@ module CustomMacros
540
507
 
541
508
  it 'should have options with the proc applied to each value' do
542
509
  ::Author.all.each do |author|
543
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{author.login.reverse}']")
510
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{author.login.reverse}']")
544
511
  end
545
512
  end
546
513
  end
@@ -557,141 +524,7 @@ module CustomMacros
557
524
 
558
525
  it 'should have options with the proc applied to each value' do
559
526
  ::Author.all.each do |author|
560
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{author.login.reverse}']")
561
- end
562
- end
563
- end
564
- end
565
-
566
- describe 'when the deprecated :label_method option is provided' do
567
-
568
- describe 'as a symbol' do
569
- before do
570
- with_deprecation_silenced do
571
- concat(semantic_form_for(@new_post) do |builder|
572
- concat(builder.input(:author, :as => as, :label_method => :login))
573
- end)
574
- end
575
- end
576
-
577
- it 'should have options with text content from the specified method' do
578
- ::Author.all.each do |author|
579
- output_buffer.should have_tag("form div.#{as}", /#{author.login}/)
580
- end
581
- end
582
- end
583
-
584
- describe 'as a proc' do
585
-
586
- before do
587
- with_deprecation_silenced do
588
- concat(semantic_form_for(@new_post) do |builder|
589
- concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
590
- end)
591
- end
592
- end
593
-
594
- it 'should have options with the proc applied to each' do
595
- ::Author.all.each do |author|
596
- output_buffer.should have_tag("form div.#{as}", /#{author.login.reverse}/)
597
- end
598
- end
599
- end
600
-
601
- describe 'as a method object' do
602
- before do
603
- def reverse_login(a)
604
- a.login.reverse
605
- end
606
- with_deprecation_silenced do
607
- concat(semantic_form_for(@new_post) do |builder|
608
- concat(builder.input(:author, :as => as, :label_method => method(:reverse_login)))
609
- end)
610
- end
611
- end
612
-
613
- it 'should have options with the proc applied to each' do
614
- ::Author.all.each do |author|
615
- output_buffer.should have_tag("form div.#{as}", /#{author.login.reverse}/)
616
- end
617
- end
618
- end
619
- end
620
-
621
- describe 'when the deprecated :label_method option is not provided' do
622
- Formtastic::FormBuilder.collection_label_methods.each do |label_method|
623
-
624
- describe "when the collection objects respond to #{label_method}" do
625
- before do
626
- @fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
627
- ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
628
-
629
- with_deprecation_silenced do
630
- concat(semantic_form_for(@new_post) do |builder|
631
- concat(builder.input(:author, :as => as))
632
- end)
633
- end
634
- end
635
-
636
- it "should render the options with #{label_method} as the label" do
637
- ::Author.all.each do |author|
638
- output_buffer.should have_tag("form div.#{as}", /The Label Text/)
639
- end
640
- end
641
- end
642
-
643
- end
644
- end
645
-
646
- describe 'when the deprecated :value_method option is provided' do
647
-
648
- describe 'as a symbol' do
649
- before do
650
- with_deprecation_silenced do
651
- concat(semantic_form_for(@new_post) do |builder|
652
- concat(builder.input(:author, :as => as, :value_method => :login))
653
- end)
654
- end
655
- end
656
-
657
- it 'should have options with values from specified method' do
658
- ::Author.all.each do |author|
659
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{author.login}']")
660
- end
661
- end
662
- end
663
-
664
- describe 'as a proc' do
665
- before do
666
- with_deprecation_silenced do
667
- concat(semantic_form_for(@new_post) do |builder|
668
- concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
669
- end)
670
- end
671
- end
672
-
673
- it 'should have options with the proc applied to each value' do
674
- ::Author.all.each do |author|
675
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{author.login.reverse}']")
676
- end
677
- end
678
- end
679
-
680
- describe 'as a method object' do
681
- before do
682
- def reverse_login(a)
683
- a.login.reverse
684
- end
685
- with_deprecation_silenced do
686
- concat(semantic_form_for(@new_post) do |builder|
687
- concat(builder.input(:author, :as => as, :value_method => method(:reverse_login)))
688
- end)
689
- end
690
- end
691
-
692
- it 'should have options with the proc applied to each value' do
693
- ::Author.all.each do |author|
694
- output_buffer.should have_tag("form div.#{as} #{countable}[@value='#{author.login.reverse}']")
527
+ output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{author.login.reverse}']")
695
528
  end
696
529
  end
697
530
  end
@@ -0,0 +1,23 @@
1
+ module FbCustomMacros
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+
9
+ def it_should_have_bootstrap_horizontal_wrapping
10
+ it "should have 'input' class in the right place" do
11
+ output_buffer.should have_tag("form div.control-group div.controls")
12
+ end
13
+ end
14
+
15
+ def it_should_have_bootstrap_controls_label_with(class_name)
16
+ it "should have bootstrap controls wrapper with class '#{class_name}'" do
17
+ output_buffer.should have_tag("form div.controls label.#{class_name}")
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end