speedo-formstrap 1.2.0 → 1.2.1

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 (82) hide show
  1. data/README.md +2 -2
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/formtastic-bootstrap.gemspec +1 -1
  5. data/lib/formtastic-bootstrap.rb +5 -5
  6. data/lib/formtastic-bootstrap/actions.rb +4 -4
  7. data/lib/formtastic-bootstrap/actions/base.rb +1 -1
  8. data/lib/formtastic-bootstrap/actions/button_action.rb +1 -1
  9. data/lib/formtastic-bootstrap/actions/input_action.rb +1 -1
  10. data/lib/formtastic-bootstrap/actions/link_action.rb +1 -1
  11. data/lib/formtastic-bootstrap/engine.rb +1 -1
  12. data/lib/formtastic-bootstrap/form_builder.rb +9 -11
  13. data/lib/formtastic-bootstrap/helpers.rb +6 -8
  14. data/lib/formtastic-bootstrap/helpers/action_helper.rb +2 -2
  15. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +2 -2
  16. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +10 -14
  17. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +7 -12
  18. data/lib/formtastic-bootstrap/helpers/input_helper.rb +2 -2
  19. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +6 -6
  20. data/lib/formtastic-bootstrap/inputs.rb +21 -21
  21. data/lib/formtastic-bootstrap/inputs/base.rb +10 -11
  22. data/lib/formtastic-bootstrap/inputs/base/choices.rb +24 -13
  23. data/lib/formtastic-bootstrap/inputs/base/errors.rb +1 -1
  24. data/lib/formtastic-bootstrap/inputs/base/hints.rb +1 -1
  25. data/lib/formtastic-bootstrap/inputs/base/html.rb +1 -1
  26. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +7 -17
  27. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +1 -1
  28. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +1 -1
  29. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +13 -6
  30. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +15 -33
  31. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +1 -1
  32. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +1 -1
  33. data/lib/formtastic-bootstrap/inputs/date_input.rb +1 -1
  34. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +1 -1
  35. data/lib/formtastic-bootstrap/inputs/email_input.rb +1 -1
  36. data/lib/formtastic-bootstrap/inputs/file_input.rb +1 -1
  37. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +1 -1
  38. data/lib/formtastic-bootstrap/inputs/number_input.rb +3 -3
  39. data/lib/formtastic-bootstrap/inputs/password_input.rb +1 -1
  40. data/lib/formtastic-bootstrap/inputs/phone_input.rb +1 -1
  41. data/lib/formtastic-bootstrap/inputs/radio_input.rb +13 -14
  42. data/lib/formtastic-bootstrap/inputs/range_input.rb +3 -3
  43. data/lib/formtastic-bootstrap/inputs/search_input.rb +1 -1
  44. data/lib/formtastic-bootstrap/inputs/select_input.rb +1 -1
  45. data/lib/formtastic-bootstrap/inputs/string_input.rb +1 -1
  46. data/lib/formtastic-bootstrap/inputs/text_input.rb +1 -1
  47. data/lib/formtastic-bootstrap/inputs/time_input.rb +1 -1
  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/spec/actions/button_action_spec.rb +1 -1
  51. data/spec/actions/generic_action_spec.rb +1 -1
  52. data/spec/actions/input_action_spec.rb +1 -1
  53. data/spec/actions/link_action_spec.rb +1 -1
  54. data/spec/builder/semantic_fields_for_spec.rb +16 -16
  55. data/spec/helpers/action_helper_spec.rb +1 -1
  56. data/spec/helpers/actions_helper_spec.rb +1 -1
  57. data/spec/helpers/buttons_helper_spec.rb +46 -56
  58. data/spec/helpers/input_helper_spec.rb +209 -209
  59. data/spec/helpers/inputs_helper_spec.rb +103 -117
  60. data/spec/inputs/boolean_input_spec.rb +46 -74
  61. data/spec/inputs/check_boxes_input_spec.rb +82 -110
  62. data/spec/inputs/date_input_spec.rb +15 -81
  63. data/spec/inputs/datetime_input_spec.rb +13 -13
  64. data/spec/inputs/email_input_spec.rb +6 -34
  65. data/spec/inputs/file_input_spec.rb +6 -34
  66. data/spec/inputs/hidden_input_spec.rb +13 -41
  67. data/spec/inputs/number_input_spec.rb +97 -127
  68. data/spec/inputs/password_input_spec.rb +6 -34
  69. data/spec/inputs/phone_input_spec.rb +6 -34
  70. data/spec/inputs/radio_input_spec.rb +45 -73
  71. data/spec/inputs/range_input_spec.rb +66 -94
  72. data/spec/inputs/search_input_spec.rb +6 -33
  73. data/spec/inputs/select_input_spec.rb +78 -124
  74. data/spec/inputs/string_input_spec.rb +22 -67
  75. data/spec/inputs/text_input_spec.rb +15 -42
  76. data/spec/inputs/time_input_spec.rb +23 -23
  77. data/spec/inputs/time_zone_input_spec.rb +20 -20
  78. data/spec/inputs/url_input_spec.rb +6 -34
  79. data/spec/support/custom_macros.rb +196 -67
  80. data/spec/support/formtastic_spec_helper.rb +6 -22
  81. data/speedo-formstrap.gemspec +146 -0
  82. metadata +18 -17
