formtastic 3.1.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +3 -2
  5. data/CHANGELOG.md +61 -0
  6. data/Gemfile.lock +140 -0
  7. data/MIT-LICENSE +1 -1
  8. data/{README.textile → README.md} +183 -167
  9. data/RELEASE_PROCESS +3 -1
  10. data/Rakefile +20 -1
  11. data/app/assets/stylesheets/formtastic.css +1 -1
  12. data/bin/appraisal +8 -0
  13. data/formtastic.gemspec +12 -16
  14. data/gemfiles/rails_6.0/Gemfile +5 -0
  15. data/gemfiles/rails_6.1/Gemfile +5 -0
  16. data/gemfiles/rails_7.0/Gemfile +5 -0
  17. data/gemfiles/rails_7.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +1 -0
  20. data/lib/formtastic/actions/base.rb +1 -0
  21. data/lib/formtastic/actions/button_action.rb +1 -0
  22. data/lib/formtastic/actions/buttonish.rb +1 -0
  23. data/lib/formtastic/actions/input_action.rb +1 -0
  24. data/lib/formtastic/actions/link_action.rb +1 -0
  25. data/lib/formtastic/actions.rb +7 -3
  26. data/lib/formtastic/deprecation.rb +2 -38
  27. data/lib/formtastic/engine.rb +4 -1
  28. data/lib/formtastic/form_builder.rb +12 -24
  29. data/lib/formtastic/helpers/action_helper.rb +2 -48
  30. data/lib/formtastic/helpers/actions_helper.rb +1 -0
  31. data/lib/formtastic/helpers/enum.rb +14 -0
  32. data/lib/formtastic/helpers/errors_helper.rb +3 -2
  33. data/lib/formtastic/helpers/fieldset_wrapper.rb +14 -9
  34. data/lib/formtastic/helpers/file_column_detection.rb +1 -0
  35. data/lib/formtastic/helpers/form_helper.rb +2 -1
  36. data/lib/formtastic/helpers/input_helper.rb +20 -76
  37. data/lib/formtastic/helpers/inputs_helper.rb +29 -23
  38. data/lib/formtastic/helpers/reflection.rb +1 -0
  39. data/lib/formtastic/helpers.rb +2 -2
  40. data/lib/formtastic/html_attributes.rb +1 -0
  41. data/lib/formtastic/i18n.rb +2 -1
  42. data/lib/formtastic/input_class_finder.rb +1 -0
  43. data/lib/formtastic/inputs/base/associations.rb +1 -0
  44. data/lib/formtastic/inputs/base/choices.rb +3 -2
  45. data/lib/formtastic/inputs/base/collections.rb +46 -10
  46. data/lib/formtastic/inputs/base/database.rb +5 -7
  47. data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
  48. data/lib/formtastic/inputs/base/errors.rb +7 -6
  49. data/lib/formtastic/inputs/base/fileish.rb +1 -0
  50. data/lib/formtastic/inputs/base/hints.rb +2 -1
  51. data/lib/formtastic/inputs/base/html.rb +9 -7
  52. data/lib/formtastic/inputs/base/labelling.rb +3 -2
  53. data/lib/formtastic/inputs/base/naming.rb +5 -4
  54. data/lib/formtastic/inputs/base/numeric.rb +1 -0
  55. data/lib/formtastic/inputs/base/options.rb +3 -3
  56. data/lib/formtastic/inputs/base/placeholder.rb +1 -0
  57. data/lib/formtastic/inputs/base/stringish.rb +1 -0
  58. data/lib/formtastic/inputs/base/timeish.rb +9 -4
  59. data/lib/formtastic/inputs/base/validations.rb +39 -12
  60. data/lib/formtastic/inputs/base/wrapping.rb +1 -0
  61. data/lib/formtastic/inputs/base.rb +3 -2
  62. data/lib/formtastic/inputs/boolean_input.rb +2 -1
  63. data/lib/formtastic/inputs/check_boxes_input.rb +15 -6
  64. data/lib/formtastic/inputs/color_input.rb +1 -1
  65. data/lib/formtastic/inputs/country_input.rb +4 -1
  66. data/lib/formtastic/inputs/datalist_input.rb +1 -0
  67. data/lib/formtastic/inputs/date_picker_input.rb +1 -0
  68. data/lib/formtastic/inputs/date_select_input.rb +1 -0
  69. data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
  70. data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
  71. data/lib/formtastic/inputs/email_input.rb +1 -0
  72. data/lib/formtastic/inputs/file_input.rb +1 -0
  73. data/lib/formtastic/inputs/hidden_input.rb +3 -2
  74. data/lib/formtastic/inputs/number_input.rb +1 -0
  75. data/lib/formtastic/inputs/password_input.rb +1 -0
  76. data/lib/formtastic/inputs/phone_input.rb +1 -0
  77. data/lib/formtastic/inputs/radio_input.rb +21 -0
  78. data/lib/formtastic/inputs/range_input.rb +1 -0
  79. data/lib/formtastic/inputs/search_input.rb +1 -0
  80. data/lib/formtastic/inputs/select_input.rb +30 -1
  81. data/lib/formtastic/inputs/string_input.rb +1 -0
  82. data/lib/formtastic/inputs/text_input.rb +1 -0
  83. data/lib/formtastic/inputs/time_picker_input.rb +1 -0
  84. data/lib/formtastic/inputs/time_select_input.rb +1 -0
  85. data/lib/formtastic/inputs/time_zone_input.rb +17 -6
  86. data/lib/formtastic/inputs/url_input.rb +1 -0
  87. data/lib/formtastic/inputs.rb +33 -29
  88. data/lib/formtastic/localized_string.rb +1 -0
  89. data/lib/formtastic/localizer.rb +21 -22
  90. data/lib/formtastic/namespaced_class_finder.rb +8 -9
  91. data/lib/formtastic/version.rb +2 -1
  92. data/lib/formtastic.rb +10 -11
  93. data/lib/generators/formtastic/form/form_generator.rb +2 -1
  94. data/lib/generators/formtastic/input/input_generator.rb +47 -0
  95. data/lib/generators/formtastic/install/install_generator.rb +1 -0
  96. data/lib/generators/templates/formtastic.rb +15 -13
  97. data/lib/generators/templates/input.rb +19 -0
  98. data/sample/basic_inputs.html +1 -1
  99. data/script/integration-template.rb +73 -0
  100. data/script/integration.sh +19 -0
  101. data/spec/action_class_finder_spec.rb +2 -1
  102. data/spec/actions/button_action_spec.rb +21 -20
  103. data/spec/actions/generic_action_spec.rb +134 -133
  104. data/spec/actions/input_action_spec.rb +20 -19
  105. data/spec/actions/link_action_spec.rb +30 -29
  106. data/spec/builder/custom_builder_spec.rb +39 -22
  107. data/spec/builder/error_proc_spec.rb +6 -5
  108. data/spec/builder/semantic_fields_for_spec.rb +46 -45
  109. data/spec/fast_spec_helper.rb +13 -0
  110. data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
  111. data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  112. data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
  113. data/spec/helpers/action_helper_spec.rb +329 -10
  114. data/spec/helpers/actions_helper_spec.rb +43 -42
  115. data/spec/helpers/form_helper_spec.rb +45 -38
  116. data/spec/helpers/input_helper_spec.rb +976 -2
  117. data/spec/helpers/inputs_helper_spec.rb +217 -202
  118. data/spec/helpers/reflection_helper_spec.rb +7 -6
  119. data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
  120. data/spec/i18n_spec.rb +30 -29
  121. data/spec/input_class_finder_spec.rb +2 -1
  122. data/spec/inputs/base/collections_spec.rb +78 -0
  123. data/spec/inputs/base/validations_spec.rb +481 -0
  124. data/spec/inputs/boolean_input_spec.rb +73 -72
  125. data/spec/inputs/check_boxes_input_spec.rb +169 -121
  126. data/spec/inputs/color_input_spec.rb +53 -64
  127. data/spec/inputs/country_input_spec.rb +23 -22
  128. data/spec/inputs/custom_input_spec.rb +3 -6
  129. data/spec/inputs/datalist_input_spec.rb +3 -2
  130. data/spec/inputs/date_picker_input_spec.rb +114 -113
  131. data/spec/inputs/date_select_input_spec.rb +76 -61
  132. data/spec/inputs/datetime_picker_input_spec.rb +123 -122
  133. data/spec/inputs/datetime_select_input_spec.rb +85 -68
  134. data/spec/inputs/email_input_spec.rb +17 -16
  135. data/spec/inputs/file_input_spec.rb +18 -17
  136. data/spec/inputs/hidden_input_spec.rb +32 -31
  137. data/spec/inputs/include_blank_spec.rb +10 -9
  138. data/spec/inputs/label_spec.rb +26 -25
  139. data/spec/inputs/number_input_spec.rb +212 -211
  140. data/spec/inputs/password_input_spec.rb +17 -16
  141. data/spec/inputs/phone_input_spec.rb +17 -16
  142. data/spec/inputs/placeholder_spec.rb +18 -17
  143. data/spec/inputs/radio_input_spec.rb +92 -65
  144. data/spec/inputs/range_input_spec.rb +136 -135
  145. data/spec/inputs/readonly_spec.rb +51 -0
  146. data/spec/inputs/search_input_spec.rb +16 -15
  147. data/spec/inputs/select_input_spec.rb +209 -102
  148. data/spec/inputs/string_input_spec.rb +51 -50
  149. data/spec/inputs/text_input_spec.rb +34 -33
  150. data/spec/inputs/time_picker_input_spec.rb +115 -114
  151. data/spec/inputs/time_select_input_spec.rb +84 -70
  152. data/spec/inputs/time_zone_input_spec.rb +58 -31
  153. data/spec/inputs/url_input_spec.rb +17 -16
  154. data/spec/inputs/with_options_spec.rb +9 -8
  155. data/spec/localizer_spec.rb +18 -17
  156. data/spec/namespaced_class_finder_spec.rb +18 -6
  157. data/spec/schema.rb +22 -0
  158. data/spec/spec_helper.rb +172 -260
  159. data/spec/support/custom_macros.rb +74 -76
  160. data/spec/support/deprecation.rb +2 -1
  161. data/spec/support/shared_examples.rb +2 -1233
  162. data/spec/support/specialized_class_finder_shared_example.rb +1 -0
  163. data/spec/support/test_environment.rb +24 -9
  164. metadata +78 -170
  165. data/.travis.yml +0 -29
  166. data/Appraisals +0 -29
  167. data/CHANGELOG +0 -39
  168. data/DEPRECATIONS +0 -49
  169. data/gemfiles/rails_3.2.gemfile +0 -7
  170. data/gemfiles/rails_4.0.4.gemfile +0 -7
  171. data/gemfiles/rails_4.1.gemfile +0 -7
  172. data/gemfiles/rails_4.2.gemfile +0 -7
  173. data/gemfiles/rails_4.gemfile +0 -7
  174. data/gemfiles/rails_edge.gemfile +0 -10
  175. data/lib/formtastic/util.rb +0 -57
  176. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  177. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  178. data/spec/support/deferred_garbage_collection.rb +0 -21
  179. data/spec/util_spec.rb +0 -66
