active_interaction 4.0.5 → 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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -6
  3. data/README.md +67 -32
  4. data/lib/active_interaction/array_input.rb +77 -0
  5. data/lib/active_interaction/base.rb +14 -98
  6. data/lib/active_interaction/concerns/active_recordable.rb +3 -3
  7. data/lib/active_interaction/concerns/missable.rb +2 -2
  8. data/lib/active_interaction/errors.rb +6 -88
  9. data/lib/active_interaction/exceptions.rb +47 -0
  10. data/lib/active_interaction/filter/column.rb +59 -0
  11. data/lib/active_interaction/filter/error.rb +40 -0
  12. data/lib/active_interaction/filter.rb +44 -53
  13. data/lib/active_interaction/filters/abstract_date_time_filter.rb +9 -6
  14. data/lib/active_interaction/filters/abstract_numeric_filter.rb +7 -3
  15. data/lib/active_interaction/filters/array_filter.rb +36 -10
  16. data/lib/active_interaction/filters/boolean_filter.rb +4 -3
  17. data/lib/active_interaction/filters/date_filter.rb +1 -1
  18. data/lib/active_interaction/filters/date_time_filter.rb +1 -1
  19. data/lib/active_interaction/filters/decimal_filter.rb +1 -1
  20. data/lib/active_interaction/filters/float_filter.rb +1 -1
  21. data/lib/active_interaction/filters/hash_filter.rb +23 -15
  22. data/lib/active_interaction/filters/integer_filter.rb +1 -1
  23. data/lib/active_interaction/filters/interface_filter.rb +12 -12
  24. data/lib/active_interaction/filters/object_filter.rb +9 -3
  25. data/lib/active_interaction/filters/record_filter.rb +21 -11
  26. data/lib/active_interaction/filters/string_filter.rb +1 -1
  27. data/lib/active_interaction/filters/symbol_filter.rb +1 -1
  28. data/lib/active_interaction/filters/time_filter.rb +4 -4
  29. data/lib/active_interaction/hash_input.rb +43 -0
  30. data/lib/active_interaction/input.rb +23 -0
  31. data/lib/active_interaction/inputs.rb +157 -46
  32. data/lib/active_interaction/locale/en.yml +0 -1
  33. data/lib/active_interaction/locale/fr.yml +0 -1
  34. data/lib/active_interaction/locale/it.yml +0 -1
  35. data/lib/active_interaction/locale/ja.yml +0 -1
  36. data/lib/active_interaction/locale/pt-BR.yml +0 -1
  37. data/lib/active_interaction/modules/validation.rb +6 -17
  38. data/lib/active_interaction/version.rb +1 -1
  39. data/lib/active_interaction.rb +43 -36
  40. data/spec/active_interaction/array_input_spec.rb +166 -0
  41. data/spec/active_interaction/base_spec.rb +15 -240
  42. data/spec/active_interaction/concerns/active_modelable_spec.rb +3 -3
  43. data/spec/active_interaction/concerns/active_recordable_spec.rb +7 -7
  44. data/spec/active_interaction/concerns/hashable_spec.rb +8 -8
  45. data/spec/active_interaction/concerns/missable_spec.rb +9 -9
  46. data/spec/active_interaction/concerns/runnable_spec.rb +34 -32
  47. data/spec/active_interaction/errors_spec.rb +60 -43
  48. data/spec/active_interaction/{filter_column_spec.rb → filter/column_spec.rb} +3 -10
  49. data/spec/active_interaction/filter_spec.rb +6 -6
  50. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +2 -2
  51. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +2 -2
  52. data/spec/active_interaction/filters/array_filter_spec.rb +99 -24
  53. data/spec/active_interaction/filters/boolean_filter_spec.rb +12 -11
  54. data/spec/active_interaction/filters/date_filter_spec.rb +32 -27
  55. data/spec/active_interaction/filters/date_time_filter_spec.rb +34 -29
  56. data/spec/active_interaction/filters/decimal_filter_spec.rb +20 -18
  57. data/spec/active_interaction/filters/file_filter_spec.rb +7 -7
  58. data/spec/active_interaction/filters/float_filter_spec.rb +19 -17
  59. data/spec/active_interaction/filters/hash_filter_spec.rb +16 -18
  60. data/spec/active_interaction/filters/integer_filter_spec.rb +24 -22
  61. data/spec/active_interaction/filters/interface_filter_spec.rb +105 -82
  62. data/spec/active_interaction/filters/object_filter_spec.rb +52 -36
  63. data/spec/active_interaction/filters/record_filter_spec.rb +61 -39
  64. data/spec/active_interaction/filters/string_filter_spec.rb +7 -7
  65. data/spec/active_interaction/filters/symbol_filter_spec.rb +6 -6
  66. data/spec/active_interaction/filters/time_filter_spec.rb +57 -34
  67. data/spec/active_interaction/hash_input_spec.rb +58 -0
  68. data/spec/active_interaction/i18n_spec.rb +22 -17
  69. data/spec/active_interaction/inputs_spec.rb +167 -23
  70. data/spec/active_interaction/integration/array_interaction_spec.rb +3 -7
  71. data/spec/active_interaction/modules/validation_spec.rb +8 -31
  72. data/spec/spec_helper.rb +8 -0
  73. data/spec/support/concerns.rb +2 -2
  74. data/spec/support/filters.rb +27 -51
  75. data/spec/support/interactions.rb +4 -4
  76. metadata +45 -95
  77. data/lib/active_interaction/filter_column.rb +0 -57