@@ -8,15 +8,15 @@ describe 'number input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
12
12
 
13
13
  @new_post.class.stub!(:validators_on).with(:title).and_return([
14
14
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
15
15
  ])
16
16
  end
17
-
17
+
18
18
  describe "all cases" do
19
-
19
+
20
20
  before do
21
21
  concat(
22
22
  semantic_form_for(@new_post) do |builder|
@@ -25,9 +25,8 @@ describe 'number input' do
25
25
  )
26
26
  end
27
27
 
28
- it_should_have_input_wrapper_with_class('number-wrapper')
29
- it_should_have_input_wrapper_with_class("control-group")
30
- it_should_have_input_wrapper_with_class(:numeric)
28
+ it_should_have_input_wrapper_with_class(:number)
29
+ it_should_have_input_wrapper_with_class(:clearfix)
31
30
  it_should_have_input_wrapper_with_class(:stringish)
32
31
  it_should_have_input_class_in_the_right_place
33
32
  it_should_have_input_wrapper_with_id("post_title_input")
@@ -36,13 +35,12 @@ describe 'number input' do
36
35
  it_should_have_input_with_id("post_title")
37
36
  it_should_have_input_with_type(:number)
38
37
  it_should_have_input_with_name("post[title]")
39
- # @todo this is not testing what it should be testing!
40
- # it_should_use_default_text_field_size_when_not_nil(:string)
41
- # it_should_not_use_default_text_field_size_when_nil(:string)
42
- # it_should_apply_custom_input_attributes_when_input_html_provided(:string)
43
- # it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
38
+ it_should_use_default_text_field_size_when_not_nil(:string)
39
+ it_should_not_use_default_text_field_size_when_nil(:string)
40
+ it_should_apply_custom_input_attributes_when_input_html_provided(:string)
41
+ it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
44
42
  it_should_apply_error_logic_for_input_type(:number)
45
-
43
+
46
44
  end
47
45
 
48
46
  describe "when no object is provided" do
@@ -51,7 +49,7 @@ describe 'number input' do
51
49
  concat(builder.input(:title, :as => :number, :input_html => { :min => 1, :max => 2 }))
52
50
  end)
53
51
  end
54
-
52
+
55
53
  it_should_have_label_with_text(/Title/)
56
54
  it_should_have_label_for("project_title")
57
55
  it_should_have_input_with_id("project_title")
@@ -65,42 +63,14 @@ describe 'number input' do
65
63
  concat(builder.input(:title, :as => :number))
66
64
  end)
67
65
  end
68
-
66
+
69
67
  it_should_have_input_wrapper_with_id("context2_post_title_input")
70
68
  it_should_have_label_and_input_with_id("context2_post_title")
71
69
  end
