formtastic 1.2.5 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/.gitignore +13 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG +279 -0
  5. data/Gemfile +3 -0
  6. data/README.textile +155 -172
  7. data/RELEASE_PROCESS +7 -0
  8. data/Rakefile +52 -0
  9. data/app/assets/stylesheets/formtastic.css +275 -0
  10. data/app/assets/stylesheets/formtastic_ie6.css +27 -0
  11. data/app/assets/stylesheets/formtastic_ie7.css +17 -0
  12. data/formtastic.gemspec +51 -0
  13. data/lib/formtastic.rb +21 -1960
  14. data/lib/formtastic/engine.rb +7 -0
  15. data/lib/formtastic/form_builder.rb +83 -0
  16. data/lib/formtastic/helpers.rb +16 -0
  17. data/lib/formtastic/helpers/buttons_helper.rb +277 -0
  18. data/lib/formtastic/helpers/errors_helper.rb +113 -0
  19. data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
  20. data/lib/formtastic/helpers/file_column_detection.rb +16 -0
  21. data/lib/formtastic/helpers/form_helper.rb +198 -0
  22. data/lib/formtastic/helpers/input_helper.rb +366 -0
  23. data/lib/formtastic/helpers/inputs_helper.rb +392 -0
  24. data/lib/formtastic/helpers/reflection.rb +33 -0
  25. data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
  26. data/lib/formtastic/html_attributes.rb +21 -0
  27. data/lib/formtastic/i18n.rb +1 -0
  28. data/lib/formtastic/inputs.rb +31 -0
  29. data/lib/formtastic/inputs/base.rb +61 -0
  30. data/lib/formtastic/inputs/base/associations.rb +31 -0
  31. data/lib/formtastic/inputs/base/choices.rb +103 -0
  32. data/lib/formtastic/inputs/base/collections.rb +94 -0
  33. data/lib/formtastic/inputs/base/database.rb +17 -0
  34. data/lib/formtastic/inputs/base/errors.rb +58 -0
  35. data/lib/formtastic/inputs/base/fileish.rb +23 -0
  36. data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
  37. data/lib/formtastic/inputs/base/hints.rb +31 -0
  38. data/lib/formtastic/inputs/base/html.rb +52 -0
  39. data/lib/formtastic/inputs/base/labelling.rb +55 -0
  40. data/lib/formtastic/inputs/base/naming.rb +42 -0
  41. data/lib/formtastic/inputs/base/options.rb +18 -0
  42. data/lib/formtastic/inputs/base/stringish.rb +35 -0
  43. data/lib/formtastic/inputs/base/timeish.rb +128 -0
  44. data/lib/formtastic/inputs/base/validations.rb +166 -0
  45. data/lib/formtastic/inputs/base/wrapping.rb +40 -0
  46. data/lib/formtastic/inputs/boolean_input.rb +96 -0
  47. data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
  48. data/lib/formtastic/inputs/country_input.rb +66 -0
  49. data/lib/formtastic/inputs/date_input.rb +14 -0
  50. data/lib/formtastic/inputs/datetime_input.rb +9 -0
  51. data/lib/formtastic/inputs/email_input.rb +40 -0
  52. data/lib/formtastic/inputs/file_input.rb +42 -0
  53. data/lib/formtastic/inputs/hidden_input.rb +66 -0
  54. data/lib/formtastic/inputs/number_input.rb +118 -0
  55. data/lib/formtastic/inputs/numeric_input.rb +21 -0
  56. data/lib/formtastic/inputs/password_input.rb +40 -0
  57. data/lib/formtastic/inputs/phone_input.rb +41 -0
  58. data/lib/formtastic/inputs/radio_input.rb +157 -0
  59. data/lib/formtastic/inputs/range_input.rb +119 -0
  60. data/lib/formtastic/inputs/search_input.rb +40 -0
  61. data/lib/formtastic/inputs/select_input.rb +210 -0
  62. data/lib/formtastic/inputs/string_input.rb +34 -0
  63. data/lib/formtastic/inputs/text_input.rb +47 -0
  64. data/lib/formtastic/inputs/time_input.rb +14 -0
  65. data/lib/formtastic/inputs/time_zone_input.rb +48 -0
  66. data/lib/formtastic/inputs/url_input.rb +40 -0
  67. data/lib/formtastic/localized_string.rb +105 -0
  68. data/lib/formtastic/railtie.rb +5 -7
  69. data/lib/formtastic/semantic_form_builder.rb +11 -0
  70. data/lib/formtastic/util.rb +6 -19
  71. data/lib/formtastic/version.rb +3 -0
  72. data/lib/generators/formtastic/install/install_generator.rb +28 -6
  73. data/lib/generators/templates/_form.html.erb +10 -4
  74. data/lib/generators/templates/_form.html.haml +8 -4
  75. data/lib/generators/templates/formtastic.rb +25 -32
  76. data/lib/locale/en.yml +1 -0
  77. data/lib/tasks/verify_rcov.rb +44 -0
  78. data/sample/basic_inputs.html +182 -0
  79. data/sample/config.ru +69 -0
  80. data/sample/index.html +14 -0
  81. data/spec/builder/custom_builder_spec.rb +109 -0
  82. data/spec/builder/error_proc_spec.rb +27 -0
  83. data/spec/builder/errors_spec.rb +193 -0
  84. data/spec/builder/semantic_fields_for_spec.rb +88 -0
  85. data/spec/helpers/buttons_helper_spec.rb +150 -0
  86. data/spec/helpers/commit_button_helper_spec.rb +470 -0
  87. data/spec/helpers/form_helper_spec.rb +135 -0
  88. data/spec/helpers/input_helper_spec.rb +837 -0
  89. data/spec/helpers/inputs_helper_spec.rb +562 -0
  90. data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
  91. data/spec/i18n_spec.rb +199 -0
  92. data/spec/inputs/boolean_input_spec.rb +184 -0
  93. data/spec/inputs/check_boxes_input_spec.rb +375 -0
  94. data/spec/inputs/country_input_spec.rb +133 -0
  95. data/spec/inputs/custom_input_spec.rb +52 -0
  96. data/spec/inputs/date_input_spec.rb +110 -0
  97. data/spec/inputs/datetime_input_spec.rb +115 -0
  98. data/spec/inputs/email_input_spec.rb +55 -0
  99. data/spec/inputs/file_input_spec.rb +59 -0
  100. data/spec/inputs/hidden_input_spec.rb +120 -0
  101. data/spec/inputs/include_blank_spec.rb +70 -0
  102. data/spec/inputs/label_spec.rb +104 -0
  103. data/spec/inputs/number_input_spec.rb +487 -0
  104. data/spec/inputs/numeric_input_spec.rb +41 -0
  105. data/spec/inputs/password_input_spec.rb +69 -0
  106. data/spec/inputs/phone_input_spec.rb +55 -0
  107. data/spec/inputs/placeholder_spec.rb +71 -0
  108. data/spec/inputs/radio_input_spec.rb +234 -0
  109. data/spec/inputs/range_input_spec.rb +477 -0
  110. data/spec/inputs/search_input_spec.rb +55 -0
  111. data/spec/inputs/select_input_spec.rb +545 -0
  112. data/spec/inputs/string_input_spec.rb +163 -0
  113. data/spec/inputs/text_input_spec.rb +158 -0
  114. data/spec/inputs/time_input_spec.rb +155 -0
  115. data/spec/inputs/time_zone_input_spec.rb +87 -0
  116. data/spec/inputs/url_input_spec.rb +55 -0
  117. data/spec/spec.opts +2 -0
  118. data/spec/spec_helper.rb +361 -0
  119. data/spec/support/custom_macros.rb +656 -0
  120. data/spec/support/deferred_garbage_collection.rb +21 -0
  121. data/spec/support/deprecation.rb +6 -0
  122. data/spec/support/test_environment.rb +30 -0
  123. metadata +306 -88
  124. data/generators/form/USAGE +0 -16
  125. data/generators/form/form_generator.rb +0 -111
  126. data/generators/formtastic/formtastic_generator.rb +0 -26
  127. data/init.rb +0 -5
  128. data/lib/formtastic/layout_helper.rb +0 -12
  129. data/lib/generators/formtastic/form/form_generator.rb +0 -84
  130. data/lib/generators/templates/formtastic.css +0 -145
  131. data/lib/generators/templates/formtastic_changes.css +0 -14
  132. data/lib/generators/templates/rails2/_form.html.erb +0 -5
  133. data/lib/generators/templates/rails2/_form.html.haml +0 -4
  134. data/rails/init.rb +0 -2