@@ -10,8 +10,8 @@ describe ActiveInteraction::InterfaceFilter, :filter do
10
10
  let(:name) { :interface_module }
11
11
  end
12
12
 
13
- describe '#cast' do
14
- let(:result) { filter.send(:cast, value, nil) }
13
+ describe '#process' do
14
+ let(:result) { filter.process(value, nil) }
15
15
 
16
16
  context 'with an implicit constant name' do
17
17
  context 'passed an instance' do
@@ -24,7 +24,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
24
24
  end
25
25
 
26
26
  it 'returns a the value' do
27
- expect(result).to eql value
27
+ expect(result.value).to eql value
28
28
  end
29
29
  end
30
30
 
@@ -35,7 +35,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
35
35
  end
36
36
 
37
37
  it 'returns a the value' do
38
- expect(result).to eql value
38
+ expect(result.value).to eql value
39
39
  end
40
40
  end
41
41
 
@@ -46,7 +46,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
46
46
  end
47
47
 
48
48
  it 'returns a the value' do
49
- expect(result).to eql value
49
+ expect(result.value).to eql value
50
50
  end
51
51
  end
52
52
 
@@ -54,10 +54,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
54
54
  let(:name) { :interface_module }
55
55
  let(:value) { Class.new }
56
56
 
57
- it 'raises an error' do
58
- expect do
59
- result
60
- end.to raise_error ActiveInteraction::InvalidValueError
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
61
62
  end
62
63
  end
63
64
 
@@ -65,10 +66,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
65
66
  let(:name) { :interface_module }
66
67
  let(:value) { nil }
67
68
 
68
- it 'raises an error' do
69
- expect do
70
- result
71
- end.to raise_error ActiveInteraction::MissingValueError
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
72
74
  end
73
75
  end
74
76
 
@@ -78,10 +80,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
78
80
  InterfaceClass.new
79
81
  end
80
82
 
81
- it 'raises an error' do
82
- expect do
83
- result
84
- end.to raise_error ActiveInteraction::InvalidValueError
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
85
88
  end
86
89
  end
87
90
  end
@@ -94,7 +97,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
94
97
  end
95
98
 
96
99
  it 'returns a the value' do
97
- expect(result).to eql value
100
+ expect(result.value).to eql value
98
101
  end
99
102
  end
100
103
 
@@ -107,7 +110,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
107
110
  end
108
111
 
109
112
  it 'returns a the value' do
110
- expect(result).to eql value
113
+ expect(result.value).to eql value
111
114
  end
112
115
  end
113
116
 
@@ -115,10 +118,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
115
118
  let(:name) { :interface_class }
116
119
  let(:value) { Class }
