speedo-formstrap 1.2.2 → 1.2.3

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