72
-
73
- describe "when index is provided" do
74
-
75
- before do
76
- @output_buffer = ''
77
- mock_everything
78
-
79
- concat(semantic_form_for(@new_post) do |builder|
80
- concat(builder.fields_for(:author, :index => 3) do |author|
81
- concat(author.input(:name, :as => :number))
82
- end)
83
- end)
84
- end
85
-
86
- it 'should index the id of the wrapper' do
87
- output_buffer.should have_tag("div#post_author_attributes_3_name_input")
88
- end
89
-
90
- it 'should index the id of the select tag' do
91
- output_buffer.should have_tag("input#post_author_attributes_3_name")
92
- end
93
-
94
- it 'should index the name of the select tag' do
95
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
96
- end
97
-
98
- end
99
-
100
-
70
+
101
71
  describe "when required" do
102
72
  it "should add the required attribute to the input's html options" do
103
- with_config :use_required_attribute, true do
73
+ with_config :use_required_attribute, true do
104
74
  concat(semantic_form_for(@new_post) do |builder|
105
75
  concat(builder.input(:title, :as => :number, :required => true))
106
76
  end)
@@ -108,47 +78,47 @@ describe 'number input' do
108
78
  end
109
79
  end
110
80
  end
111
-
81
+
112
82
  describe "when validations require a minimum value (:greater_than)" do
113
83
  before do
114
84
  @new_post.class.stub!(:validators_on).with(:title).and_return([
115
85
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
116
86
  ])
117
87
  end
118
-
88
+
119
89
  it "should allow :input_html to override :min" do
120
90
  concat(semantic_form_for(@new_post) do |builder|
121
91
  builder.input(:title, :as => :number, :input_html => { :min => 5 })
122
92
  end)
123
93
  output_buffer.should have_tag('input[@min="5"]')
124
94
  end
125
-
95
+
126
96
  it "should allow :input_html to override :min through :in" do
127
97
  concat(semantic_form_for(@new_post) do |builder|
128
98
  builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
129
99
  end)
130
100
  output_buffer.should have_tag('input[@min="5"]')
131
101
  end
132
-
102
+
133
103
  it "should allow options to override :min" do
134
104
  concat(semantic_form_for(@new_post) do |builder|
135
105
  builder.input(:title, :as => :number, :min => 5)
136
106
  end)
137
107
  output_buffer.should have_tag('input[@min="5"]')
138
108
  end
139
-
109
+
140
110
  it "should allow options to override :min through :in" do
141
111
  concat(semantic_form_for(@new_post) do |builder|
142
112
  builder.input(:title, :as => :number, :in => 5..102)
143
113
  end)
144
114
  output_buffer.should have_tag('input[@min="5"]')
145
115
  end
146
-
116
+
147
117
  describe "and the column is an integer" do
148
118
  before do
149
119
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
150
120
  end
151
-
121
+
152
122
  it "should add a min attribute to the input one greater than the validation" do