117
120
 
118
- it 'raises an error' do
119
- expect do
120
- result
121
- end.to raise_error ActiveInteraction::InvalidValueError
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
122
126
  end
123
127
  end
124
128
 
@@ -126,10 +130,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
126
130
  let(:name) { :interface_class }
127
131
  let(:value) { InterfaceClass }
128
132
 
129
- it 'raises an error' do
130
- expect do
131
- result
132
- end.to raise_error ActiveInteraction::InvalidValueError
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
133
138
  end
134
139
  end
135
140
  end
@@ -144,7 +149,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
144
149
  end
145
150
 
146
151
  it 'returns a the value' do
147
- expect(result).to eql value
152
+ expect(result.value).to eql value
148
153
  end
149
154
  end
150
155
 
@@ -152,10 +157,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
152
157
  let(:name) { :interface_module }
153
158
  let(:value) { Module.new }
154
159
 
155
- it 'raises an error' do
156
- expect do
157
- result
158
- end.to raise_error ActiveInteraction::InvalidValueError
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
159
165
  end
160
166
  end
161
167
 
@@ -163,10 +169,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
163
169
  let(:name) { :interface_module }
164
170
  let(:value) { InterfaceModule }
165
171
 
166
- it 'raises an error' do
167
- expect do
168
- result
169
- end.to raise_error ActiveInteraction::InvalidValueError
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
170
177
  end
171
178
  end
172
179
  end
@@ -187,6 +194,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
187
194
  context 'passed an instance' do
188
195
  context 'with the module included' do
189
196
  before { options.merge!(from: :interface_module) }
197
+
190
198
  let(:value) do
191
199
  Class.new do
192
200
  include InterfaceModule
@@ -194,29 +202,31 @@ describe ActiveInteraction::InterfaceFilter, :filter do
194
202
  end
195
203
 
196
204
  it 'returns a the value' do
197
- expect(result).to eql value
205
+ expect(result.value).to eql value
198
206
  end
199
207
  end
200
208
 
201
209
  context 'with the class inherited from' do
202
210
  before { options.merge!(from: :interface_class) }
211
+
203
212
  let(:value) do
204
213
  Class.new(InterfaceClass) {}.new # rubocop:disable Lint/EmptyBlock
205
214
  end
206
215
 
207
216
  it 'returns a the value' do
208
- expect(result).to eql value
217
+ expect(result.value).to eql value
209
218
  end
210
219
  end
211
220
 
212
221
  context 'that is extended by the ancestor' do
213
222
  before { options.merge!(from: :interface_module) }
223
+
214
224
  let(:value) do
215
225
  Class.new {}.new.extend(InterfaceModule) # rubocop:disable Lint/EmptyBlock
216
226
  end
217
227
 
218
228
  it 'returns a the value' do
219
- expect(result).to eql value
229
+ expect(result.value).to eql value
220
230
  end
221
231
  end
222
232
 
@@ -224,10 +234,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
224
234
  let(:name) { :interface_class }
225
235
  let(:value) { Class.new }
226
236
 
227
- it 'raises an error' do
228
- expect do
229
- result
230
- end.to raise_error ActiveInteraction::InvalidValueError
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
231
242
  end
232
243
  end
233
244
 
@@ -235,10 +246,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
235
246
  let(:name) { :interface_class }
236
247
  let(:value) { InterfaceClass.new }
237
248
 
238
- it 'raises an error' do
239
- expect do
240
- result
241
- end.to raise_error ActiveInteraction::InvalidValueError
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
242
254
  end
243
255
  end
244
256
  end
@@ -246,17 +258,19 @@ describe ActiveInteraction::InterfaceFilter, :filter do
246
258
  context 'passed a class' do
247
259
  context 'with the class inherited from' do
248
260
  before { options.merge!(from: :interface_class) }
261
+
249
262
  let(:value) do
250
263
  Class.new(InterfaceClass) {} # rubocop:disable Lint/EmptyBlock
251
264
  end
252
265
 
253
266
  it 'returns a the value' do
254
- expect(result).to eql value
267
+ expect(result.value).to eql value
255
268
  end
