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,8 +9,6 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
11
 
12
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
13
-
14
12
  @errors = mock('errors')
15
13
  @errors.stub!(:[]).and_return([])
16
14
  @new_post.stub!(:errors).and_return(@errors)
@@ -31,49 +29,48 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
31
29
  end
32
30
 
33
31
  describe ':required option' do
34
-
32
+
35
33
  describe 'when true' do
36
-
34
+
37
35
  it 'should set a "required" class' do
38
36
  with_config :required_string, " required yo!" do
39
37
  concat(semantic_form_for(@new_post) do |builder|
40
38
  concat(builder.input(:title, :required => true))
41
39
  end)
42
- output_buffer.should_not have_tag('form div.clearfix.optional')
43
- output_buffer.should have_tag('form div.clearfix.required')
40
+ output_buffer.should_not have_tag('form div.optional')
41
+ output_buffer.should have_tag('form div.required')
44
42
  end
45
43
  end
46
-
44
+
47
45
  it 'should append the "required" string to the label' do
48
46
  with_config :required_string, " required yo!" do
49
47
  concat(semantic_form_for(@new_post) do |builder|
50
48
  concat(builder.input(:title, :required => true))
51
49
  end)
52
- output_buffer.should have_tag('form div.clearfix.required label', /required yo/)
50
+ output_buffer.should have_tag('form div.required label', /required yo/)
53
51
  end
54
52
  end
55
53
  end
56
-
54
+
57
55
  describe 'when false' do
58
-
59
- before(:each) do
60
- @orig_optional_string = FormtasticBootstrap::FormBuilder.optional_string
61
- @string = FormtasticBootstrap::FormBuilder.optional_string = " optional yo!" # ensure there's something in the string
56
+
57
+ before do
58
+ @string = Formtastic::FormBuilder.optional_string = " optional yo!" # ensure there's something in the string
62
59
  @new_post.class.should_not_receive(:reflect_on_all_validations)
63
60
  end
64
-
65
- after(:each) do
66
- FormtasticBootstrap::FormBuilder.optional_string = @orig_optional_string
61
+
62
+ after do
63
+ Formtastic::FormBuilder.optional_string = ''
67
64
  end
68
-
65
+
69
66
  it 'should set an "optional" class' do
70
67
  concat(semantic_form_for(@new_post) do |builder|
71
68
  concat(builder.input(:title, :required => false))
72
69
  end)
73
- output_buffer.should_not have_tag('form div.clearfix.required')
74
- output_buffer.should have_tag('form div.clearfix.optional')
70
+ output_buffer.should_not have_tag('form div.required')
71
+ output_buffer.should have_tag('form div.optional')
75
72
  end
76
-
73
+
77
74
  it 'should set and "optional" class also when there is presence validator' do
78
75
  @new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
79
76
  active_model_presence_validator([:title])
@@ -81,72 +78,65 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
81
78
  concat(semantic_form_for(@new_post) do |builder|
82
79
  concat(builder.input(:title, :required => false))
83
80
  end)
84
- output_buffer.should_not have_tag('form div.clearfix.required')
85
- output_buffer.should have_tag('form div.clearfix.optional')
81
+ output_buffer.should_not have_tag('form div.required')
82
+ output_buffer.should have_tag('form div.optional')
86
83
  end
87
-
84
+
88
85
  it 'should append the "optional" string to the label' do
89
86
  concat(semantic_form_for(@new_post) do |builder|
90
87
  concat(builder.input(:title, :required => false))
91
88
  end)
92
- output_buffer.should have_tag('form div.clearfix.optional label', /#{@string}$/)
89
+ output_buffer.should have_tag('form div.optional label', /#{@string}$/)
93
90
  end
94
-
91
+
95
92
  end
96
-
93
+
97
94
  describe 'when not provided' do
98
-
95
+
99
96
  describe 'and an object was not given' do
100
-
101
- before(:each) do
102
- @orig_all_fields_required = FormtasticBootstrap::FormBuilder.all_fields_required_by_default
103
- end
104
-
105
- after(:each) do
106
- FormtasticBootstrap::FormBuilder.all_fields_required_by_default = @orig_all_fields_required
107
- end
108
-
97
+
109
98
  it 'should use the default value' do
110
- FormtasticBootstrap::FormBuilder.all_fields_required_by_default.should == true
111
- FormtasticBootstrap::FormBuilder.all_fields_required_by_default = false
112
-
99
+ Formtastic::FormBuilder.all_fields_required_by_default.should == true
100
+ Formtastic::FormBuilder.all_fields_required_by_default = false
101
+
113
102
  concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
114
103
  concat(builder.input(:title))
115
104
  end)
116
- output_buffer.should_not have_tag('form div.clearfix.required')
117
- output_buffer.should have_tag('form div.clearfix.optional')
118
-
105
+ output_buffer.should_not have_tag('form div.required')
106
+ output_buffer.should have_tag('form div.optional')
107
+
108
+ Formtastic::FormBuilder.all_fields_required_by_default = true
119
109
  end
120
-
110
+
121
111
  end
122
-
112
+
123
113
  describe 'and an object with :validators_on was given (ActiveModel, Active Resource)' do
124
114
  before do
125
115
  @new_post.stub!(:class).and_return(::PostModel)
126
116
  end
127
-
117
+
128
118
  after do
129
119
  @new_post.stub!(:class).and_return(::Post)
130
120
  end
131
121
  describe 'and validates_presence_of was called for the method' do
132
122
  it 'should be required' do
133
-
123
+
134
124
  @new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
135
125
  active_model_presence_validator([:title])
136
126
  ])