@@ -0,0 +1,481 @@
1
+ # frozen_string_literal: true
2
+ require 'fast_spec_helper'
3
+ require 'active_model'
4
+ require 'inputs/base/validations'
5
+
6
+ class MyInput
7
+ attr_accessor :validations
8
+ include Formtastic::Inputs::Base::Validations
9
+
10
+ def validations?
11
+ true
12
+ end
13
+ end
14
+
15
+ RSpec.describe MyInput do
16
+ let(:builder) { double }
17
+ let(:template) { double }
18
+ let(:model_class) { double }
19
+ let(:model) { double(:class => model_class) }
20
+ let(:model_name) { "post" }
21
+ let(:method) { double }
22
+ let(:options) { Hash.new }
23
+ let(:validator) { double }
24
+ let(:instance) do
25
+ MyInput.new(builder, template, model, model_name, method, options).tap do |my_input|
26
+ my_input.validations = validations
27
+ end
28
+ end
29
+
30
+ describe '#required?' do
31
+ context 'with a single validator' do
32
+ let(:validations) { [validator] }
33
+
34
+ context 'with options[:required] being true' do
35
+ let(:options) { {required: true} }
36
+
37
+ it 'is required' do
38
+ expect(instance.required?).to be_truthy
39
+ end
40
+ end
41
+
42
+ context 'with options[:required] being false' do
43
+ let(:options) { {required: false} }
44
+
45
+ it 'is not required' do
46
+ expect(instance.required?).to be_falsey
47
+ end
48
+ end
49
+
50
+ context 'with negated validation' do
51
+ it 'is not required' do
52
+ instance.not_required_through_negated_validation!
53
+ expect(instance.required?).to be_falsey
54
+ end
55
+ end
56
+
57
+ context 'with presence validator' do
58
+ let (:validator) { double(options: {}, kind: :presence) }
59
+
60
+ it 'is required' do
61
+ expect(instance.required?).to be_truthy
62
+ end
63
+
64
+ context 'with options[:on] as symbol' do
65
+ context 'with save context' do
66
+ let (:validator) { double(options: {on: :save}, kind: :presence) }
67
+
68
+ it 'is required' do
69
+ expect(instance.required?).to be_truthy
70
+ end
71
+ end
72
+
73
+ context 'with create context' do
74
+ let (:validator) { double(options: {on: :create}, kind: :presence) }
75
+
76
+ it 'is required for new records' do
77
+ allow(model).to receive(:new_record?).and_return(true)
78
+ expect(instance.required?).to be_truthy
79
+ end
80
+
81
+ it 'is not required for existing records' do
82
+ allow(model).to receive(:new_record?).and_return(false)
83
+ expect(instance.required?).to be_falsey
84
+ end
85
+ end
86
+
87
+ context 'with update context' do
88
+ let (:validator) { double(options: {on: :update}, kind: :presence) }
89
+
90
+ it 'is not required for new records' do
91
+ allow(model).to receive(:new_record?).and_return(true)
92
+ expect(instance.required?).to be_falsey
93
+ end
94
+
95
+ it 'is required for existing records' do
96
+ allow(model).to receive(:new_record?).and_return(false)
97
+ expect(instance.required?).to be_truthy
98
+ end
99
+ end
100
+ end
101
+
102
+ context 'with options[:on] as array' do
103
+ context 'with save context' do
104
+ let (:validator) { double(options: {on: [:save]}, kind: :presence) }
105
+
106
+ it 'is required' do
107
+ expect(instance.required?).to be_truthy
108
+ end
109
+ end
110
+
111
+ context 'with create context' do
112
+ let (:validator) { double(options: {on: [:create]}, kind: :presence) }
113
+
114
+ it 'is required for new records' do
115
+ allow(model).to receive(:new_record?).and_return(true)
116
+ expect(instance.required?).to be_truthy
117
+ end
118
+
119
+ it 'is not required for existing records' do
120
+ allow(model).to receive(:new_record?).and_return(false)
121
+ expect(instance.required?).to be_falsey
122
+ end
123
+ end
124
+
125
+ context 'with update context' do
126
+ let (:validator) { double(options: {on: [:update]}, kind: :presence) }
127
+
128
+ it 'is not required for new records' do
129
+ allow(model).to receive(:new_record?).and_return(true)
130
+ expect(instance.required?).to be_falsey
131
+ end
132
+
133
+ it 'is required for existing records' do
134
+ allow(model).to receive(:new_record?).and_return(false)
135
+ expect(instance.required?).to be_truthy
136
+ end
137
+ end
138
+
139
+ context 'with save and create context' do
140
+ let (:validator) { double(options: {on: [:save, :create]}, kind: :presence) }
141
+
142
+ it 'is required for new records' do
143
+ allow(model).to receive(:new_record?).and_return(true)
144
+ expect(instance.required?).to be_truthy
145
+ end
146
+
147
+ it 'is required for existing records' do
148
+ allow(model).to receive(:new_record?).and_return(false)
149
+ expect(instance.required?).to be_truthy
150
+ end
151
+ end
152
+
153
+ context 'with save and update context' do
154
+ let (:validator) { double(options: {on: [:save, :create]}, kind: :presence) }
155
+
156
+ it 'is required for new records' do
157
+ allow(model).to receive(:new_record?).and_return(true)
158
+ expect(instance.required?).to be_truthy
159
+ end
160
+
161
+ it 'is required for existing records' do
162
+ allow(model).to receive(:new_record?).and_return(false)
163
+ expect(instance.required?).to be_truthy
164
+ end
165
+ end
166
+
167
+ context 'with create and update context' do
168
+ let (:validator) { double(options: {on: [:create, :update]}, kind: :presence) }
169
+
170
+ it 'is required for new records' do
171
+ allow(model).to receive(:new_record?).and_return(true)
172
+ expect(instance.required?).to be_truthy
173
+ end
174
+
175
+ it 'is required for existing records' do
176
+ allow(model).to receive(:new_record?).and_return(false)
177
+ expect(instance.required?).to be_truthy
178
+ end
179
+ end
180
+
181
+ context 'with save and other context' do
182
+ let (:validator) { double(options: {on: [:save, :foo]}, kind: :presence) }
183
+
184
+ it 'is required for new records' do
185
+ allow(model).to receive(:new_record?).and_return(true)
186
+ expect(instance.required?).to be_truthy
187
+ end
188
+
189
+ it 'is required for existing records' do
190
+ allow(model).to receive(:new_record?).and_return(false)
191
+ expect(instance.required?).to be_truthy
192
+ end
193
+ end
194
+
195
+ context 'with create and other context' do
196
+ let (:validator) { double(options: {on: [:create, :foo]}, kind: :presence) }
197
+
198
+ it 'is required for new records' do
199
+ allow(model).to receive(:new_record?).and_return(true)
200
+ expect(instance.required?).to be_truthy
201
+ end
202
+
203
+ it 'is not required for existing records' do
204
+ allow(model).to receive(:new_record?).and_return(false)
205
+ expect(instance.required?).to be_falsey
206
+ end
207
+ end
208
+
209
+ context 'with update and other context' do
210
+ let (:validator) { double(options: {on: [:update, :foo]}, kind: :presence) }
211
+
212
+ it 'is not required for new records' do
213
+ allow(model).to receive(:new_record?).and_return(true)
214
+ expect(instance.required?).to be_falsey
215
+ end
216
+
217
+ it 'is required for existing records' do
218
+ allow(model).to receive(:new_record?).and_return(false)
219
+ expect(instance.required?).to be_truthy
220
+ end
221
+ end
222
+ end
223
+ end
224
+
225
+ context 'with inclusion validator' do
226
+ context 'with allow blank' do
227
+ let (:validator) { double(options: {allow_blank: true}, kind: :inclusion) }
228
+
229
+ it 'is not required' do
230
+ expect(instance.required?).to be_falsey
231
+ end
232
+ end
233
+
234
+ context 'without allow blank' do
235
+ let (:validator) { double(options: {allow_blank: false}, kind: :inclusion) }
236
+
237
+ it 'is required' do
238
+ expect(instance.required?).to be_truthy
239
+ end
240
+ end
241
+ end
242
+
243
+ context 'with a length validator' do
244
+ context 'with allow blank' do
245
+ let (:validator) { double(options: {allow_blank: true}, kind: :length) }
246
+
247
+ it 'is not required' do
248
+ expect(instance.required?).to be_falsey
249
+ end
250
+ end
251
+
252
+ context 'without allow blank' do
253
+ let (:validator) { double(options: {allow_blank: false}, kind: :length) }
254
+
255
+ it 'is not required' do
256
+ expect(instance.required?).to be_falsey
257
+ end
258
+
259
+ context 'with a minimum > 0' do
260
+ let (:validator) { double(options: {allow_blank: false, minimum: 1}, kind: :length) }
261
+
262
+ it 'is required' do
263
+ expect(instance.required?).to be_truthy
264
+ end
265
+ end
266
+
267
+ context 'with a minimum <= 0' do
268
+ let (:validator) { double(options: {allow_blank: false, minimum: 0}, kind: :length) }
269
+
270
+ it 'is not required' do
271
+ expect(instance.required?).to be_falsey
272
+ end
273
+ end
274
+
275
+ context 'with a defined range starting with > 0' do
276
+ let (:validator) { double(options: {allow_blank: false, within: 1..5}, kind: :length) }
277
+
278
+ it 'is required' do
279
+ expect(instance.required?).to be_truthy
280
+ end
281
+ end
282
+
283
+ context 'with a defined range starting with <= 0' do
284
+ let (:validator) { double(options: {allow_blank: false, within: 0..5}, kind: :length) }
285
+
286
+ it 'is not required' do
287
+ expect(instance.required?).to be_falsey
288
+ end
289
+ end
290
+ end
291
+ end
292
+
293
+ context 'with another validator' do
294
+ let (:validator) { double(options: {allow_blank: true}, kind: :foo) }
295
+
296
+ it 'is not required' do
297
+ expect(instance.required?).to be_falsey
298
+ end
299
+ end
300
+ end
301
+
302
+ context 'with multiple validators' do
303
+ let(:validations) { [validator1, validator2] }
304
+
305
+ context 'with a on create presence validator and a on update presence validator' do
306
+ let(:validator1) { double(options: {on: :create}, kind: :presence) }
307
+ let(:validator2) { double(options: {}, kind: :presence) }
308
+
309
+ before :example do
310
+ allow(model).to receive(:new_record?).and_return(false)
311
+ end
312
+
313
+ it 'is required' do
314
+ expect(instance.required?).to be_truthy
315
+ end
316
+ end
317
+
318
+ context 'with a on create presence validator and a presence validator' do
319
+ let (:validator1) { double(options: {on: :create}, kind: :presence) }
320
+ let (:validator2) { double(options: {}, kind: :presence) }
321
+
322
+ before :example do
323
+ allow(model).to receive(:new_record?).and_return(false)
324
+ end
325
+
326
+ it 'is required' do
327
+ expect(instance.required?).to be_truthy
328
+ end
329
+ end
330
+
331
+ context 'with a on create presence validator and a allow blank inclusion validator' do
332
+ let(:validator1) { double(options: {on: :create}, kind: :presence) }
333
+ let(:validator2) { double(options: {allow_blank: true}, kind: :inclusion) }
334
+
335
+ before :example do
336
+ allow(model).to receive(:new_record?).and_return(false)
337
+ end
338
+
339
+ it 'is required' do
340
+ expect(instance.required?).to be_falsey
341
+ end
342
+ end
343
+ end
344
+ end
345
+
346
+ describe '#validation_min' do
347
+ let(:validations) { [validator] }
348
+
349
+ context 'with a greater_than numericality validator' do
350
+ let(:validator) { double(options: { greater_than: option_value }, kind: :numericality) }
351
+
352
+ context 'with a symbol' do
353
+ let(:option_value) { :a_symbol }
354
+
355
+ it 'returns one greater' do
356
+ allow(model).to receive(:send).with(option_value).and_return(14)
357
+ expect(instance.validation_min).to eq 15
358
+ end
359
+ end
360
+
361
+ context 'with a proc' do
362
+ let(:option_value) { Proc.new { 10 } }
363
+
364
+ it 'returns one greater' do
365
+ expect(instance.validation_min).to eq 11
366
+ end
367
+ end
368
+
369
+ context 'with a number' do
370
+ let(:option_value) { 8 }
371
+
372
+ it 'returns one greater' do
373
+ expect(instance.validation_min).to eq 9
374
+ end
375
+ end
376
+ end
377
+
378
+ context 'with a greater_than_or_equal_to numericality validator' do
379
+ let(:validator) do
380
+ double(
381
+ options: { greater_than_or_equal_to: option_value },
382
+ kind: :numericality
383
+ )
384
+ end
385
+
386
+ context 'with a symbol' do
387
+ let(:option_value) { :a_symbol }
388
+
389
+ it 'returns the instance method amount' do
390
+ allow(model).to receive(:send).with(option_value).and_return(14)
391
+ expect(instance.validation_min).to eq 14
392
+ end
393
+ end
394
+
395
+ context 'with a proc' do
396
+ let(:option_value) { Proc.new { 10 } }
397
+
398
+ it 'returns the proc amount' do
399
+ expect(instance.validation_min).to eq 10
400
+ end
401
+ end
402
+
403
+ context 'with a number' do
404
+ let(:option_value) { 8 }
405
+
406
+ it 'returns the number' do
407
+ expect(instance.validation_min).to eq 8
408
+ end
409
+ end
410
+ end
411
+ end
412
+
413
+ describe '#validation_max' do
414
+ let(:validations) do
415
+ [
416
+ ActiveModel::Validations::NumericalityValidator.new(
417
+ validator_options.merge(attributes: :an_attribute)
418
+ )
419
+ ]
420
+ end
421
+
422
+ context 'with a less_than numericality validator' do
423
+ let(:validator_options) { { less_than: option_value } }
424
+
425
+ context 'with a symbol' do
426
+ let(:option_value) { :a_symbol }
427
+
428
+ it 'returns one less' do
429
+ allow(model).to receive(:send).with(option_value).and_return(14)
430
+ expect(instance.validation_max).to eq 13
431
+ end
432
+ end
433
+
434
+ context 'with a proc' do
435
+ let(:option_value) { proc { 10 } }
436
+
437
+ it 'returns one less' do
438
+ expect(instance.validation_max).to eq 9
439
+ end
440
+ end
441
+
442
+ context 'with a number' do
443
+ let(:option_value) { 8 }
444
+
445
+ it 'returns one less' do
446
+ expect(instance.validation_max).to eq 7
447
+ end
448
+ end
449
+ end
450
+
451
+ context 'with a less_than_or_equal_to numericality validator' do
452
+ let(:validator_options) { { less_than_or_equal_to: option_value } }
453
+
454
+ context 'with a symbol' do
455
+ let(:option_value) { :a_symbol }
456
+
457
+ it 'returns the instance method amount' do
458
+ allow(model).to receive(:send).with(option_value).and_return(14)
459
+ expect(instance.validation_max).to eq 14
460
+ end
461
+ end
462
+
463
+ context 'with a proc' do
464
+ let(:option_value) { proc { 10 } }
465
+
466
+ it 'returns the proc amount' do
467
+ expect(instance.validation_max).to eq 10
468
+ end
469
+ end
470
+
471
+ context 'with a number' do
472
+ let(:option_value) { 8 }
473
+
474
+ it 'returns the number' do
475
+ expect(instance.validation_max).to eq 8
476
+ end
477
+ end
478
+ end
479
+ end
480
+ end
481
+