256
269
  end
257
270
 
258
271
  context 'that is extended by the ancestor' do
259
272
  before { options.merge!(from: :interface_module) }
273
+
260
274
  let(:value) do
261
275
  Class.new do
262
276
  extend InterfaceModule
@@ -264,7 +278,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
264
278
  end
265
279
 
266
280
  it 'returns a the value' do
267
- expect(result).to eql value
281
+ expect(result.value).to eql value
268
282
  end
269
283
  end
270
284
 
@@ -272,10 +286,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
272
286
  let(:name) { :interface_class }
273
287
  let(:value) { Class }
274
288
 
275
- it 'raises an error' do
276
- expect do
277
- result
278
- end.to raise_error ActiveInteraction::InvalidValueError
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
279
294
  end
280
295
  end
281
296
 
@@ -283,10 +298,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
283
298
  let(:name) { :interface_class }
284
299
  let(:value) { InterfaceClass }
285
300
 
286
- it 'raises an error' do
287
- expect do
288
- result
289
- end.to raise_error ActiveInteraction::InvalidValueError
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
290
306
  end
291
307
  end
292
308
  end
@@ -294,6 +310,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
294
310
  context 'passed a module' do
295
311
  context 'that is extended by the ancestor' do
296
312
  before { options.merge!(from: :interface_module) }
313
+
297
314
  let(:value) do
298
315
  Module.new do
299
316
  extend InterfaceModule
@@ -301,7 +318,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
301
318
  end
302
319
 
303
320
  it 'returns a the value' do
304
- expect(result).to eql value
321
+ expect(result.value).to eql value
305
322
  end
306
323
  end
307
324
 
@@ -309,10 +326,11 @@ describe ActiveInteraction::InterfaceFilter, :filter do
309
326
  let(:name) { :interface_module }
310
327
  let(:value) { Module.new }
311
328
 
312
- it 'raises an error' do
313
- expect do
314
- result
315
- end.to raise_error ActiveInteraction::InvalidValueError
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
316
334
  end
317
335
  end
318
336
 
@@ -320,16 +338,18 @@ describe ActiveInteraction::InterfaceFilter, :filter do
320
338
  let(:name) { :interface_module }
321
339
  let(:value) { InterfaceModule }
322
340
 
323
- it 'raises an error' do
324
- expect do
325
- result
326
- end.to raise_error ActiveInteraction::InvalidValueError
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
327
346
  end
328
347
  end
329
348
  end
330
349
 
331
350
  context 'given an invalid name' do
332
351
  before { options.merge!(from: :invalid) }
352
+
333
353
  let(:value) { Object }
334
354
 
335
355
  it 'raises an error' do
@@ -353,17 +373,18 @@ describe ActiveInteraction::InterfaceFilter, :filter do
353
373
  end
354
374
 
355
375
  it 'returns a the value' do
356
- expect(result).to eql value
376
+ expect(result.value).to eql value
357
377
  end
358
378
  end
359
379
 
360
380
  context 'passed an invalid instance' do
361
381
  let(:value) { Class.new }
362
382
 
363
- it 'raises an error' do
364
- expect do
365
- result
366
- end.to raise_error ActiveInteraction::InvalidValueError
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
367
388
  end
368
389
  end
369
390
 
@@ -377,17 +398,18 @@ describe ActiveInteraction::InterfaceFilter, :filter do
377
398
  end
378
399
 
379
400
  it 'returns a the value' do
380
- expect(result).to eql value
401
+ expect(result.value).to eql value
381
402
  end
382
403
  end
383
404
 
384
405
  context 'passed an invalid class' do
385
406
  let(:value) { Class }
386
407
 
387
- it 'raises an error' do
388
- expect do
389
- result
390
- end.to raise_error ActiveInteraction::InvalidValueError
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
391
413
  end
392
414
  end
393
415
 
@@ -401,17 +423,18 @@ describe ActiveInteraction::InterfaceFilter, :filter do
401
423
  end
402
424
 
403
425
  it 'returns a the value' do
404
- expect(result).to eql value
426
+ expect(result.value).to eql value
405
427
  end
