active_interaction 5.1.0 → 5.5.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -0
  3. data/README.md +11 -12
  4. data/lib/active_interaction/base.rb +2 -0
  5. data/lib/active_interaction/errors.rb +16 -16
  6. data/lib/active_interaction/filter.rb +9 -12
  7. data/lib/active_interaction/filters/array_filter.rb +1 -1
  8. data/lib/active_interaction/filters/hash_filter.rb +5 -1
  9. data/lib/active_interaction/grouped_input.rb +23 -3
  10. data/lib/active_interaction/locale/es.yml +23 -0
  11. data/lib/active_interaction/version.rb +1 -1
  12. metadata +13 -115
  13. data/spec/active_interaction/array_input_spec.rb +0 -166
  14. data/spec/active_interaction/base_spec.rb +0 -537
  15. data/spec/active_interaction/concerns/active_modelable_spec.rb +0 -45
  16. data/spec/active_interaction/concerns/active_recordable_spec.rb +0 -49
  17. data/spec/active_interaction/concerns/hashable_spec.rb +0 -46
  18. data/spec/active_interaction/concerns/missable_spec.rb +0 -99
  19. data/spec/active_interaction/concerns/runnable_spec.rb +0 -397
  20. data/spec/active_interaction/errors_spec.rb +0 -196
  21. data/spec/active_interaction/filter/column_spec.rb +0 -87
  22. data/spec/active_interaction/filter_spec.rb +0 -39
  23. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +0 -13
  24. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +0 -13
  25. data/spec/active_interaction/filters/array_filter_spec.rb +0 -245
  26. data/spec/active_interaction/filters/boolean_filter_spec.rb +0 -87
  27. data/spec/active_interaction/filters/date_filter_spec.rb +0 -178
  28. data/spec/active_interaction/filters/date_time_filter_spec.rb +0 -189
  29. data/spec/active_interaction/filters/decimal_filter_spec.rb +0 -126
  30. data/spec/active_interaction/filters/file_filter_spec.rb +0 -40
  31. data/spec/active_interaction/filters/float_filter_spec.rb +0 -110
  32. data/spec/active_interaction/filters/hash_filter_spec.rb +0 -129
  33. data/spec/active_interaction/filters/integer_filter_spec.rb +0 -104
  34. data/spec/active_interaction/filters/interface_filter_spec.rb +0 -461
  35. data/spec/active_interaction/filters/object_filter_spec.rb +0 -237
  36. data/spec/active_interaction/filters/record_filter_spec.rb +0 -206
  37. data/spec/active_interaction/filters/string_filter_spec.rb +0 -60
  38. data/spec/active_interaction/filters/symbol_filter_spec.rb +0 -46
  39. data/spec/active_interaction/filters/time_filter_spec.rb +0 -251
  40. data/spec/active_interaction/grouped_input_spec.rb +0 -17
  41. data/spec/active_interaction/hash_input_spec.rb +0 -58
  42. data/spec/active_interaction/i18n_spec.rb +0 -113
  43. data/spec/active_interaction/inputs_spec.rb +0 -266
  44. data/spec/active_interaction/integration/array_interaction_spec.rb +0 -88
  45. data/spec/active_interaction/integration/boolean_interaction_spec.rb +0 -5
  46. data/spec/active_interaction/integration/date_interaction_spec.rb +0 -5
  47. data/spec/active_interaction/integration/date_time_interaction_spec.rb +0 -5
  48. data/spec/active_interaction/integration/file_interaction_spec.rb +0 -18
  49. data/spec/active_interaction/integration/float_interaction_spec.rb +0 -5
  50. data/spec/active_interaction/integration/hash_interaction_spec.rb +0 -76
  51. data/spec/active_interaction/integration/integer_interaction_spec.rb +0 -5
  52. data/spec/active_interaction/integration/interface_interaction_spec.rb +0 -19
  53. data/spec/active_interaction/integration/object_interaction_spec.rb +0 -14
  54. data/spec/active_interaction/integration/record_integration_spec.rb +0 -5
  55. data/spec/active_interaction/integration/string_interaction_spec.rb +0 -5
  56. data/spec/active_interaction/integration/symbol_interaction_spec.rb +0 -5
  57. data/spec/active_interaction/integration/time_interaction_spec.rb +0 -88
  58. data/spec/active_interaction/modules/validation_spec.rb +0 -57
  59. data/spec/spec_helper.rb +0 -20
  60. data/spec/support/concerns.rb +0 -13
  61. data/spec/support/filters.rb +0 -227
  62. data/spec/support/interactions.rb +0 -124
