formtastic-bootstrap 2.0.0 → 2.1.0

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