@@ -0,0 +1,477 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'active_record'
4
+
5
+ describe 'range input' do
6
+
7
+ include FormtasticSpecHelper
8
+
9
+ before do
10
+ @output_buffer = ''
11
+ mock_everything
12
+ end
13
+
14
+ describe "when object is provided" do
15
+ before do
16
+ concat(semantic_form_for(@bob) do |builder|
17
+ concat(builder.input(:age, :as => :range))
18
+ end)
19
+ end
20
+
21
+ it_should_have_input_wrapper_with_class(:range)
22
+ it_should_have_input_wrapper_with_class(:input)
23
+ it_should_have_input_wrapper_with_class(:stringish) # might be removed
24
+ it_should_have_input_wrapper_with_id("author_age_input")
25
+ it_should_have_label_with_text(/Age/)
26
+ it_should_have_label_for("author_age")
27
+ it_should_have_input_with_id("author_age")
28
+ it_should_have_input_with_type(:range)
29
+ it_should_have_input_with_name("author[age]")
30
+
31
+ end
32
+
33
+ describe "when namespace is provided" do
34
+
35
+ before do
36
+ concat(semantic_form_for(@james, :namespace => "context2") do |builder|
37
+ concat(builder.input(:age, :as => :range))
38
+ end)
39
+ end
40
+
41
+ it_should_have_input_wrapper_with_id("context2_author_age_input")
42
+ it_should_have_label_and_input_with_id("context2_author_age")
43
+
44
+ end
45
+
46
+ describe "when validations require a minimum value (:greater_than)" do
47
+ before do
48
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
49
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
50
+ ])
51
+ end
52
+
53
+ it "should allow :input_html to override :min" do
54
+ concat(semantic_form_for(@new_post) do |builder|
55
+ builder.input(:title, :as => :range, :input_html => { :min => 5 })
56
+ end)
57
+ output_buffer.should have_tag('input[@min="5"]')
58
+ end
59
+
60
+ it "should allow :input_html to override :min through :in" do
61
+ concat(semantic_form_for(@new_post) do |builder|
62
+ builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
63
+ end)
64
+ output_buffer.should have_tag('input[@min="5"]')
65
+ end
66
+
67
+ it "should allow options to override :min" do
68
+ concat(semantic_form_for(@new_post) do |builder|
69
+ builder.input(:title, :as => :range, :min => 5)
70
+ end)
71
+ output_buffer.should have_tag('input[@min="5"]')
72
+ end
73
+
74
+ it "should allow options to override :min through :in" do
75
+ concat(semantic_form_for(@new_post) do |builder|
76
+ builder.input(:title, :as => :range, :in => 5..102)
77
+ end)
78
+ output_buffer.should have_tag('input[@min="5"]')
79
+ end
80
+
81
+ describe "and the column is an integer" do
82
+ before do
83
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
84
+ end
85
+
86
+ it "should add a min attribute to the input one greater than the validation" do
87
+ concat(semantic_form_for(@new_post) do |builder|
88
+ builder.input(:title, :as => :range)
89
+ end)
90
+ output_buffer.should have_tag('input[@min="3"]')
91
+ end
92
+ end
93
+
94
+ describe "and the column is a float" do
95
+ before do
96
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
97
+ end
98
+
99
+ it "should raise an error" do
100
+ lambda {
101
+ concat(semantic_form_for(@new_post) do |builder|
102
+ builder.input(:title, :as => :range)
103
+ end)
104
+ }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
105
+ end
106
+ end
107
+
108
+ describe "and the column is a big decimal" do
109
+ before do
110
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
111
+ end
112
+
113
+ it "should raise an error" do
114
+ lambda {
115
+ concat(semantic_form_for(@new_post) do |builder|
116
+ builder.input(:title, :as => :range)
117
+ end)
118
+ }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
119
+ end
120
+ end
121
+
122
+ end
123
+
124
+ describe "when validations require a minimum value (:greater_than_or_equal_to)" do
125
+ before do
126
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
127
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
128
+ ])
129
+ end
130
+
131
+ it "should allow :input_html to override :min" do
132
+ concat(semantic_form_for(@new_post) do |builder|
133
+ builder.input(:title, :as => :range, :input_html => { :min => 5 })
134
+ end)
135
+ output_buffer.should have_tag('input[@min="5"]')
136
+ end
137
+
138
+ it "should allow options to override :min" do
139
+ concat(semantic_form_for(@new_post) do |builder|
140
+ builder.input(:title, :as => :range, :min => 5)
141
+ end)
142
+ output_buffer.should have_tag('input[@min="5"]')
143
+ end
144
+
145
+ it "should allow :input_html to override :min with :in" do
146
+ concat(semantic_form_for(@new_post) do |builder|
147
+ builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
148
+ end)
149
+ output_buffer.should have_tag('input[@min="5"]')
150
+ end
151
+
152
+ it "should allow options to override :min with :in" do
153
+ concat(semantic_form_for(@new_post) do |builder|
154
+ builder.input(:title, :as => :range, :in => 5..102)
155
+ end)
156
+ output_buffer.should have_tag('input[@min="5"]')
157
+ end
158
+
159
+
160
+ [:integer, :decimal, :float].each do |column_type|
161
+ describe "and the column is a #{column_type}" do
162
+ before do
163
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => column_type))
164
+ end
165
+
166
+ it "should add a max attribute to the input equal to the validation" do
167
+ concat(semantic_form_for(@new_post) do |builder|
168
+ builder.input(:title, :as => :range)
169
+ end)
170
+ output_buffer.should have_tag('input[@min="2"]')
171
+ end
172
+ end
173
+ end
174
+
175
+ describe "and there is no column" do
176
+ before do
177
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
178
+ end
179
+
180
+ it "should add a max attribute to the input equal to the validation" do
181
+ concat(semantic_form_for(@new_post) do |builder|
182
+ builder.input(:title, :as => :range)
183
+ end)
184
+ output_buffer.should have_tag('input[@min="2"]')
185
+ end
186
+ end
187
+ end
188
+
189
+ describe "when validations do not require a minimum value" do
190
+
191
+ it "should default to 1" do
192
+ concat(semantic_form_for(@new_post) do |builder|
193
+ builder.input(:title, :as => :range)
194
+ end)
195
+ output_buffer.should have_tag('input[@min="1"]')
196
+ end
197
+
198
+ end
199
+
200
+ describe "when validations require a maximum value (:less_than)" do
201
+ before do
202
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
203
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
204
+ ])
205
+ end
206
+
207
+ it "should allow :input_html to override :max" do
208
+ concat(semantic_form_for(@new_post) do |builder|
209
+ builder.input(:title, :as => :range, :input_html => { :max => 102 })
210
+ end)
211
+ output_buffer.should have_tag('input[@max="102"]')
212
+ end
213
+
214
+ it "should allow option to override :max" do
215
+ concat(semantic_form_for(@new_post) do |builder|
216
+ builder.input(:title, :as => :range, :max => 102)
217
+ end)
218
+ output_buffer.should have_tag('input[@max="102"]')
219
+ end
220
+
221
+ it "should allow :input_html to override :max with :in" do
222
+ concat(semantic_form_for(@new_post) do |builder|
223
+ builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
224
+ end)
225
+ output_buffer.should have_tag('input[@max="102"]')
226
+ end
227
+
228
+ it "should allow option to override :max with :in" do
229
+ concat(semantic_form_for(@new_post) do |builder|
230
+ builder.input(:title, :as => :range, :in => 1..102)
231
+ end)
232
+ output_buffer.should have_tag('input[@max="102"]')
233
+ end
234
+
235
+ describe "and the column is an integer" do
236
+ before do
237
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
238
+ end
239
+
240
+ it "should add a max attribute to the input one greater than the validation" do
241
+ concat(semantic_form_for(@new_post) do |builder|
242
+ builder.input(:title, :as => :range)
243
+ end)
244
+ output_buffer.should have_tag('input[@max="19"]')
245
+ end
246
+ end
247
+
248
+ describe "and the column is a float" do
249
+ before do
250
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
251
+ end
252
+
253
+ it "should raise an error" do
254
+ lambda {
255
+ concat(semantic_form_for(@new_post) do |builder|
256
+ builder.input(:title, :as => :range)
257
+ end)
258
+ }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
259
+ end
260
+ end
261
+
262
+ describe "and the column is a big decimal" do
263
+ before do
264
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
265
+ end
266
+
267
+ it "should raise an error" do
268
+ lambda {
269
+ concat(semantic_form_for(@new_post) do |builder|
270
+ builder.input(:title, :as => :range)
271
+ end)
272
+ }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
273
+ end
274
+ end
275
+
276
+ end
277
+
278
+ describe "when validations require a maximum value (:less_than_or_equal_to)" do
279
+ before do
280
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
281
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
282
+ ])
283
+ end
284
+
285
+ it "should allow :input_html to override :max" do
286
+ concat(semantic_form_for(@new_post) do |builder|
287
+ builder.input(:title, :as => :range, :input_html => { :max => 102 })
288
+ end)
289
+ output_buffer.should have_tag('input[@max="102"]')
290
+ end
291
+
292
+ it "should allow options to override :max" do
293
+ concat(semantic_form_for(@new_post) do |builder|
294
+ builder.input(:title, :as => :range, :max => 102)
295
+ end)
296
+ output_buffer.should have_tag('input[@max="102"]')
297
+ end
298
+
299
+ it "should allow :input_html to override :max with :in" do
300
+ concat(semantic_form_for(@new_post) do |builder|
301
+ builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
302
+ end)
303
+ output_buffer.should have_tag('input[@max="102"]')
304
+ end
305
+
306
+ it "should allow options to override :max with :in" do
307
+ concat(semantic_form_for(@new_post) do |builder|
308
+ builder.input(:title, :as => :range, :in => 1..102)
309
+ end)
310
+ output_buffer.should have_tag('input[@max="102"]')
311
+ end
312
+
313
+ [:integer, :decimal, :float].each do |column_type|
314
+ describe "and the column is a #{column_type}" do
315
+ before do
316
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => column_type))
317
+ end
318
+
319
+ it "should add a max attribute to the input equal to the validation" do
320
+ concat(semantic_form_for(@new_post) do |builder|
321
+ builder.input(:title, :as => :range)
322
+ end)
323
+ output_buffer.should have_tag('input[@max="20"]')
324
+ end
325
+ end
326
+ end
327
+
328
+ describe "and there is no column" do
329
+ before do
330
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
331
+ end
332
+
333
+ it "should add a max attribute to the input equal to the validation" do
334
+ concat(semantic_form_for(@new_post) do |builder|
335
+ builder.input(:title, :as => :range)
336
+ end)
337
+ output_buffer.should have_tag('input[@max="20"]')
338
+ end
339
+ end
340
+ end
341
+
342
+ describe "when validations do not require a maximum value" do
343
+
344
+ it "should default to 1" do
345
+ concat(semantic_form_for(@new_post) do |builder|
346
+ builder.input(:title, :as => :range)
347
+ end)
348
+ output_buffer.should have_tag('input[@max="100"]')
349
+ end
350
+
351
+ end
352
+
353
+ describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
354
+ before do
355
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
356
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
357
+ ])
358
+ end
359
+
360
+ it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
361
+ concat(semantic_form_for(@new_post) do |builder|
362
+ builder.input(:title, :as => :range)
363
+ end)
364
+ output_buffer.should have_tag('input[@min="2"]')
365
+ end
366
+ end
367
+
368
+ describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
369
+ before do
370
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
371
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
372
+ ])
373
+ end
374
+
375
+ it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
376
+ concat(semantic_form_for(@new_post) do |builder|
377
+ builder.input(:title, :as => :range)
378
+ end)
379
+ output_buffer.should have_tag('input[@max="2"]')
380
+ end
381
+ end
382
+
383
+ describe "when validations require only an integer (:only_integer)" do
384
+
385
+ before do
386
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
387
+ active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
388
+ ])
389
+ end
390
+
391
+ it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
392
+ concat(semantic_form_for(@new_post) do |builder|
393
+ builder.input(:title, :as => :range)
394
+ end)
395
+ output_buffer.should have_tag('input[@step="1"]')
396
+ end
397
+
398
+ it "should let input_html override :step" do
399
+ concat(semantic_form_for(@new_post) do |builder|
400
+ builder.input(:title, :as => :range, :input_html => { :step => 3 })
401
+ end)
402
+ output_buffer.should have_tag('input[@step="3"]')
403
+ end
404
+
405
+ it "should let options override :step" do
406
+ concat(semantic_form_for(@new_post) do |builder|
407
+ builder.input(:title, :as => :range, :step => 3)
408
+ end)
409
+ output_buffer.should have_tag('input[@step="3"]')
410
+ end
411
+
412
+ end
413
+
414
+ describe "when validations require a :step (non standard)" do
415
+
416
+ before do
417
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
418
+ active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
419
+ ])
420
+ end
421
+
422
+ it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
423
+ concat(semantic_form_for(@new_post) do |builder|
424
+ builder.input(:title, :as => :range)
425
+ end)
426
+ output_buffer.should have_tag('input[@step="2"]')
427
+ end
428
+
429
+ it "should let input_html override :step" do
430
+ concat(semantic_form_for(@new_post) do |builder|
431
+ builder.input(:title, :as => :range, :input_html => { :step => 3 })
432
+ end)
433
+ output_buffer.should have_tag('input[@step="3"]')
434
+ end
435
+
436
+ it "should let options override :step" do
437
+ concat(semantic_form_for(@new_post) do |builder|
438
+ builder.input(:title, :as => :range, :step => 3)
439
+ end)
440
+ output_buffer.should have_tag('input[@step="3"]')
441
+ end
442
+
443
+ end
444
+
445
+ describe "when validations do not specify :step (non standard) or :only_integer" do
446
+
447
+ before do
448
+ @new_post.class.stub!(:validators_on).with(:title).and_return([
449
+ active_model_numericality_validator([:title], {:allow_nil=>false})
450
+ ])
451
+ end
452
+
453
+ it "should default step to 1" do
454
+ concat(semantic_form_for(@new_post) do |builder|
455
+ builder.input(:title, :as => :range)
456
+ end)
457
+ output_buffer.should have_tag('input[@step="1"]')
458
+ end
459
+
460
+ it "should let input_html set :step" do
461
+ concat(semantic_form_for(@new_post) do |builder|
462
+ builder.input(:title, :as => :range, :input_html => { :step => 3 })
463
+ end)
464
+ output_buffer.should have_tag('input[@step="3"]')
465
+ end
466
+
467
+ it "should let options set :step" do
468
+ concat(semantic_form_for(@new_post) do |builder|
469
+ builder.input(:title, :as => :range, :step => 3)
470
+ end)
471
+ output_buffer.should have_tag('input[@step="3"]')
472
+ end
473
+
474
+ end
475
+
476
+ end
477
+