137
-
127
+
138
128
  @new_post.class.should_receive(:validators_on).with(:body).any_number_of_times.and_return([
139
129
  active_model_presence_validator([:body], {:if => true})
140
130
  ])
141
-
131
+
142
132
  concat(semantic_form_for(@new_post) do |builder|
143
133
  concat(builder.input(:title))
144
134
  concat(builder.input(:body))
145
135
  end)
146
- output_buffer.should have_tag('form div.clearfix.required')
147
- output_buffer.should_not have_tag('form div.clearfix.optional')
136
+ output_buffer.should have_tag('form div.required')
137
+ output_buffer.should_not have_tag('form div.optional')
148
138
  end
149
-
139
+
150
140
  it 'should be required when there is :on => :create option on create' do
151
141
  with_config :required_string, " required yo!" do
152
142
  @new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
@@ -155,11 +145,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
155
145
  concat(semantic_form_for(@new_post) do |builder|
156
146
  concat(builder.input(:title))
157
147
  end)
158
- output_buffer.should have_tag('form div.clearfix.required')
159
- output_buffer.should_not have_tag('form div.clearfix.optional')
148
+ output_buffer.should have_tag('form div.required')
149
+ output_buffer.should_not have_tag('form div.optional')
160
150
  end
161
151
  end
162
-
152
+
163
153
  it 'should be required when there is :on => :save option on create' do
164
154
  with_config :required_string, " required yo!" do
165
155
  @new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
@@ -168,11 +158,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
168
158
  concat(semantic_form_for(@new_post) do |builder|
169
159
  concat(builder.input(:title))
170
160
  end)
171
- output_buffer.should have_tag('form div.clearfix.required')
172
- output_buffer.should_not have_tag('form div.clearfix.optional')
161
+ output_buffer.should have_tag('form div.required')
162
+ output_buffer.should_not have_tag('form div.optional')
173
163
  end
174
164
  end
175
-
165
+
176
166
  it 'should be required when there is :on => :save option on update' do
177
167
  with_config :required_string, " required yo!" do