406
428
  end
407
429
 
408
430
  context 'passed an invalid module' do
409
431
  let(:value) { Module.new }
410
432
 
411
- it 'raises an error' do
412
- expect do
413
- result
414
- end.to raise_error ActiveInteraction::InvalidValueError
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
415
438
  end
416
439
  end
417
440
  end
@@ -432,7 +455,7 @@ describe ActiveInteraction::InterfaceFilter, :filter do
432
455
 
433
456
  describe '#database_column_type' do
434
457
  it 'returns :string' do
435
- expect(filter.database_column_type).to eql :string
458
+ expect(filter.database_column_type).to be :string
436
459
  end
437
460
  end
438
461
  end
@@ -15,19 +15,19 @@ BackupObjectThing = ObjectThing
15
15
 
16
16
  describe ActiveInteraction::ObjectFilter, :filter do
17
17
  include_context 'filters'
18
- it_behaves_like 'a filter'
19
-
20
18
  before do
21
19
  options[:class] = ObjectThing
22
20
  end
23
21
 
24
- describe '#cast' do
22
+ it_behaves_like 'a filter'
23
+
24
+ describe '#process' do
25
25
  let(:value) { ObjectThing.new }
26
- let(:result) { filter.send(:cast, value, nil) }
26
+ let(:result) { filter.process(value, nil) }
27
27
 
28
28
  context 'with an instance of the class' do
29
29
  it 'returns the instance' do
30
- expect(result).to eql value
30
+ expect(result.value).to eql value
31
31
  end
32
32
 
33
33
  context 'with an instance that is a subclass' do
@@ -35,18 +35,18 @@ describe ActiveInteraction::ObjectFilter, :filter do
35
35
  let(:value) { subclass.new }
36
36
 
37
37
  it 'returns the instance' do
38
- expect(result).to eql value
38
+ expect(result.value).to eql value
39
39
  end
40
40
  end
41
41
 
42
42
  it 'handles reconstantizing' do
43
- expect(result).to eql value
43
+ expect(result.value).to eql value
44
44
 
45
45
  Object.send(:remove_const, :ObjectThing)
46
46
  ObjectThing = BackupObjectThing # rubocop:disable Lint/ConstantDefinitionInBlock
47
47
  value = ObjectThing.new
48
48
 
49
- expect(filter.send(:cast, value, nil)).to eql value
49
+ expect(filter.process(value, nil).value).to eql value
50
50
  end
51
51
 
52
52
  it 'handles reconstantizing subclasses' do
@@ -57,11 +57,12 @@ describe ActiveInteraction::ObjectFilter, :filter do
57
57
  class SubObjectThing < ObjectThing; end # rubocop:disable Lint/ConstantDefinitionInBlock
58
58
  value = SubObjectThing.new
59
59
 
60
- expect(filter.send(:cast, value, nil)).to eql value
60
+ expect(filter.process(value, nil).value).to eql value
61
61
  end
62
62
 
63
63
  context 'without the class available' do
64
64
  before { Object.send(:remove_const, :ObjectThing) }
65
+
65
66
  after { ObjectThing = BackupObjectThing } # rubocop:disable Lint/ConstantDefinitionInBlock
66
67
 
67
68
  it 'does not raise an error on initialization' do
@@ -76,7 +77,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
76
77
  end
77
78
 
78
79
  it 'returns the instance' do
79
- expect(result).to eql value
80
+ expect(result.value).to eql value
80
81
  end
81
82
  end
82
83
 
@@ -86,7 +87,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
86
87
  before { options[:class] = ObjectThings }
87
88
 
88
89
  it 'returns the instance' do
89
- expect(result).to eql value
90
+ expect(result.value).to eql value
90
91
  end
91
92
  end
92
93
 
@@ -111,7 +112,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
111
112
  end
112
113
 
113
114
  it 'calls the class method' do
114
- expect(result).to eql ObjectThing.converter(value)
115
+ expect(result.value).to eql ObjectThing.converter(value)
115
116
  end
116
117
  end
117
118
 
@@ -121,7 +122,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
121
122
  end
