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