178
168
  @fred.class.should_receive(:validators_on).with(:login).any_number_of_times.and_return([
@@ -181,11 +171,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
181
171
  concat(semantic_form_for(@fred) do |builder|
182
172
  concat(builder.input(:login))
183
173
  end)
184
- output_buffer.should have_tag('form div.clearfix.required')
185
- output_buffer.should_not have_tag('form div.clearfix.optional')
174
+ output_buffer.should have_tag('form div.required')
175
+ output_buffer.should_not have_tag('form div.optional')
186
176
  end
187
177
  end
188
-
178
+
189
179
  it 'should not be required when there is :on => :create option on update' do
190
180
  @fred.class.should_receive(:validators_on).with(:login).any_number_of_times.and_return([
191
181
  active_model_presence_validator([:login], {:on => :create})
@@ -193,10 +183,10 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
193
183
  concat(semantic_form_for(@fred) do |builder|
194
184
  concat(builder.input(:login))
195
185
  end)
196
- output_buffer.should_not have_tag('form div.clearfix.required')
197
- output_buffer.should have_tag('form div.clearfix.optional')
186
+ output_buffer.should_not have_tag('form div.required')
187
+ output_buffer.should have_tag('form div.optional')
198
188
  end
199
-
189
+
200
190
  it 'should not be required when there is :on => :update option on create' do
201
191
  @new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
202
192
  active_model_presence_validator([:title], {:on => :update})
@@ -204,51 +194,51 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
204
194
  concat(semantic_form_for(@new_post) do |builder|
205
195
  concat(builder.input(:title))
206
196
  end)
207
- output_buffer.should_not have_tag('form div.clearfix.required')
208
- output_buffer.should have_tag('form div.clearfix.optional')
197
+ output_buffer.should_not have_tag('form div.required')
198
+ output_buffer.should have_tag('form div.optional')
209
199
  end
210
-
200
+
211
201
  it 'should be not be required if the optional :if condition is not satisifed' do
212
202
  presence_should_be_required(:required => false, :tag => :body, :options => { :if => false })
213
203
  end
214
-
204
+
215
205
  it 'should not be required if the optional :if proc evaluates to false' do
216
206
  presence_should_be_required(:required => false, :tag => :body, :options => { :if => proc { |record| false } })
217
207
  end
218
-
208
+
219
209
  it 'should be required if the optional :if proc evaluates to true' do
220
210
  presence_should_be_required(:required => true, :tag => :body, :options => { :if => proc { |record| true } })
221
211
  end
222
-
212
+
223
213
  it 'should not be required if the optional :unless proc evaluates to true' do
224
214
  presence_should_be_required(:required => false, :tag => :body, :options => { :unless => proc { |record| true } })
225
215
  end
226
-
216
+
227
217
  it 'should be required if the optional :unless proc evaluates to false' do
228
218
  presence_should_be_required(:required => true, :tag => :body, :options => { :unless => proc { |record| false } })
229
219
  end
230
-
220
+
231
221
  it 'should be required if the optional :if with a method string evaluates to true' do
232
222
  @new_post.should_receive(:required_condition).and_return(true)
233
223
  presence_should_be_required(:required => true, :tag => :body, :options => { :if => :required_condition })
234
224
  end
235
-
225
+
236
226
  it 'should be required if the optional :if with a method string evaluates to false' do
237
227
  @new_post.should_receive(:required_condition).and_return(false)
238
228
  presence_should_be_required(:required => false, :tag => :body, :options => { :if => :required_condition })
239
229
  end
240
-
230
+
241
231
  it 'should be required if the optional :unless with a method string evaluates to false' do
242
232
  @new_post.should_receive(:required_condition).and_return(false)
243
233
  presence_should_be_required(:required => true, :tag => :body, :options => { :unless => :required_condition })
244
234
  end
245
-
235
+
246
236
  it 'should not be required if the optional :unless with a method string evaluates to true' do
247
237
  @new_post.should_receive(:required_condition).and_return(true)
248
238
  presence_should_be_required(:required => false, :tag => :body, :options => { :unless => :required_condition })
249
239
  end
250
240
  end
251
-
241
+
252
242
  describe 'and validates_inclusion_of was called for the method' do
253
243
  it 'should be required' do
254
244
  @new_post.class.should_receive(:validators_on).with(:published).any_number_of_times.and_return([
@@ -256,7 +246,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
256
246
  ])
257
247
  should_be_required(:tag => :published, :required => true)
258
248
  end
259
-
249
+
260
250
  it 'should not be required if allow_blank is true' do
261
251
  @new_post.class.should_receive(:validators_on).with(:published).any_number_of_times.and_return([
262
252
  active_model_inclusion_validator([:published], {:in => [false, true], :allow_blank => true})
@@ -264,298 +254,287 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
264
254
  should_be_required(:tag => :published, :required => false)
265
255
  end
266
256
  end
267
-
257
+
268
258
  describe 'and validates_length_of was called for the method' do
269
259
  it 'should be required if minimum is set' do
270
260
  length_should_be_required(:tag => :title, :required => true, :options => {:minimum => 1})
271
261
  end
272
-
262
+
273
263
  it 'should be required if :within is set' do
274
264
  length_should_be_required(:tag => :title, :required => true, :options => {:within => 1..5})
275
265
  end
276
-
266
+
277
267
  it 'should not be required if :within allows zero length' do
278
268
  length_should_be_required(:tag => :title, :required => false, :options => {:within => 0..5})
279
269
  end
280
-
270
+
281
271
  it 'should not be required if only :minimum is zero' do
282
272
  length_should_be_required(:tag => :title, :required => false, :options => {:minimum => 0})
283
273
  end
284
-
274
+
285
275
  it 'should not be required if only :minimum is not set' do
286
276
  length_should_be_required(:tag => :title, :required => false, :options => {:maximum => 5})
287
277
  end
288
-
278
+
289
279
  it 'should not be required if allow_blank is true' do
290
280
  length_should_be_required(:tag => :published, :required => false, :options => {:allow_blank => true})
291
281
  end
292
282
  end
293
-
283
+
294
284
  def add_presence_validator(options)
295
285
  @new_post.class.stub!(:validators_on).with(options[:tag]).and_return([
296
286
  active_model_presence_validator([options[:tag]], options[:options])
297
287
  ])
298
288
  end
299
-
289
+
300
290
  def add_length_validator(options)
301
291
  @new_post.class.should_receive(:validators_on).with(options[:tag]).any_number_of_times {[
302
292
  active_model_length_validator([options[:tag]], options[:options])
303
293
  ]}
304
294
  end
305
-
295
+
306
296
  # TODO make a matcher for this?
307
297
  def should_be_required(options)
308
298
  concat(semantic_form_for(@new_post) do |builder|
309
299
  concat(builder.input(options[:tag]))
310
300
  end)
311
-
301
+
312
302
  if options[:required]
313
- output_buffer.should_not have_tag('form div.clearfix.optional')
314
- output_buffer.should have_tag('form div.clearfix.required')
303
+ output_buffer.should_not have_tag('form div.optional')
304
+ output_buffer.should have_tag('form div.required')
315
305
  else
316
- output_buffer.should have_tag('form div.clearfix.optional')
317
- output_buffer.should_not have_tag('form div.clearfix.required')
306
+ output_buffer.should have_tag('form div.optional')
307
+ output_buffer.should_not have_tag('form div.required')
318
308
  end
319
309
  end
320
-
310
+
321
311
  def presence_should_be_required(options)
322
312
  add_presence_validator(options)
323
313
  should_be_required(options)
324
314
  end
325
-
315
+
326
316
  def length_should_be_required(options)
327
317
  add_length_validator(options)
328
318
  should_be_required(options)
329
319
  end
330
-
320
+
331
321
  # TODO JF reversed this during refactor, need to make sure
332
322
  describe 'and there are no requirement validations on the method' do
333
323
  before do
334
324
  @new_post.class.should_receive(:validators_on).with(:title).and_return([])
335
325
  end
336
-
326
+
337
327
  it 'should not be required' do
338
328
  concat(semantic_form_for(@new_post) do |builder|
339
329
  concat(builder.input(:title))
340
330
  end)
341
- output_buffer.should_not have_tag('form div.clearfix.required')
342
- output_buffer.should have_tag('form div.clearfix.optional')
331
+ output_buffer.should_not have_tag('form div.required')
332
+ output_buffer.should have_tag('form div.optional')
343
333
  end
344
334
  end
345
-
335
+
346
336
  end
347
-
337
+
348
338
  describe 'and an object without :validators_on' do
349
-
350
- before(:each) do
351
- @orig_all_fields_required = FormtasticBootstrap::FormBuilder.all_fields_required_by_default
352
- end
353
-
354
- after(:each) do
355
- FormtasticBootstrap::FormBuilder.all_fields_required_by_default = @orig_all_fields_required
356
- end
357
-
358
- it 'should use the default value' do
359
- FormtasticBootstrap::FormBuilder.all_fields_required_by_default.should == true
360
- FormtasticBootstrap::FormBuilder.all_fields_required_by_default = false
361
-
362
- concat(semantic_form_for(@new_post) do |builder|
363
- concat(builder.input(:title))
364
- end)
365
- output_buffer.should_not have_tag('form div.clearfix.required')
366
- output_buffer.should have_tag('form div.clearfix.optional')
367
-
368
- # Formtastic::FormBuilder.all_fields_required_by_default = true
339
+
340
+ it 'should use the default value' do
341
+ Formtastic::FormBuilder.all_fields_required_by_default.should == true
342
+ Formtastic::FormBuilder.all_fields_required_by_default = false
343
+
344
+ concat(semantic_form_for(@new_post) do |builder|
345
+ concat(builder.input(:title))
346
+ end)
347
+ output_buffer.should_not have_tag('form div.required')
348
+ output_buffer.should have_tag('form div.optional')
349
+
350
+ Formtastic::FormBuilder.all_fields_required_by_default = true
351
+ end
352
+
369
353
  end
370
-
371
- end
372
-
354
+
373
355
  end
374
-
356
+
375
357
  end
376
358
 
377
359
  describe ':as option' do
378
-
360
+
379
361
  describe 'when not provided' do
380
-
362
+
381
363
  it 'should default to a string for forms without objects unless column is password' do
382
364
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
383
365
  concat(builder.input(:anything))
384
366
  end)
385
- output_buffer.should have_tag('form div.clearfix.string')
367
+ output_buffer.should have_tag('form div.string')
386
368
  end
387
-
369
+
388
370
  it 'should default to password for forms without objects if column is password' do
389
371
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
390
372
  concat(builder.input(:password))
391
373
  concat(builder.input(:password_confirmation))
392
374
  concat(builder.input(:confirm_password))
393
375
  end)
394
- output_buffer.should have_tag('form div.clearfix.password', :count => 3)
376
+ output_buffer.should have_tag('form div.password', :count => 3)
395
377
  end
396
-
378
+
397
379
  it 'should default to a string for methods on objects that don\'t respond to "column_for_attribute"' do
398
380
  @new_post.stub!(:method_without_a_database_column)
399
381
  @new_post.stub!(:column_for_attribute).and_return(nil)
400
382
  default_input_type(nil, :method_without_a_database_column).should == :string
401
383
  end
402
-
384
+
403
385
  it 'should default to :password for methods that don\'t have a column in the database but "password" is in the method name' do
404
386
  @new_post.stub!(:password_method_without_a_database_column)
405
387
  @new_post.stub!(:column_for_attribute).and_return(nil)
406
388
  default_input_type(nil, :password_method_without_a_database_column).should == :password
407
389
  end
408
-
390
+
409
391
  it 'should default to :password for methods on objects that don\'t respond to "column_for_attribute" but "password" is in the method name' do
410
392
  @new_post.stub!(:password_method_without_a_database_column)
411
393
  @new_post.stub!(:column_for_attribute).and_return(nil)
412
394
  default_input_type(nil, :password_method_without_a_database_column).should == :password
413
395
  end
414
-
396
+
415
397
  it 'should default to :number for "integer" column with name ending in "_id"' do
416
398
  @new_post.stub!(:aws_instance_id)
417
399
  @new_post.stub!(:column_for_attribute).with(:aws_instance_id).and_return(mock('column', :type => :integer))
418
400
  default_input_type(:integer, :aws_instance_id).should == :number
419
401
  end
420
-
402
+
421
403
  it 'should default to :select for associations' do
422
404
  @new_post.class.stub!(:reflect_on_association).with(:user_id).and_return(mock('ActiveRecord::Reflection::AssociationReflection'))
423
405
  @new_post.class.stub!(:reflect_on_association).with(:section_id).and_return(mock('ActiveRecord::Reflection::AssociationReflection'))
424
406
  default_input_type(:integer, :user_id).should == :select
425
407
  default_input_type(:integer, :section_id).should == :select
426
408
  end
427
-
409
+
428
410
  it 'should default to :password for :string column types with "password" in the method name' do
429
411
  default_input_type(:string, :password).should == :password
430
412
  default_input_type(:string, :hashed_password).should == :password
431
413
  default_input_type(:string, :password_hash).should == :password
432
414
  end
433
-
415
+
434
416
  it 'should default to :text for :text column types' do
435
417
  default_input_type(:text).should == :text
436
418
  end
437
-
438
- it 'should default to :date for :date column types' do
439
- default_input_type(:date).should == :date
419
+
420
+ it 'should default to :date_select for :date column types' do
421
+ default_input_type(:date).should == :date_select
440
422
  end
441
-
442
- it 'should default to :datetime for :datetime and :timestamp column types' do
443
- default_input_type(:datetime).should == :datetime
444
- default_input_type(:timestamp).should == :datetime
423
+
424
+ it 'should default to :datetime_select for :datetime and :timestamp column types' do
425
+ default_input_type(:datetime).should == :datetime_select
426
+ default_input_type(:timestamp).should == :datetime_select
445
427
  end
446
-
447
- it 'should default to :time for :time column types' do
448
- default_input_type(:time).should == :time
428
+
429
+ it 'should default to :time_select for :time column types' do
430
+ default_input_type(:time).should == :time_select
449
431
  end
450
-
432
+
451
433
  it 'should default to :boolean for :boolean column types' do
452
434
  default_input_type(:boolean).should == :boolean
453
435
  end
454
-
436
+
455
437
  it 'should default to :string for :string column types' do
456
438
  default_input_type(:string).should == :string
457
439
  end
458
-
440
+
459
441
  it 'should default to :number for :integer, :float and :decimal column types' do
460
442
  default_input_type(:integer).should == :number
461
443
  default_input_type(:float).should == :number
462
444
  default_input_type(:decimal).should == :number
463
445
  end
464
-
446
+
465
447
  it 'should default to :country for :string columns named country' do
466
448
  default_input_type(:string, :country).should == :country
467
449
  end
468
-
450
+
469
451
  it 'should default to :email for :string columns matching email' do
470
452
  default_input_type(:string, :email).should == :email
471
453
  default_input_type(:string, :customer_email).should == :email
472
454
  default_input_type(:string, :email_work).should == :email
473
455
  end
474
-
456
+
475
457
  it 'should default to :url for :string columns named url or website' do
476
458
  default_input_type(:string, :url).should == :url
477
459
  default_input_type(:string, :website).should == :url
478
460
  default_input_type(:string, :my_url).should == :url
479
461
  default_input_type(:string, :hurl).should_not == :url
480
462
  end
481
-
463
+
482
464
  it 'should default to :phone for :string columns named phone or fax' do
483
465
  default_input_type(:string, :phone).should == :phone
484
466
  default_input_type(:string, :fax).should == :phone
485
467
  end
486
-
468
+
487
469
  it 'should default to :search for :string columns named search' do
488
470
  default_input_type(:string, :search).should == :search
489
471
  end
490
-
472
+
491
473
  describe 'defaulting to file column' do
492
- FormtasticBootstrap::FormBuilder.file_methods.each do |method|
474
+ Formtastic::FormBuilder.file_methods.each do |method|
493
475
  it "should default to :file for attributes that respond to ##{method}" do
494
476
  column = mock('column')
495
-
496
- FormtasticBootstrap::FormBuilder.file_methods.each do |test|
477
+
478
+ Formtastic::FormBuilder.file_methods.each do |test|
497
479
  ### TODO: Check if this is ok
498
480
  column.stub!(method).with(test).and_return(method == test)
499
481
  end
500
-
482
+
501
483
  @new_post.should_receive(method).and_return(column)
502
-
484
+
503
485
  semantic_form_for(@new_post) do |builder|
504
486
  builder.send(:default_input_type, method).should == :file
505
487
  end
506
488
  end
507
489
  end
508
-
490
+
509
491
  end
510
492
  end
511
-
493
+
512
494
  it 'should call the corresponding input class with .to_html' do
513
- # TODO Re-activate timezone test.
514
- # TODO Add for fancy Bootstrap types.
515
- # [:select, :time_zone, :radio, :date, :datetime, :time, :boolean, :check_boxes, :hidden, :string, :password, :number, :text, :file].each do |input_style|
516
- [:select, :radio, :date, :datetime, :time, :boolean, :check_boxes, :hidden, :string, :password, :number, :text, :file].each do |input_style|
495
+ [:select, :time_zone, :radio, :date_select, :datetime_select, :time_select, :boolean, :check_boxes, :hidden, :string, :password, :number, :text, :file].each do |input_style|
517
496
  @new_post.stub!(:generic_column_name)
518
497
  @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
519
498
  semantic_form_for(@new_post) do |builder|
520
499
  input_instance = mock('Input instance')
521
500
  input_class = "#{input_style.to_s}_input".classify
522
501
  input_constant = "FormtasticBootstrap::Inputs::#{input_class}".constantize
523
-
502
+
524
503
  input_constant.should_receive(:new).and_return(input_instance)
525
504
  input_instance.should_receive(:to_html).and_return("some HTML")
526
-
505
+
527
506
  concat(builder.input(:generic_column_name, :as => input_style))
528
507
  end
529
508
  end
530
509
  end
531
-
510
+
532
511
  end
533
512
 
534
513
  describe ':label option' do
535
-
514
+
536
515
  describe 'when provided' do
537
516
  it 'should be passed down to the label tag' do
538
517
  concat(semantic_form_for(@new_post) do |builder|
539
518
  concat(builder.input(:title, :label => "Kustom"))
540
519
  end)
541
- output_buffer.should have_tag("form div.clearfix label", /Kustom/)
520
+ output_buffer.should have_tag("form div label", /Kustom/)
542
521
  end
543
-
522
+
544
523
  it 'should not generate a label if false' do
545
524
  concat(semantic_form_for(@new_post) do |builder|
546
525
  concat(builder.input(:title, :label => false))
547
526
  end)
548
- output_buffer.should_not have_tag("form div.clearfix label")
527
+ output_buffer.should_not have_tag("form div label")
549
528
  end
550
-
529
+
551
530
  it 'should be dupped if frozen' do
552
531
  concat(semantic_form_for(@new_post) do |builder|
553
532
  concat(builder.input(:title, :label => "Kustom".freeze))
554
533
  end)
555
- output_buffer.should have_tag("form div.clearfix label", /Kustom/)
534
+ output_buffer.should have_tag("form div label", /Kustom/)
556
535
  end
557
536
  end
558
-
537
+
559
538
  describe 'when not provided' do
560
539
  describe 'when localized label is provided' do
561
540
  describe 'and object is given' do
@@ -570,17 +549,17 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
570
549
  :meta_description => @localized_label_text
571
550
  }
572
551
  }
573
-
552
+
574
553
  concat(semantic_form_for(@new_post) do |builder|
575
554
  concat(builder.input(:meta_description))
576
555
  end)
577
- output_buffer.should have_tag('form div.clearfix label', /Localized title/)
556
+ output_buffer.should have_tag('form div label', /Localized title/)
578
557
  end
579
558
  end
580
559
  end
581
560
  end
582
561
  end
583
-
562
+
584
563
  describe 'when localized label is NOT provided' do
585
564
  describe 'and object is not given' do
586
565
  it 'should default the humanized method name, passing it down to the label tag' do
@@ -589,37 +568,37 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
589
568
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
590
569
  concat(builder.input(:meta_description))
591
570
  end)
592
- output_buffer.should have_tag("form div.clearfix label", /#{'meta_description'.humanize}/)
571
+ output_buffer.should have_tag("form div label", /#{'meta_description'.humanize}/)
593
572
  end
594
573
  end
595
574
  end
596
-
575
+
597
576
  describe 'and object is given' do
598
577
  it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
599
578
  @new_post.stub!(:meta_description) # a two word method name
600
579
  @new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
601
-
580
+
602
581
  concat(semantic_form_for(@new_post) do |builder|
603
582
  concat(builder.input(:meta_description))
604
583
  end)
605
- output_buffer.should have_tag("form div.clearfix label", /#{'meta_description'.humanize}/)
584
+ output_buffer.should have_tag("form div label", /#{'meta_description'.humanize}/)
606
585
  end
607
586
  end
608
-
587
+
609
588
  describe 'and object is given with label_str_method set to :capitalize' do
610
589
  it 'should capitalize method name, passing it down to the label tag' do
611
590
  with_config :label_str_method, :capitalize do
612
591
  @new_post.stub!(:meta_description)
613
-
592
+
614
593
  concat(semantic_form_for(@new_post) do |builder|
615
594
  concat(builder.input(:meta_description))
616
595
  end)
617
- output_buffer.should have_tag("form div.clearfix label", /#{'meta_description'.capitalize}/)
596
+ output_buffer.should have_tag("form div label", /#{'meta_description'.capitalize}/)
618
597
  end
619
598
  end
620
599
  end
621
600
  end
622
-
601
+
623
602
  describe 'when localized label is provided' do
624
603
  before do
625
604
  @localized_label_text = 'Localized title'
@@ -636,17 +615,17 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
636
615
  }
637
616
  }
638
617
  end
639
-
618
+
640
619
  it 'should render a label with localized label (I18n)' do
641
620
  with_config :i18n_lookups_by_default, false do
642
621
  concat(semantic_form_for(@new_post) do |builder|
643
622
  concat(builder.input(:title, :label => true))
644
623
  concat(builder.input(:published, :as => :boolean, :label => true))
645
624
  end)
646
- output_buffer.should have_tag('form div.clearfix label', Regexp.new('^' + @localized_label_text))
625
+ output_buffer.should have_tag('form div label', Regexp.new('^' + @localized_label_text))
647
626
  end
648
627
  end
649
-
628
+
650
629
  it 'should render a hint paragraph containing an optional localized label (I18n) if first is not set' do
651
630
  with_config :i18n_lookups_by_default, false do
652
631
  ::I18n.backend.store_translations :en,
@@ -662,24 +641,20 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
662
641
  concat(builder.input(:title, :label => true))
663
642
  concat(builder.input(:published, :as => :boolean, :label => true))
664
643
  end)
665
- output_buffer.should have_tag('form div.clearfix label', Regexp.new('^' + @default_localized_label_text))
644
+ output_buffer.should have_tag('form div label', Regexp.new('^' + @default_localized_label_text))
666
645
  end
667
646
  end
668
647
  end
669
648
  end
670
-
649
+
671
650
  end
672
651
 
673
652
  describe ':hint option' do
674
653
 
675
654
  describe 'when provided' do
676
-
677
- before(:each) do
678
- @orig_hint_class = FormtasticBootstrap::FormBuilder.default_inline_hint_class
679
- end
680
655
 
681
- after(:each) do
682
- FormtasticBootstrap::FormBuilder.default_inline_hint_class = @orig_hint_class
656
+ after do
657
+ Formtastic::FormBuilder.default_hint_class = "inline-hints"
683
658
  end
684
659
 
685
660
  it 'should be passed down to the paragraph tag' do
@@ -687,31 +662,32 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
687
662
  concat(semantic_form_for(@new_post) do |builder|
688
663
  concat(builder.input(:title, :hint => hint_text))
689
664
  end)
690
- output_buffer.should have_tag("form div.clearfix div span.help-inline", hint_text)
665
+ output_buffer.should have_tag("form div p.inline-hints", hint_text)
691
666
  end
692
667
 
693
- it 'should have a custom hint class if I ask for one' do
694
- hint_text = "this is the title of the post"
695
- concat(semantic_form_for(@new_post) do |builder|
696
- concat(builder.input(:title, :hint => hint_text, :hint_class => 'custom-hint-class'))
697
- end)
698
- output_buffer.should have_tag("form div.clearfix div span.custom-hint-class", hint_text)
668
+ it 'should have a custom hint class if I ask for one' do
669
+ with_deprecation_silenced do
670
+ hint_text = "this is the title of the post"
671
+ concat(semantic_form_for(@new_post) do |builder|
672
+ concat(builder.input(:title, :hint => hint_text, :hint_class => 'custom-hint-class'))
673
+ end)
674
+ output_buffer.should have_tag("form div p.custom-hint-class", hint_text)
675
+ end
699
676
  end
700
677
 
701
678
  it 'should have a custom hint class defaulted for all forms' do
702
679
  hint_text = "this is the title of the post"
703
- # FormtasticBootstrap::FormBuilder.default_hint_class = "custom-hint-class"
704
- FormtasticBootstrap::FormBuilder.default_inline_hint_class = "custom-hint-class"
680
+ Formtastic::FormBuilder.default_hint_class = "custom-hint-class"
705
681
  concat(semantic_form_for(@new_post) do |builder|
706
682
  concat(builder.input(:title, :hint => hint_text))
707
683
  end)
708
- output_buffer.should have_tag("form div.clearfix div span.custom-hint-class", hint_text)
684
+ output_buffer.should have_tag("form div p.custom-hint-class", hint_text)
709
685
  end
710
686
  end
711
687
 
712
688
  describe 'when not provided' do
713
689
  describe 'when localized hint (I18n) is provided' do
714
- before(:each) do
690
+ before do
715
691
  @localized_hint_text = "This is the localized hint."
716
692
  @default_localized_hint_text = "This is the default localized hint."
717
693
  ::I18n.backend.store_translations :en,
@@ -722,7 +698,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
722
698
  }
723
699
  end
724
700
 
725
- after(:each) do
701
+ after do
726
702
  ::I18n.backend.reload!
727
703
  end
728
704
 
@@ -740,11 +716,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
740
716
  concat(semantic_form_for(@new_post) do |builder|
741
717
  concat(builder.input(:title, :hint => true))
742
718
  end)
743
- output_buffer.should have_tag('form div.clearfix div span.help-inline', @localized_hint_text)
719
+ output_buffer.should have_tag('form div p.inline-hints', @localized_hint_text)
744
720
  end
745
721
  end
746
722
 
747
- it 'should render a hint paragraph containing a localized hint (I18n) with a custom hint class if i ask for one' do
723
+ it 'should render a hint paragraph containing a localized hint (I18n) with a custom hint class if i ask for one' do
748
724
  with_config :i18n_lookups_by_default, false do
749
725
  ::I18n.backend.store_translations :en,
750
726
  :formtastic => {
@@ -754,10 +730,12 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
754
730
  }
755
731
  }
756
732
  }
757
- concat(semantic_form_for(@new_post) do |builder|
758
- concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
759
- end)
760
- output_buffer.should have_tag('form div.clearfix div span.custom-hint-class', @localized_hint_text)
733
+ with_deprecation_silenced do
734
+ concat(semantic_form_for(@new_post) do |builder|
735
+ concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
736
+ end)
737
+ end
738
+ output_buffer.should have_tag('form div p.custom-hint-class', @localized_hint_text)
761
739
  end
762
740
  end
763
741
 
@@ -766,7 +744,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
766
744
  concat(semantic_form_for(@new_post) do |builder|
767
745
  concat(builder.input(:title, :hint => true))
768
746
  end)
769
- output_buffer.should have_tag('form div.clearfix div span.help-inline', @default_localized_hint_text)
747
+ output_buffer.should have_tag('form div p.inline-hints', @default_localized_hint_text)
770
748
  end
771
749
  end
772
750
  end
@@ -777,7 +755,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
777
755
  concat(semantic_form_for(@new_post) do |builder|
778
756
  concat(builder.input(:title, :hint => false))
779
757
  end)
780
- output_buffer.should_not have_tag('form div.clearfix div span.help-inline', @localized_hint_text)
758
+ output_buffer.should_not have_tag('form div p.inline-hints', @localized_hint_text)
781
759
  end
782
760
  end
783
761
  end
@@ -797,7 +775,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
797
775
  semantic_form_for(@new_post) do |builder|
798
776
  concat(builder.input(:title, :hint => true))
799
777
  end
800
- output_buffer.should_not have_tag('form div.clearfix div span.help-inline', @localized_hint_text)
778
+ output_buffer.should_not have_tag('form div p.inline-hints', @localized_hint_text)
801
779
  end
802
780
  end
803
781
  end
@@ -808,7 +786,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
808
786
  concat(semantic_form_for(@new_post) do |builder|
809
787
  concat(builder.input(:title))
810
788
  end)
811
- output_buffer.should_not have_tag('form div.clearfix div span.help-inline')
789
+ output_buffer.should_not have_tag('form div p.inline-hints')
812
790
  end
813
791
  end
814
792
  end
@@ -817,48 +795,48 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
817
795
  end
818
796
 
819
797
  describe ':wrapper_html option' do
820
-
798
+
821
799
  describe 'when provided' do
822
- it 'should be passed down to the li tag' do
800
+ it 'should be passed down to the div tag' do
823
801
  concat(semantic_form_for(@new_post) do |builder|
824
802
  concat(builder.input(:title, :wrapper_html => {:id => :another_id}))
825
803
  end)
826
804
  output_buffer.should have_tag("form div#another_id")
827
805
  end
828
-
829
- it 'should append given classes to li default classes' do
806
+
807
+ it 'should append given classes to div default classes' do
830
808
  concat(semantic_form_for(@new_post) do |builder|
831
809
  concat(builder.input(:title, :wrapper_html => {:class => :another_class}, :required => true))
832
810
  end)
833
- output_buffer.should have_tag("form div.clearfix.string")
834
- output_buffer.should have_tag("form div.clearfix.required")
835
- output_buffer.should have_tag("form div.clearfix.another_class")
811
+ output_buffer.should have_tag("form div.string")
812
+ output_buffer.should have_tag("form div.required")
813
+ output_buffer.should have_tag("form div.another_class")
836
814
  end
837
-
815
+
838
816
  it 'should allow classes to be an array' do
839
817
  concat(semantic_form_for(@new_post) do |builder|
840
818
  concat(builder.input(:title, :wrapper_html => {:class => [ :my_class, :another_class ]}))
841
819
  end)
842
- output_buffer.should have_tag("form div.clearfix.string")
843
- output_buffer.should have_tag("form div.clearfix.my_class")
844
- output_buffer.should have_tag("form div.clearfix.another_class")
820
+ output_buffer.should have_tag("form div.string")
821
+ output_buffer.should have_tag("form div.my_class")
822
+ output_buffer.should have_tag("form div.another_class")
845
823
  end
846
824
  end
847
-
848
- # describe 'when not provided' do
849
- # it 'should use default id and class' do
850
- # concat(semantic_form_for(@new_post) do |builder|
851
- # concat(builder.input(:title))
852
- # end)
853
- # output_buffer.should have_tag("form div#post_title_input")
854
- # output_buffer.should have_tag("form div.clearfix.string")
855
- # end
856
- # end
857
- #
825
+
826
+ describe 'when not provided' do
827
+ it 'should use default id and class' do
828
+ concat(semantic_form_for(@new_post) do |builder|
829
+ concat(builder.input(:title))
830
+ end)
831
+ output_buffer.should have_tag("form div#post_title_input")
832
+ output_buffer.should have_tag("form div.string")
833
+ end
834
+ end
835
+
858
836
  end
859
837
 
860
838
  describe ':collection option' do
861
-
839
+
862
840
  it "should be required on polymorphic associations" do
863
841
  @new_post.stub!(:commentable)
864
842
  @new_post.class.stub!(:reflections).and_return({
@@ -878,28 +856,29 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
878
856
  end)
879
857
  }.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
880
858
  end
881
-
859
+
882
860
  end
883
861
 
884
862
  end
885
863
 
886
864
  describe 'options re-use' do
887
-
865
+
888
866
  it 'should retain :as option when re-using the same options hash' do
889
867
  my_options = { :as => :string }
890
868
  output = ''
891
-
869
+
892
870
  concat(semantic_form_for(@new_post) do |builder|
893
871
  concat(builder.input(:title, my_options))
894
872
  concat(builder.input(:publish_at, my_options))
895
873
  end)
896
- output_buffer.should have_tag 'div.clearfix.string', :count => 2
874
+ output_buffer.should have_tag 'div.string', :count => 2
897
875
  end
898
876
 
877
+
899
878
  end
900
879
 
901
880
  describe 'instantiating an input class' do
902
-
881
+
903
882
  context 'when a class does not exist' do
904
883
  it "should raise an error" do
905
884
  lambda {
@@ -909,36 +888,36 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
909
888
  }.should raise_error(Formtastic::UnknownInputError)
910
889
  end
911
890
  end
912
-
891
+
913
892
  context 'when a customized top-level class does not exist' do
914
-
893
+
915
894
  it 'should instantiate the Formtastic input' do
916
895
  input = mock('input', :to_html => 'some HTML')
917
- FormtasticBootstrap::Inputs::StringInput.should_receive(:new).and_return(input)
896
+ Formtastic::Inputs::StringInput.should_receive(:new).and_return(input)
918
897
  concat(semantic_form_for(@new_post) do |builder|
919
898
  builder.input(:title, :as => :string)
920
899
  end)
921
900
  end
922
-
901
+
923
902
  end
924
-
903
+
925
904
  describe 'when a top-level input class exists' do
926
905
  it "should instantiate the top-level input instead of the Formtastic one" do
927
- class ::StringInput < FormtasticBootstrap::Inputs::StringInput
906
+ class ::StringInput < Formtastic::Inputs::StringInput
928
907
  end
929
-
908
+
930
909
  input = mock('input', :to_html => 'some HTML')
931
- FormtasticBootstrap::Inputs::StringInput.should_not_receive(:new).and_return(input)
910
+ Formtastic::Inputs::StringInput.should_not_receive(:new).and_return(input)
932
911
  ::StringInput.should_receive(:new).and_return(input)
933
-
912
+
934
913
  concat(semantic_form_for(@new_post) do |builder|
935
914
  builder.input(:title, :as => :string)
936
915
  end)
937
916
  end
938
917
  end
939
-
918
+
940
919
  describe 'when instantiated multiple times with the same input type' do
941
-
920
+
942
921
  it "should be cached (not calling the internal methods)" do
943
922
  # TODO this is really tied to the underlying implementation
944
923
  concat(semantic_form_for(@new_post) do |builder|
@@ -947,9 +926,9 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
947
926
  builder.input(:title, :as => :string)
948
927
  end)
949
928
  end
950
-
929
+
951
930
  end
952
-
931
+
953
932
  end
954
933
 
955
934
  end