122
123
 
123
124
  it 'gets called' do
124
- expect(result).to eql ObjectThing.converter(value)
125
+ expect(result.value).to eql ObjectThing.converter(value)
125
126
  end
126
127
  end
127
128
 
@@ -129,8 +130,13 @@ describe ActiveInteraction::ObjectFilter, :filter do
129
130
  let(:value) { ObjectThing.new }
130
131
 
131
132
  it 'does not call the converter' do
132
- expect(ObjectThing).to_not receive(:converter)
133
- expect(result).to eql value
133
+ allow(ObjectThing).to receive(:converter)
134
+ result.value
135
+ expect(ObjectThing).to_not have_received(:converter)
136
+ end
137
+
138
+ it 'returns the correct value' do
139
+ expect(result.value).to eql value
134
140
  end
135
141
  end
136
142
 
@@ -139,18 +145,29 @@ describe ActiveInteraction::ObjectFilter, :filter do
139
145
  let(:value) { subclass.new }
140
146
 
141
147
  it 'does not call the converter' do
142
- expect(subclass).to_not receive(:converter)
143
- expect(result).to eql value
148
+ allow(subclass).to receive(:converter)
149
+ result.value
150
+ expect(subclass).to_not have_received(:converter)
151
+ end
152
+
153
+ it 'returns the correct value' do
154
+ expect(result.value).to eql value
144
155
  end
145
156
  end
146
157
 
147
158
  context 'with a nil value' do
148
159
  let(:value) { nil }
160
+
149
161
  include_context 'optional'
150
162
 
151
163
  it 'returns nil' do
152
- expect(ObjectThing).to_not receive(:converter)
153
- expect(result).to eql value
164
+ allow(ObjectThing).to receive(:converter)
165
+ result.value
166
+ expect(ObjectThing).to_not have_received(:converter)
167
+ end
168
+
169
+ it 'returns the correct value' do
170
+ expect(result.value).to eql value
154
171
  end
155
172
  end
156
173
 
@@ -171,17 +188,14 @@ describe ActiveInteraction::ObjectFilter, :filter do
171
188
  options[:converter] = :converter_with_error
172
189
  end
173
190
 
174
- it 'raises an error' do
175
- expect do
176
- result
177
- end.to raise_error ActiveInteraction::InvalidValueError
191
+ it 'indicates an error' do
192
+ error = result.errors.first
193
+
194
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
195
+ expect(error.type).to be :invalid_type
178
196
  end
179
197
  end
180
- end
181
- end
182
198
 
183
- describe '#clean' do
184
- context 'with a converter' do
185
199
  context 'that returns a nil' do
186
200
  let(:value) { '' }
187
201
 
@@ -190,10 +204,11 @@ describe ActiveInteraction::ObjectFilter, :filter do
190
204
  options[:converter] = ->(_) {}
191
205
  end
192
206
 
193
- it 'raises an error' do
194
- expect do
195
- filter.clean(value, nil)
196
- end.to raise_error ActiveInteraction::InvalidValueError
207
+ it 'indicates an error' do
208
+ error = filter.process(value, nil).errors.first
209
+
210
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
211
+ expect(error.type).to be :invalid_type
197
212
  end
198
213
  end
199
214
 
@@ -204,10 +219,11 @@ describe ActiveInteraction::ObjectFilter, :filter do
204
219
  options[:converter] = ->(_) { 'invalid' }
205
220
  end
206
221
 
207
- it 'raises an error' do
208
- expect do
209
- filter.clean(value, nil)
210
- end.to raise_error ActiveInteraction::InvalidValueError
222
+ it 'indicates an error' do
223
+ error = filter.process(value, nil).errors.first
224
+
225
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
226
+ expect(error.type).to be :invalid_type
211
227
  end
212
228
  end
213
229
  end
@@ -215,7 +231,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
215
231
 
216
232
  describe '#database_column_type' do
217
233
  it 'returns :string' do
218
- expect(filter.database_column_type).to eql :string
234
+ expect(filter.database_column_type).to be :string
219
235
  end
220
236
  end
221
237
  end