@@ -1,129 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveInteraction::HashFilter, :filter do
4
- include_context 'filters'
5
- it_behaves_like 'a filter'
6
-
7
- context 'with a nested nameless filter' do
8
- let(:block) { proc { hash } }
9
-
10
- it 'raises an error' do
11
- expect { filter }.to raise_error ActiveInteraction::InvalidFilterError
12
- end
13
- end
14
-
15
- describe '#process' do
16
- let(:result) { filter.process(value, nil) }
17
-
18
- context 'with a Hash' do
19
- let(:value) { {} }
20
-
21
- it 'returns the Hash' do
22
- expect(result.value).to eql value
23
- expect(result.value).to be_an_instance_of HashWithIndifferentAccess
24
- end
25
- end
26
-
27
- context 'with an implicit Hash' do
28
- let(:value) do
29
- Class.new do
30
- def to_hash
31
- {}
32
- end
33
- end.new
34
- end
35
-
36
- it 'returns the Hash' do
37
- expect(result.value).to eql value.to_hash
38
- end
39
- end
40
-
41
- context 'with a non-empty Hash' do
42
- let(:value) { { a: {} } }
43
-
44
- it 'returns an empty Hash' do
45
- expect(result.value).to eql({})
46
- end
47
- end
48
-
49
- context 'with a nested filter' do
50
- let(:block) { proc { hash :a } }
51
-
52
- context 'with a Hash' do
53
- let(:value) { { 'a' => {} } }
54
-
55
- it 'returns the Hash' do
56
- expect(result.value).to eql value
57
- expect(result.value).to be_an_instance_of HashWithIndifferentAccess
58
- end
59
-
60
- context 'with String keys' do
61
- before do
62
- value.stringify_keys!
63
- end
64
-
65
- it 'does not raise an error' do
66
- expect { result }.to_not raise_error
67
- end
68
- end
69
- end
70
-
71
- context 'without a Hash' do
72
- let(:k) { 'a' }
73
- let(:v) { double }
74
- let(:value) { { k => v } }
75
-
76
- it 'indicates an error' do
77
- error = result.errors.first
78
-
79
- expect(result.errors.size).to be 1
80
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
81
- expect(error.name).to be :"#{filter.name}.#{error.filter.name}"
82
- expect(error.type).to be :invalid_type
83
- end
84
- end
85
- end
86
-
87
- context 'with :strip false' do
88
- let(:options) { { strip: false } }
89
-
90
- context 'with a non-empty Hash' do
91
- let(:value) { { 'a' => {} } }
92
-
93
- it 'returns an empty Hash' do
94
- expect(result.value).to eql value
95
- end
96
- end
97
- end
98
- end
99
-
100
- describe '#default' do
101
- context 'with a Hash' do
102
- before do
103
- options[:default] = {}
104
- end
105
-
106
- it 'returns the Hash' do
107
- expect(filter.default(nil)).to eql options[:default]
108
- end
109
- end
110
-
111
- context 'with a non-empty Hash' do
112
- before do
113
- options[:default] = { a: {} }
114
- end
115
-
116
- it 'raises an error' do
117
- expect do
118
- filter.default(nil)
119
- end.to raise_error ActiveInteraction::InvalidDefaultError
120
- end
121
- end
122
- end
123
-
124
- describe '#database_column_type' do
125
- it 'returns :string' do
126
- expect(filter.database_column_type).to be :string
127
- end
128
- end
129
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveInteraction::IntegerFilter, :filter do
4
- include_context 'filters'
5
- it_behaves_like 'a filter'
6
-
7
- describe '#process' do
8
- let(:result) { filter.process(value, nil) }
9
-
10
- context 'with an Integer' do
11
- let(:value) { rand(1 << 16) }
12
-
13
- it 'returns the Integer' do
14
- expect(result.value).to eql value
15
- end
16
- end
17
-
18
- context 'with a Numeric' do
19
- let(:value) { rand(1 << 16) + rand }
20
-
21
- it 'returns an Integer' do
22
- expect(result.value).to eql value.to_i
23
- end
24
- end
25
-
26
- context 'with a String' do
27
- let(:value) { rand(1 << 16).to_s }
28
-
29
- it 'returns an Integer' do
30
- expect(result.value).to eql Integer(value, 10)
31
- end
32
- end
33
-
34
- context 'with an invalid String' do
35
- let(:value) { 'invalid' }
36
-
37
- it 'indicates an error' do
38
- error = result.errors.first
39
-
40
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
41
- expect(error.type).to be :invalid_type
42
- end
43
- end
44
-
45
- context 'with an implicit String' do
46
- let(:value) do
47
- Class.new do
48
- def to_str
49
- '1'
50
- end
51
- end.new
52
- end
53
-
54
- it 'returns an Integer' do
55
- expect(result.value).to eql Integer(value.to_str, 10)
56
- end
57
- end
58
-
59
- context 'with a blank String' do
60
- let(:value) do
61
- Class.new do
62
- def to_str
63
- ' '
64
- end
65
- end.new
66
- end
67
-
68
- context 'optional' do
69
- include_context 'optional'
70
-
71
- it 'returns the default' do
72
- expect(result.value).to eql options[:default]
73
- end
74
- end
75
-
76
- context 'required' do
77
- include_context 'required'
78
-
79
- it 'indicates an error' do
80
- error = result.errors.first
81
-
82
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
83
- expect(error.type).to be :missing
84
- end
85
- end
86
- end
87
-
88
- it 'supports different bases' do
89
- expect(
90
- described_class.new(name, base: 8).process('071', nil).value
91
- ).to be 57
92
- error = described_class.new(name, base: 8).process('081', nil).errors.first
93
-
94
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
95
- expect(error.type).to be :invalid_type
96
- end
97
- end
98
-
99
- describe '#database_column_type' do
100
- it 'returns :integer' do
101
- expect(filter.database_column_type).to be :integer
102
- end
103
- end
104
- end
@@ -1,461 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module InterfaceModule; end
4
-
5
- class InterfaceClass; end # rubocop:disable Lint/EmptyClass
6
-
7
- describe ActiveInteraction::InterfaceFilter, :filter do
8
- include_context 'filters'
9
- it_behaves_like 'a filter' do
10
- let(:name) { :interface_module }
11
- end
12
-
13
- describe '#process' do
14
- let(:result) { filter.process(value, nil) }
15
-
16
- context 'with an implicit constant name' do
17
- context 'passed an instance' do
18
- context 'with the module included' do
19
- let(:name) { :interface_module }
20
- let(:value) do
21
- Class.new do
22
- include InterfaceModule
23
- end.new
24
- end
25
-
26
- it 'returns a the value' do
27
- expect(result.value).to eql value
28
- end
29
- end
30
-
31
- context 'with the class inherited from' do
32
- let(:name) { :interface_class }
33
- let(:value) do
34
- Class.new(InterfaceClass) {}.new # rubocop:disable Lint/EmptyBlock
35
- end
36
-
37
- it 'returns a the value' do
38
- expect(result.value).to eql value
39
- end
40
- end
41
-
42
- context 'that is extended by the ancestor' do
43
- let(:name) { :interface_module }
44
- let(:value) do
45
- Class.new {}.new.extend(InterfaceModule) # rubocop:disable Lint/EmptyBlock
46
- end
47
-
48
- it 'returns a the value' do
49
- expect(result.value).to eql value
50
- end
51
- end
52
-
53
- context 'that does not match' do
54
- let(:name) { :interface_module }
55
- let(:value) { Class.new }
56
-
57
- it 'indicates an error' do
58
- error = result.errors.first
59
-
60
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
61
- expect(error.type).to be :invalid_type
62
- end
63
- end
64
-
65
- context 'that is nil' do
66
- let(:name) { :interface_module }
67
- let(:value) { nil }
68
-
69
- it 'indicates an error' do
70
- error = result.errors.first
71
-
72
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
73
- expect(error.type).to be :missing
74
- end
75
- end
76
-
77
- context 'with the class itself' do
78
- let(:name) { :interface_class }
79
- let(:value) do
80
- InterfaceClass.new
81
- end
82
-
83
- it 'indicates an error' do
84
- error = result.errors.first
85
-
86
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
87
- expect(error.type).to be :invalid_type
88
- end
89
- end
90
- end
91
-
92
- context 'passed a class' do
93
- context 'with the class inherited from' do
94
- let(:name) { :interface_class }
95
- let(:value) do
96
- Class.new(InterfaceClass) {} # rubocop:disable Lint/EmptyBlock
97
- end
98
-
99
- it 'returns a the value' do
100
- expect(result.value).to eql value
101
- end
102
- end
103
-
104
- context 'that is extended by the ancestor' do
105
- let(:name) { :interface_module }
106
- let(:value) do
107
- Class.new do
108
- extend InterfaceModule
109
- end
110
- end
111
-
112
- it 'returns a the value' do
113
- expect(result.value).to eql value
114
- end
115
- end
116
-
117
- context 'that does not match' do
118
- let(:name) { :interface_class }
119
- let(:value) { Class }
120
-
121
- it 'indicates an error' do
122
- error = result.errors.first
123
-
124
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
125
- expect(error.type).to be :invalid_type
126
- end
127
- end
128
-
129
- context 'with the class itself' do
130
- let(:name) { :interface_class }
131
- let(:value) { InterfaceClass }
132
-
133
- it 'indicates an error' do
134
- error = result.errors.first
135
-
136
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
137
- expect(error.type).to be :invalid_type
138
- end
139
- end
140
- end
141
-
142
- context 'passed a module' do
143
- context 'that is extended by the ancestor' do
144
- let(:name) { :interface_module }
145
- let(:value) do
146
- Module.new do
147
- extend InterfaceModule
148
- end
149
- end
150
-
151
- it 'returns a the value' do
152
- expect(result.value).to eql value
153
- end
154
- end
155
-
156
- context 'that does not match' do
157
- let(:name) { :interface_module }
158
- let(:value) { Module.new }
159
-
160
- it 'indicates an error' do
161
- error = result.errors.first
162
-
163
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
164
- expect(error.type).to be :invalid_type
165
- end
166
- end
167
-
168
- context 'with the module itself' do
169
- let(:name) { :interface_module }
170
- let(:value) { InterfaceModule }
171
-
172
- it 'indicates an error' do
173
- error = result.errors.first
174
-
175
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
176
- expect(error.type).to be :invalid_type
177
- end
178
- end
179
- end
180
-
181
- context 'given an invalid name' do
182
- let(:name) { :invalid }
183
- let(:value) { Object }
184
-
185
- it 'raises an error' do
186
- expect do
187
- result
188
- end.to raise_error ActiveInteraction::InvalidNameError
189
- end
190
- end
191
- end
192
-
193
- context 'with a constant given' do
194
- context 'passed an instance' do
195
- context 'with the module included' do
196
- before { options.merge!(from: :interface_module) }
197
-
198
- let(:value) do
199
- Class.new do
200
- include InterfaceModule
201
- end.new
202
- end
203
-
204
- it 'returns a the value' do
205
- expect(result.value).to eql value
206
- end
207
- end
208
-
209
- context 'with the class inherited from' do
210
- before { options.merge!(from: :interface_class) }
211
-
212
- let(:value) do
213
- Class.new(InterfaceClass) {}.new # rubocop:disable Lint/EmptyBlock
214
- end
215
-
216
- it 'returns a the value' do
217
- expect(result.value).to eql value
218
- end
219
- end
220
-
221
- context 'that is extended by the ancestor' do
222
- before { options.merge!(from: :interface_module) }
223
-
224
- let(:value) do
225
- Class.new {}.new.extend(InterfaceModule) # rubocop:disable Lint/EmptyBlock
226
- end
227
-
228
- it 'returns a the value' do
229
- expect(result.value).to eql value
230
- end
231
- end
232
-
233
- context 'that does not match' do
234
- let(:name) { :interface_class }
235
- let(:value) { Class.new }
236
-
237
- it 'indicates an error' do
238
- error = result.errors.first
239
-
240
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
241
- expect(error.type).to be :invalid_type
242
- end
243
- end
244
-
245
- context 'with the class itself' do
246
- let(:name) { :interface_class }
247
- let(:value) { InterfaceClass.new }
248
-
249
- it 'indicates an error' do
250
- error = result.errors.first
251
-
252
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
253
- expect(error.type).to be :invalid_type
254
- end
255
- end
256
- end
257
-
258
- context 'passed a class' do
259
- context 'with the class inherited from' do
260
- before { options.merge!(from: :interface_class) }
261
-
262
- let(:value) do
263
- Class.new(InterfaceClass) {} # rubocop:disable Lint/EmptyBlock
264
- end
265
-
266
- it 'returns a the value' do
267
- expect(result.value).to eql value
268
- end
269
- end
270
-
271
- context 'that is extended by the ancestor' do
272
- before { options.merge!(from: :interface_module) }
273
-
274
- let(:value) do
275
- Class.new do
276
- extend InterfaceModule
277
- end
278
- end
279
-
280
- it 'returns a the value' do
281
- expect(result.value).to eql value
282
- end
283
- end
284
-
285
- context 'that does not match' do
286
- let(:name) { :interface_class }
287
- let(:value) { Class }
288
-
289
- it 'indicates an error' do
290
- error = result.errors.first
291
-
292
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
293
- expect(error.type).to be :invalid_type
294
- end
295
- end
296
-
297
- context 'with the class itself' do
298
- let(:name) { :interface_class }
299
- let(:value) { InterfaceClass }
300
-
301
- it 'indicates an error' do
302
- error = result.errors.first
303
-
304
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
305
- expect(error.type).to be :invalid_type
306
- end
307
- end
308
- end
309
-
310
- context 'passed a module' do
311
- context 'that is extended by the ancestor' do
312
- before { options.merge!(from: :interface_module) }
313
-
314
- let(:value) do
315
- Module.new do
316
- extend InterfaceModule
317
- end
318
- end
319
-
320
- it 'returns a the value' do
321
- expect(result.value).to eql value
322
- end
323
- end
324
-
325
- context 'that does not match' do
326
- let(:name) { :interface_module }
327
- let(:value) { Module.new }
328
-
329
- it 'indicates an error' do
330
- error = result.errors.first
331
-
332
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
333
- expect(error.type).to be :invalid_type
334
- end
335
- end
336
-
337
- context 'with the module itself' do
338
- let(:name) { :interface_module }
339
- let(:value) { InterfaceModule }
340
-
341
- it 'indicates an error' do
342
- error = result.errors.first
343
-
344
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
345
- expect(error.type).to be :invalid_type
346
- end
347
- end
348
- end
349
-
350
- context 'given an invalid name' do
351
- before { options.merge!(from: :invalid) }
352
-
353
- let(:value) { Object }
354
-
355
- it 'raises an error' do
356
- expect do
357
- result
358
- end.to raise_error ActiveInteraction::InvalidNameError
359
- end
360
- end
361
- end
362
-
363
- context 'with methods passed' do
364
- before { options[:methods] = %i[dump load] }
365
-
366
- context 'passed an valid instance' do
367
- let(:value) do
368
- Class.new do
369
- def dump; end
370
-
371
- def load; end
372
- end.new
373
- end
374
-
375
- it 'returns a the value' do
376
- expect(result.value).to eql value
377
- end
378
- end
379
-
380
- context 'passed an invalid instance' do
381
- let(:value) { Class.new }
382
-
383
- it 'indicates an error' do
384
- error = result.errors.first
385
-
386
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
387
- expect(error.type).to be :invalid_type
388
- end
389
- end
390
-
391
- context 'passed a class' do
392
- let(:value) do
393
- Class.new do
394
- def self.dump; end
395
-
396
- def self.load; end
397
- end
398
- end
399
-
400
- it 'returns a the value' do
401
- expect(result.value).to eql value
402
- end
403
- end
404
-
405
- context 'passed an invalid class' do
406
- let(:value) { Class }
407
-
408
- it 'indicates an error' do
409
- error = result.errors.first
410
-
411
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
412
- expect(error.type).to be :invalid_type
413
- end
414
- end
415
-
416
- context 'passed a module' do
417
- let(:value) do
418
- Module.new do
419
- def self.dump; end
420
-
421
- def self.load; end
422
- end
423
- end
424
-
425
- it 'returns a the value' do
426
- expect(result.value).to eql value
427
- end
428
- end
429
-
430
- context 'passed an invalid module' do
431
- let(:value) { Module.new }
432
-
433
- it 'indicates an error' do
434
- error = result.errors.first
435
-
436
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
437
- expect(error.type).to be :invalid_type
438
- end
439
- end
440
- end
441
-
442
- context 'with from and methods passed' do
443
- before do
444
- options[:from] = :module
445
- options[:methods] = %i[dump load]
446
- end
447
-
448
- it 'raises an error' do
449
- expect do
450
- filter
451
- end.to raise_error ActiveInteraction::InvalidFilterError
452
- end
453
- end
454
- end
455
-
456
- describe '#database_column_type' do
457
- it 'returns :string' do
458
- expect(filter.database_column_type).to be :string
459
- end
460
- end
461
- end