153
123
  concat(semantic_form_for(@new_post) do |builder|
154
124
  builder.input(:title, :as => :number)
@@ -156,12 +126,12 @@ describe 'number input' do
156
126
  output_buffer.should have_tag('input[@min="3"]')
157
127
  end
158
128
  end
159
-
129
+
160
130
  describe "and the column is a float" do
161
131
  before do
162
132
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
163
133
  end
164
-
134
+
165
135
  it "should raise an error" do
166
136
  lambda {
167
137
  concat(semantic_form_for(@new_post) do |builder|
@@ -170,12 +140,12 @@ describe 'number input' do
170
140
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
171
141
  end
172
142
  end
173
-
143
+
174
144
  describe "and the column is a big decimal" do
175
145
  before do
176
146
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
177
147
  end
178
-
148
+
179
149
  it "should raise an error" do
180
150
  lambda {
181
151
  concat(semantic_form_for(@new_post) do |builder|
@@ -184,49 +154,49 @@ describe 'number input' do
184
154
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
185
155
  end
186
156
  end
187
-
157
+
188
158
  end
189
-
159
+
190
160
  describe "when validations require a minimum value (:greater_than) that takes a proc" do
191
161
  before do
192
162
  @new_post.class.stub!(:validators_on).with(:title).and_return([
193
163
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=> Proc.new {|post| 2}})
194
164
  ])
195
165
  end
196
-
166
+
197
167
  it "should allow :input_html to override :min" do
198
168
  concat(semantic_form_for(@new_post) do |builder|
199
169
  builder.input(:title, :as => :number, :input_html => { :min => 5 })
200
170
  end)
201
171
  output_buffer.should have_tag('input[@min="5"]')
202
172
  end
203
-
173
+
204
174
  it "should allow :input_html to override :min through :in" do
205
175
  concat(semantic_form_for(@new_post) do |builder|
206
176
  builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
207
177
  end)
208
178
  output_buffer.should have_tag('input[@min="5"]')
209
179
  end
210
-
180
+
211
181
  it "should allow options to override :min" do
212
182
  concat(semantic_form_for(@new_post) do |builder|
213
183
  builder.input(:title, :as => :number, :min => 5)
214
184
  end)
215
185
  output_buffer.should have_tag('input[@min="5"]')
216
186
  end
217
-
187
+
218
188
  it "should allow options to override :min through :in" do
219
189
  concat(semantic_form_for(@new_post) do |builder|
220
190
  builder.input(:title, :as => :number, :in => 5..102)
221
191
  end)
222
192
  output_buffer.should have_tag('input[@min="5"]')
223
193
  end
224
-
194
+
225
195
  describe "and the column is an integer" do
226
196
  before do
227
197
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
228
198
  end
229
-
199
+
230
200
  it "should add a min attribute to the input one greater than the validation" do
231
201
  concat(semantic_form_for(@new_post) do |builder|
232
202
  builder.input(:title, :as => :number)
@@ -234,12 +204,12 @@ describe 'number input' do
234
204
  output_buffer.should have_tag('input[@min="3"]')
235
205
  end
236
206
  end
237
-
207
+
238
208
  describe "and the column is a float" do
239
209
  before do
240
210
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
241
211
  end
242
-
212
+
243
213
  it "should raise an error" do
244
214
  lambda {
245
215
  concat(semantic_form_for(@new_post) do |builder|
@@ -248,12 +218,12 @@ describe 'number input' do
248
218
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
249
219
  end
250
220
  end
251
-
221
+
252
222
  describe "and the column is a big decimal" do
253
223
  before do
254
224
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
255
225
  end
256
-
226
+
257
227
  it "should raise an error" do
258
228
  lambda {
259
229
  concat(semantic_form_for(@new_post) do |builder|
@@ -262,23 +232,23 @@ describe 'number input' do
262
232
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
263
233
  end
264
234
  end
265
-
235
+
266
236
  end
267
-
237
+
268
238
  describe "when validations require a minimum value (:greater_than_or_equal_to)" do
269
239
  before do
270
240
  @new_post.class.stub!(:validators_on).with(:title).and_return([
271
241
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
272
242
  ])
273
243
  end
274
-
244
+
275
245
  it "should allow :input_html to override :min" do
276
246
  concat(semantic_form_for(@new_post) do |builder|
277
247
  builder.input(:title, :as => :number, :input_html => { :min => 5 })
278
248
  end)
279
249
  output_buffer.should have_tag('input[@min="5"]')
280
250
  end
281
-
251
+
282
252
  it "should allow options to override :min" do
283
253
  concat(semantic_form_for(@new_post) do |builder|
284
254
  builder.input(:title, :as => :number, :min => 5)
@@ -292,14 +262,14 @@ describe 'number input' do
292
262
  end)
293
263
  output_buffer.should have_tag('input[@min="5"]')
294
264
  end
295
-
265
+
296
266
  it "should allow options to override :min with :in" do
297
267
  concat(semantic_form_for(@new_post) do |builder|
298
268
  builder.input(:title, :as => :number, :in => 5..102)
299
269
  end)
300
270
  output_buffer.should have_tag('input[@min="5"]')
301
271
  end
302
-
272
+
303
273
 
304
274
  [:integer, :decimal, :float].each do |column_type|
305
275
  describe "and the column is a #{column_type}" do
@@ -320,7 +290,7 @@ describe 'number input' do
320
290
  before do
321
291
  @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
322
292
  end
323
-
293
+
324
294
  it "should add a max attribute to the input equal to the validation" do
325
295
  concat(semantic_form_for(@new_post) do |builder|
326
296
  builder.input(:title, :as => :number)
@@ -329,7 +299,7 @@ describe 'number input' do
329
299
  end
330
300
  end
331
301
  end
332
-
302
+
333
303
  describe "when validations require a minimum value (:greater_than_or_equal_to) that takes a Proc" do
334
304
  before do
335
305
  @new_post.class.stub!(:validators_on).with(:title).and_return([
@@ -396,27 +366,27 @@ describe 'number input' do
396
366
  end
397
367
 
398
368
  describe "when validations require a maximum value (:less_than)" do
399
-
369
+
400
370
  before do
401
371
  @new_post.class.stub!(:validators_on).with(:title).and_return([
402
372
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
403
373
  ])
404
374
  end
405
-
375
+
406
376
  it "should allow :input_html to override :max" do
407
377
  concat(semantic_form_for(@new_post) do |builder|
408
378
  builder.input(:title, :as => :number, :input_html => { :max => 102 })
409
379
  end)
410
380
  output_buffer.should have_tag('input[@max="102"]')
411
381
  end
412
-
382
+
413
383
  it "should allow option to override :max" do
414
384
  concat(semantic_form_for(@new_post) do |builder|
415
385
  builder.input(:title, :as => :number, :max => 102)
416
386
  end)
417
387
  output_buffer.should have_tag('input[@max="102"]')
418
388
  end
419
-
389
+
420
390
  it "should allow :input_html to override :max with :in" do
421
391
  concat(semantic_form_for(@new_post) do |builder|
422
392
  builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
@@ -430,12 +400,12 @@ describe 'number input' do
430
400
  end)
431
401
  output_buffer.should have_tag('input[@max="102"]')
432
402
  end
433
-
403
+
434
404
  describe "and the column is an integer" do
435
405
  before do
436
406
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
437
407
  end
438
-
408
+
439
409
  it "should add a max attribute to the input one greater than the validation" do
440
410
  concat(semantic_form_for(@new_post) do |builder|
441
411
  builder.input(:title, :as => :number)
@@ -443,12 +413,12 @@ describe 'number input' do
443
413
  output_buffer.should have_tag('input[@max="19"]')
444
414
  end
445
415
  end
446
-
416
+
447
417
  describe "and the column is a float" do
448
418
  before do
449
419
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
450
420
  end
451
-
421
+
452
422
  it "should raise an error" do
453
423
  lambda {
454
424
  concat(semantic_form_for(@new_post) do |builder|
@@ -457,12 +427,12 @@ describe 'number input' do
457
427
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
458
428
  end
459
429
  end
460
-
430
+
461
431
  describe "and the column is a big decimal" do
462
432
  before do
463
433
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
464
434
  end
465
-
435
+
466
436
  it "should raise an error" do
467
437
  lambda {
468
438
  concat(semantic_form_for(@new_post) do |builder|
@@ -477,29 +447,29 @@ describe 'number input' do
477
447
  end
478
448
  end
479
449
  end
480
-
450
+
481
451
  describe "when validations require a maximum value (:less_than) that takes a Proc" do
482
-
452
+
483
453
  before do
484
454
  @new_post.class.stub!(:validators_on).with(:title).and_return([
485
455
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=> Proc.new {|post| 20 }})
486
456
  ])
487
457
  end
488
-
458
+
489
459
  it "should allow :input_html to override :max" do
490
460
  concat(semantic_form_for(@new_post) do |builder|
491
461
  builder.input(:title, :as => :number, :input_html => { :max => 102 })
492
462
  end)
493
463
  output_buffer.should have_tag('input[@max="102"]')
494
464
  end
495
-
465
+
496
466
  it "should allow option to override :max" do
497
467
  concat(semantic_form_for(@new_post) do |builder|
498
468
  builder.input(:title, :as => :number, :max => 102)
499
469
  end)
500
470
  output_buffer.should have_tag('input[@max="102"]')
501
471
  end
502
-
472
+
503
473
  it "should allow :input_html to override :max with :in" do
504
474
  concat(semantic_form_for(@new_post) do |builder|
505
475
  builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
@@ -513,12 +483,12 @@ describe 'number input' do
513
483
  end)
514
484
  output_buffer.should have_tag('input[@max="102"]')
515
485
  end
516
-
486
+
517
487
  describe "and the column is an integer" do
518
488
  before do
519
489
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
520
490
  end
521
-
491
+
522
492
  it "should add a max attribute to the input one greater than the validation" do
523
493
  concat(semantic_form_for(@new_post) do |builder|
524
494
  builder.input(:title, :as => :number)
@@ -526,12 +496,12 @@ describe 'number input' do
526
496
  output_buffer.should have_tag('input[@max="19"]')
527
497
  end
528
498
  end
529
-
499
+
530
500
  describe "and the column is a float" do
531
501
  before do
532
502
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
533
503
  end
534
-
504
+
535
505
  it "should raise an error" do
536
506
  lambda {
537
507
  concat(semantic_form_for(@new_post) do |builder|
@@ -540,12 +510,12 @@ describe 'number input' do
540
510
  }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
541
511
  end
542
512
  end
543
-
513
+
544
514
  describe "and the column is a big decimal" do
545
515
  before do
546
516
  @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
547
517
  end
548
-
518
+
549
519
  it "should raise an error" do
550
520
  lambda {
551
521
  concat(semantic_form_for(@new_post) do |builder|
@@ -560,36 +530,36 @@ describe 'number input' do
560
530
  end
561
531
  end
562
532
  end
563
-
564
-
533
+
534
+
565
535
  describe "when validations require a maximum value (:less_than_or_equal_to)" do
566
536
  before do
567
537
  @new_post.class.stub!(:validators_on).with(:title).and_return([
568
538
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
569
539
  ])
570
540
  end
571
-
541
+
572
542
  it "should allow :input_html to override :max" do
573
543
  concat(semantic_form_for(@new_post) do |builder|
574
544
  builder.input(:title, :as => :number, :input_html => { :max => 102 })
575
545
  end)
576
546
  output_buffer.should have_tag('input[@max="102"]')
577
547
  end
578
-
548
+
579
549
  it "should allow options to override :max" do
580
550
  concat(semantic_form_for(@new_post) do |builder|
581
551
  builder.input(:title, :as => :number, :max => 102)
582
552
  end)
583
553
  output_buffer.should have_tag('input[@max="102"]')
584
554
  end
585
-
555
+
586
556
  it "should allow :input_html to override :max with :in" do
587
557
  concat(semantic_form_for(@new_post) do |builder|
588
558
  builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
589
559
  end)
590
560
  output_buffer.should have_tag('input[@max="102"]')
591
561
  end
592
-
562
+
593
563
  it "should allow options to override :max with :in" do
594
564
  concat(semantic_form_for(@new_post) do |builder|
595
565
  builder.input(:title, :as => :number, :in => 1..102)
@@ -616,7 +586,7 @@ describe 'number input' do
616
586
  before do
617
587
  @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
618
588
  end
619
-
589
+
620
590
  it "should add a max attribute to the input equal to the validation" do
621
591
  concat(semantic_form_for(@new_post) do |builder|
622
592
  builder.input(:title, :as => :number)
@@ -625,7 +595,7 @@ describe 'number input' do
625
595
  end
626
596
  end
627
597
  end
628
-
598
+
629
599
  describe "when validations require a maximum value (:less_than_or_equal_to) that takes a proc" do
630
600
  before do
631
601
  @new_post.class.stub!(:validators_on).with(:title).and_return([
@@ -689,14 +659,14 @@ describe 'number input' do
689
659
  end
690
660
  end
691
661
  end
692
-
662
+
693
663
  describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
694
664
  before do
695
665
  @new_post.class.stub!(:validators_on).with(:title).and_return([
696
666
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
697
667
  ])
698
668
  end
699
-
669
+
700
670
  it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
701
671
  concat(semantic_form_for(@new_post) do |builder|
702
672
  builder.input(:title, :as => :number)
@@ -704,14 +674,14 @@ describe 'number input' do
704
674
  output_buffer.should have_tag('input[@min="2"]')
705
675
  end
706
676
  end
707
-
677
+
708
678
  describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
709
679
  before do
710
680
  @new_post.class.stub!(:validators_on).with(:title).and_return([
711
681
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
712
682
  ])
713
683
  end
714
-
684
+
715
685
  it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
716
686
  concat(semantic_form_for(@new_post) do |builder|
717
687
  builder.input(:title, :as => :number)
@@ -719,99 +689,99 @@ describe 'number input' do
719
689
  output_buffer.should have_tag('input[@max="2"]')
720
690
  end
721
691
  end
722
-
692
+
723
693
  describe "when validations require only an integer (:only_integer)" do
724
-
694
+
725
695
  before do
726
696
  @new_post.class.stub!(:validators_on).with(:title).and_return([
727
697
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
728
698
  ])
729
699
  end
730
-
700
+
731
701
  it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
732
702
  concat(semantic_form_for(@new_post) do |builder|
733
703
  builder.input(:title, :as => :number)
734
704
  end)
735
705
  output_buffer.should have_tag('input[@step="1"]')
736
706
  end
737
-
707
+
738
708
  it "should let input_html override :step" do
739
709
  concat(semantic_form_for(@new_post) do |builder|
740
710
  builder.input(:title, :as => :number, :input_html => { :step => 3 })
741
711
  end)
742
712
  output_buffer.should have_tag('input[@step="3"]')
743
713
  end
744
-
714
+
745
715
  it "should let options override :step" do
746
716
  concat(semantic_form_for(@new_post) do |builder|
747
717
  builder.input(:title, :as => :number, :step => 3)
748
718
  end)
749
719
  output_buffer.should have_tag('input[@step="3"]')
750
720
  end
751
-
721
+
752
722
  end
753
-
723
+
754
724
  describe "when validations require a :step (non standard)" do
755
-
725
+
756
726
  before do
757
727
  @new_post.class.stub!(:validators_on).with(:title).and_return([
758
728
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
759
729
  ])
760
730
  end
761
-
731
+
762
732
  it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
763
733
  concat(semantic_form_for(@new_post) do |builder|
764
734
  builder.input(:title, :as => :number)
765
735
  end)
766
736
  output_buffer.should have_tag('input[@step="2"]')
767
737
  end
768
-
738
+
769
739
  it "should let input_html override :step" do
770
740
  concat(semantic_form_for(@new_post) do |builder|
771
741
  builder.input(:title, :as => :number, :input_html => { :step => 3 })
772
742
  end)
773
743
  output_buffer.should have_tag('input[@step="3"]')
774
744
  end
775
-
745
+
776
746
  it "should let options override :step" do
777
747
  concat(semantic_form_for(@new_post) do |builder|
778
748
  builder.input(:title, :as => :number, :step => 3)
779
749
  end)
780
750
  output_buffer.should have_tag('input[@step="3"]')
781
751
  end
782
-
752
+
783
753
  end
784
-
754
+
785
755
  describe "when validations do not specify :step (non standard) or :only_integer" do
786
-
756
+
787
757
  before do
788
758
  @new_post.class.stub!(:validators_on).with(:title).and_return([
789
759
  active_model_numericality_validator([:title], {:allow_nil=>false})
790
760
  ])
791
761
  end
792
-
762
+
793
763
  it "should default step to 'any'" do
794
764
  concat(semantic_form_for(@new_post) do |builder|
795
765
  builder.input(:title, :as => :number)
796
766
  end)
797
767
  output_buffer.should have_tag('input[@step="any"]')
798
768
  end
799
-
769
+
800
770
  it "should let input_html set :step" do
801
771
  concat(semantic_form_for(@new_post) do |builder|
802
772
  builder.input(:title, :as => :number, :input_html => { :step => 3 })
803
773
  end)
804
774
  output_buffer.should have_tag('input[@step="3"]')
805
775
  end
806
-
776
+
807
777
  it "should let options set :step" do
808
778
  concat(semantic_form_for(@new_post) do |builder|
809
779
  builder.input(:title, :as => :number, :step => 3)
810
780
  end)
811
781
  output_buffer.should have_tag('input[@step="3"]')
812
782
  end
813
-
783
+
814
784
  end
815
-
785
+
816
786
  end
817
787