active_interaction 5.2.0 → 5.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +11 -12
- data/lib/active_interaction/base.rb +2 -0
- data/lib/active_interaction/errors.rb +16 -16
- data/lib/active_interaction/filters/hash_filter.rb +5 -1
- data/lib/active_interaction/version.rb +1 -1
- metadata +26 -112
- data/spec/active_interaction/array_input_spec.rb +0 -166
- data/spec/active_interaction/base_spec.rb +0 -537
- data/spec/active_interaction/concerns/active_modelable_spec.rb +0 -45
- data/spec/active_interaction/concerns/active_recordable_spec.rb +0 -49
- data/spec/active_interaction/concerns/hashable_spec.rb +0 -46
- data/spec/active_interaction/concerns/missable_spec.rb +0 -99
- data/spec/active_interaction/concerns/runnable_spec.rb +0 -397
- data/spec/active_interaction/errors_spec.rb +0 -196
- data/spec/active_interaction/filter/column_spec.rb +0 -87
- data/spec/active_interaction/filter_spec.rb +0 -60
- data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +0 -13
- data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +0 -13
- data/spec/active_interaction/filters/array_filter_spec.rb +0 -250
- data/spec/active_interaction/filters/boolean_filter_spec.rb +0 -87
- data/spec/active_interaction/filters/date_filter_spec.rb +0 -178
- data/spec/active_interaction/filters/date_time_filter_spec.rb +0 -189
- data/spec/active_interaction/filters/decimal_filter_spec.rb +0 -126
- data/spec/active_interaction/filters/file_filter_spec.rb +0 -40
- data/spec/active_interaction/filters/float_filter_spec.rb +0 -110
- data/spec/active_interaction/filters/hash_filter_spec.rb +0 -129
- data/spec/active_interaction/filters/integer_filter_spec.rb +0 -104
- data/spec/active_interaction/filters/interface_filter_spec.rb +0 -461
- data/spec/active_interaction/filters/object_filter_spec.rb +0 -237
- data/spec/active_interaction/filters/record_filter_spec.rb +0 -206
- data/spec/active_interaction/filters/string_filter_spec.rb +0 -60
- data/spec/active_interaction/filters/symbol_filter_spec.rb +0 -46
- data/spec/active_interaction/filters/time_filter_spec.rb +0 -251
- data/spec/active_interaction/grouped_input_spec.rb +0 -17
- data/spec/active_interaction/hash_input_spec.rb +0 -58
- data/spec/active_interaction/i18n_spec.rb +0 -113
- data/spec/active_interaction/inputs_spec.rb +0 -266
- data/spec/active_interaction/integration/array_interaction_spec.rb +0 -88
- data/spec/active_interaction/integration/boolean_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/date_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/date_time_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/file_interaction_spec.rb +0 -18
- data/spec/active_interaction/integration/float_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/hash_interaction_spec.rb +0 -76
- data/spec/active_interaction/integration/integer_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/interface_interaction_spec.rb +0 -19
- data/spec/active_interaction/integration/object_interaction_spec.rb +0 -14
- data/spec/active_interaction/integration/record_integration_spec.rb +0 -5
- data/spec/active_interaction/integration/string_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/symbol_interaction_spec.rb +0 -5
- data/spec/active_interaction/integration/time_interaction_spec.rb +0 -88
- data/spec/active_interaction/modules/validation_spec.rb +0 -57
- data/spec/spec_helper.rb +0 -20
- data/spec/support/concerns.rb +0 -13
- data/spec/support/filters.rb +0 -227
- data/spec/support/interactions.rb +0 -124
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f39aaac6de9ca228f9a223ef78ce39b17f7b934ac161e66067993b33968851c6
|
4
|
+
data.tar.gz: 9b16a1f1e0e0ecacb542709b103db93a79c9995a7cc90c5cff89d619ffcad204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c1796f310a05133999ad8b69ea16073f017856a4fb371d4f38381d8d69c3503b3b1b2e1e45126b4f8feec0723de622ce672d043b5e6a933840abd5825327235
|
7
|
+
data.tar.gz: b7af241f16b1554e186456e647e2d612446b4a1ad8bb9ae2a4fa903a5231fe4b04751e6ba4becd4c5d2edd69ebe4698ab27b82534a73a464ca631073a7f71160
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
# [5.4.0][] (2024-11-23)
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
- [#579][] Support for Rails 8. Thanks @bvalentino!
|
6
|
+
|
7
|
+
## Fixed
|
8
|
+
|
9
|
+
- [#577][] Manually pull in the `ostruct` gem since it's being removed from stdlib.
|
10
|
+
|
11
|
+
# [5.3.0][] (2023-05-06)
|
12
|
+
|
13
|
+
## Added
|
14
|
+
|
15
|
+
- Added predicate methods for boolean values. Thanks @heka1024
|
16
|
+
|
17
|
+
## Fixed
|
18
|
+
|
19
|
+
- [#554][] - Non-detailed error should not lose options when merged.
|
20
|
+
- [#553][] - Improve error handling and documentation for hash filter defaults.
|
21
|
+
|
1
22
|
# [5.2.0][] (2022-10-22)
|
2
23
|
|
3
24
|
## Added
|
@@ -1130,6 +1151,7 @@ Example.run
|
|
1130
1151
|
|
1131
1152
|
- Initial release.
|
1132
1153
|
|
1154
|
+
[5.3.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.2.0...v5.3.0
|
1133
1155
|
[5.2.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.1.1...v5.2.0
|
1134
1156
|
[5.1.1]: https://github.com/AaronLasseigne/active_interaction/compare/v5.1.0...v5.1.1
|
1135
1157
|
[5.1.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.0.0...v5.1.0
|
@@ -1361,3 +1383,7 @@ Example.run
|
|
1361
1383
|
[#537]: https://github.com/AaronLasseigne/active_interaction/issues/537
|
1362
1384
|
[#539]: https://github.com/AaronLasseigne/active_interaction/issues/539
|
1363
1385
|
[#545]: https://github.com/AaronLasseigne/active_interaction/issues/545
|
1386
|
+
[#554]: https://github.com/AaronLasseigne/active_interaction/issues/554
|
1387
|
+
[#553]: https://github.com/AaronLasseigne/active_interaction/issues/553
|
1388
|
+
[#577]: https://github.com/AaronLasseigne/active_interaction/issues/577
|
1389
|
+
[#579]: https://github.com/AaronLasseigne/active_interaction/pull/579
|
data/README.md
CHANGED
@@ -2,16 +2,11 @@
|
|
2
2
|
|
3
3
|
ActiveInteraction manages application-specific business logic.
|
4
4
|
It's an implementation of service objects designed to blend seamlessly into Rails.
|
5
|
+
It also helps you write safer code by validating that your inputs conform to your expectations.
|
6
|
+
If ActiveModel deals with your nouns, then ActiveInteraction handles your verbs.
|
5
7
|
|
6
8
|
[](https://rubygems.org/gems/active_interaction)
|
7
|
-
[](https://github.com/AaronLasseigne/active_interaction/actions?query=workflow%3ATest)
|
15
10
|
|
16
11
|
- [Installation](#installation)
|
17
12
|
- [Basic usage](#basic-usage)
|
@@ -65,13 +60,13 @@ handles your verbs.
|
|
65
60
|
Add it to your Gemfile:
|
66
61
|
|
67
62
|
``` rb
|
68
|
-
gem 'active_interaction', '~> 5.
|
63
|
+
gem 'active_interaction', '~> 5.4'
|
69
64
|
```
|
70
65
|
|
71
66
|
Or install it manually:
|
72
67
|
|
73
68
|
``` sh
|
74
|
-
$ gem install active_interaction --version '~> 5.
|
69
|
+
$ gem install active_interaction --version '~> 5.4'
|
75
70
|
```
|
76
71
|
|
77
72
|
This project uses [Semantic Versioning][]. Check out [GitHub releases][] for a
|
@@ -296,12 +291,15 @@ Boolean filters convert the strings `"1"`, `"true"`, and `"on"`
|
|
296
291
|
(case-insensitive) into `true`. They also convert `"0"`, `"false"`, and `"off"`
|
297
292
|
into `false`. Blank strings will be treated as `nil`.
|
298
293
|
|
294
|
+
Boolean values can be accessed using the filter name but can also be checked
|
295
|
+
using a predicate method of the same name.
|
296
|
+
|
299
297
|
``` rb
|
300
298
|
class BooleanInteraction < ActiveInteraction::Base
|
301
299
|
boolean :kool_aid
|
302
300
|
|
303
301
|
def execute
|
304
|
-
'Oh yeah!' if kool_aid
|
302
|
+
'Oh yeah!' if kool_aid? # could also use `kool_aid`
|
305
303
|
end
|
306
304
|
end
|
307
305
|
|
@@ -360,7 +358,8 @@ HashInteraction.run!(preferences: { newsletter: true, 'sweepstakes' => false })
|
|
360
358
|
|
361
359
|
Setting default hash values can be tricky. The default value has to be either
|
362
360
|
`nil` or `{}`. Use `nil` to make the hash optional. Use `{}` if you want to set
|
363
|
-
some defaults for values inside the hash.
|
361
|
+
some defaults for values inside the hash. If any nested filter uses a
|
362
|
+
[lazy default](#defaults) then the hash must also use a lazy default.
|
364
363
|
|
365
364
|
``` rb
|
366
365
|
hash :optional,
|
@@ -11,7 +11,15 @@ module ActiveInteraction
|
|
11
11
|
#
|
12
12
|
# @return [Errors]
|
13
13
|
def merge!(other)
|
14
|
-
|
14
|
+
other.messages.each do |attribute, messages|
|
15
|
+
messages.zip(other.details[attribute]) do |message, detail|
|
16
|
+
if detailed_error?(detail)
|
17
|
+
merge_detail!(attribute, detail, message)
|
18
|
+
else
|
19
|
+
merge_message!(attribute, detail, message)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
15
23
|
|
16
24
|
self
|
17
25
|
end
|
@@ -31,24 +39,16 @@ module ActiveInteraction
|
|
31
39
|
detail[:error].is_a?(Symbol)
|
32
40
|
end
|
33
41
|
|
34
|
-
def merge_message!(attribute, message)
|
42
|
+
def merge_message!(attribute, detail, message)
|
43
|
+
options = detail.dup
|
44
|
+
options.delete(:error)
|
45
|
+
|
35
46
|
unless attribute?(attribute)
|
36
47
|
message = full_message(attribute, message)
|
37
48
|
attribute = :base
|
38
49
|
end
|
39
|
-
add(attribute, message) unless added?(attribute, message)
|
40
|
-
end
|
41
50
|
|
42
|
-
|
43
|
-
other.messages.each do |attribute, messages|
|
44
|
-
messages.zip(other.details[attribute]) do |message, detail|
|
45
|
-
if detailed_error?(detail)
|
46
|
-
merge_detail!(attribute, detail, message)
|
47
|
-
else
|
48
|
-
merge_message!(attribute, message)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
51
|
+
add(attribute, message, **options) unless added?(attribute, message, **options)
|
52
52
|
end
|
53
53
|
|
54
54
|
def merge_detail!(attribute, detail, message)
|
@@ -56,9 +56,9 @@ module ActiveInteraction
|
|
56
56
|
options = detail.dup
|
57
57
|
error = options.delete(:error)
|
58
58
|
|
59
|
-
add(attribute, error, **options
|
59
|
+
add(attribute, error, **options, message: message) unless added?(attribute, error, **options)
|
60
60
|
else
|
61
|
-
merge_message!(attribute, message)
|
61
|
+
merge_message!(attribute, detail, message)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -25,7 +25,7 @@ module ActiveInteraction
|
|
25
25
|
|
26
26
|
register :hash
|
27
27
|
|
28
|
-
def process(value, context)
|
28
|
+
def process(value, context) # rubocop:disable Metrics/AbcSize
|
29
29
|
input = super
|
30
30
|
|
31
31
|
return HashInput.new(self, value: input.value, error: input.errors.first) if input.errors.first
|
@@ -36,6 +36,10 @@ module ActiveInteraction
|
|
36
36
|
children = {}
|
37
37
|
|
38
38
|
filters.each do |name, filter|
|
39
|
+
if filter.options[:default].is_a?(Proc) && !options[:default].is_a?(Proc)
|
40
|
+
raise InvalidDefaultError, "#{self.name}: must use a lazy default if any nested filter uses a lazy default"
|
41
|
+
end
|
42
|
+
|
39
43
|
filter.process(input.value[name], context).tap do |result|
|
40
44
|
value[name] = result.value
|
41
45
|
children[name.to_sym] = result
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: '5.2'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
23
|
+
version: '9'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: '5.2'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '9'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: activesupport
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version: '5.2'
|
41
41
|
- - "<"
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '9'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
version: '5.2'
|
51
51
|
- - "<"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '9'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: actionpack
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,6 +93,20 @@ dependencies:
|
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '2.1'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: ostruct
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.6'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.6'
|
96
110
|
- !ruby/object:Gem::Dependency
|
97
111
|
name: rake
|
98
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,14 +141,14 @@ dependencies:
|
|
127
141
|
requirements:
|
128
142
|
- - "~>"
|
129
143
|
- !ruby/object:Gem::Version
|
130
|
-
version: 1.
|
144
|
+
version: 1.68.0
|
131
145
|
type: :development
|
132
146
|
prerelease: false
|
133
147
|
version_requirements: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
149
|
- - "~>"
|
136
150
|
- !ruby/object:Gem::Version
|
137
|
-
version: 1.
|
151
|
+
version: 1.68.0
|
138
152
|
- !ruby/object:Gem::Dependency
|
139
153
|
name: rubocop-rake
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,14 +169,14 @@ dependencies:
|
|
155
169
|
requirements:
|
156
170
|
- - "~>"
|
157
171
|
- !ruby/object:Gem::Version
|
158
|
-
version: 2.
|
172
|
+
version: 3.2.0
|
159
173
|
type: :development
|
160
174
|
prerelease: false
|
161
175
|
version_requirements: !ruby/object:Gem::Requirement
|
162
176
|
requirements:
|
163
177
|
- - "~>"
|
164
178
|
- !ruby/object:Gem::Version
|
165
|
-
version: 2.
|
179
|
+
version: 3.2.0
|
166
180
|
- !ruby/object:Gem::Dependency
|
167
181
|
name: sqlite3
|
168
182
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,56 +263,6 @@ files:
|
|
249
263
|
- lib/active_interaction/locale/pt-BR.yml
|
250
264
|
- lib/active_interaction/modules/validation.rb
|
251
265
|
- lib/active_interaction/version.rb
|
252
|
-
- spec/active_interaction/array_input_spec.rb
|
253
|
-
- spec/active_interaction/base_spec.rb
|
254
|
-
- spec/active_interaction/concerns/active_modelable_spec.rb
|
255
|
-
- spec/active_interaction/concerns/active_recordable_spec.rb
|
256
|
-
- spec/active_interaction/concerns/hashable_spec.rb
|
257
|
-
- spec/active_interaction/concerns/missable_spec.rb
|
258
|
-
- spec/active_interaction/concerns/runnable_spec.rb
|
259
|
-
- spec/active_interaction/errors_spec.rb
|
260
|
-
- spec/active_interaction/filter/column_spec.rb
|
261
|
-
- spec/active_interaction/filter_spec.rb
|
262
|
-
- spec/active_interaction/filters/abstract_date_time_filter_spec.rb
|
263
|
-
- spec/active_interaction/filters/abstract_numeric_filter_spec.rb
|
264
|
-
- spec/active_interaction/filters/array_filter_spec.rb
|
265
|
-
- spec/active_interaction/filters/boolean_filter_spec.rb
|
266
|
-
- spec/active_interaction/filters/date_filter_spec.rb
|
267
|
-
- spec/active_interaction/filters/date_time_filter_spec.rb
|
268
|
-
- spec/active_interaction/filters/decimal_filter_spec.rb
|
269
|
-
- spec/active_interaction/filters/file_filter_spec.rb
|
270
|
-
- spec/active_interaction/filters/float_filter_spec.rb
|
271
|
-
- spec/active_interaction/filters/hash_filter_spec.rb
|
272
|
-
- spec/active_interaction/filters/integer_filter_spec.rb
|
273
|
-
- spec/active_interaction/filters/interface_filter_spec.rb
|
274
|
-
- spec/active_interaction/filters/object_filter_spec.rb
|
275
|
-
- spec/active_interaction/filters/record_filter_spec.rb
|
276
|
-
- spec/active_interaction/filters/string_filter_spec.rb
|
277
|
-
- spec/active_interaction/filters/symbol_filter_spec.rb
|
278
|
-
- spec/active_interaction/filters/time_filter_spec.rb
|
279
|
-
- spec/active_interaction/grouped_input_spec.rb
|
280
|
-
- spec/active_interaction/hash_input_spec.rb
|
281
|
-
- spec/active_interaction/i18n_spec.rb
|
282
|
-
- spec/active_interaction/inputs_spec.rb
|
283
|
-
- spec/active_interaction/integration/array_interaction_spec.rb
|
284
|
-
- spec/active_interaction/integration/boolean_interaction_spec.rb
|
285
|
-
- spec/active_interaction/integration/date_interaction_spec.rb
|
286
|
-
- spec/active_interaction/integration/date_time_interaction_spec.rb
|
287
|
-
- spec/active_interaction/integration/file_interaction_spec.rb
|
288
|
-
- spec/active_interaction/integration/float_interaction_spec.rb
|
289
|
-
- spec/active_interaction/integration/hash_interaction_spec.rb
|
290
|
-
- spec/active_interaction/integration/integer_interaction_spec.rb
|
291
|
-
- spec/active_interaction/integration/interface_interaction_spec.rb
|
292
|
-
- spec/active_interaction/integration/object_interaction_spec.rb
|
293
|
-
- spec/active_interaction/integration/record_integration_spec.rb
|
294
|
-
- spec/active_interaction/integration/string_interaction_spec.rb
|
295
|
-
- spec/active_interaction/integration/symbol_interaction_spec.rb
|
296
|
-
- spec/active_interaction/integration/time_interaction_spec.rb
|
297
|
-
- spec/active_interaction/modules/validation_spec.rb
|
298
|
-
- spec/spec_helper.rb
|
299
|
-
- spec/support/concerns.rb
|
300
|
-
- spec/support/filters.rb
|
301
|
-
- spec/support/interactions.rb
|
302
266
|
homepage: https://github.com/AaronLasseigne/active_interaction
|
303
267
|
licenses:
|
304
268
|
- MIT
|
@@ -322,58 +286,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
286
|
- !ruby/object:Gem::Version
|
323
287
|
version: '0'
|
324
288
|
requirements: []
|
325
|
-
rubygems_version: 3.
|
289
|
+
rubygems_version: 3.5.22
|
326
290
|
signing_key:
|
327
291
|
specification_version: 4
|
328
292
|
summary: Manage application specific business logic.
|
329
|
-
test_files:
|
330
|
-
- spec/active_interaction/array_input_spec.rb
|
331
|
-
- spec/active_interaction/base_spec.rb
|
332
|
-
- spec/active_interaction/concerns/active_modelable_spec.rb
|
333
|
-
- spec/active_interaction/concerns/active_recordable_spec.rb
|
334
|
-
- spec/active_interaction/concerns/hashable_spec.rb
|
335
|
-
- spec/active_interaction/concerns/missable_spec.rb
|
336
|
-
- spec/active_interaction/concerns/runnable_spec.rb
|
337
|
-
- spec/active_interaction/errors_spec.rb
|
338
|
-
- spec/active_interaction/filter/column_spec.rb
|
339
|
-
- spec/active_interaction/filter_spec.rb
|
340
|
-
- spec/active_interaction/filters/abstract_date_time_filter_spec.rb
|
341
|
-
- spec/active_interaction/filters/abstract_numeric_filter_spec.rb
|
342
|
-
- spec/active_interaction/filters/array_filter_spec.rb
|
343
|
-
- spec/active_interaction/filters/boolean_filter_spec.rb
|
344
|
-
- spec/active_interaction/filters/date_filter_spec.rb
|
345
|
-
- spec/active_interaction/filters/date_time_filter_spec.rb
|
346
|
-
- spec/active_interaction/filters/decimal_filter_spec.rb
|
347
|
-
- spec/active_interaction/filters/file_filter_spec.rb
|
348
|
-
- spec/active_interaction/filters/float_filter_spec.rb
|
349
|
-
- spec/active_interaction/filters/hash_filter_spec.rb
|
350
|
-
- spec/active_interaction/filters/integer_filter_spec.rb
|
351
|
-
- spec/active_interaction/filters/interface_filter_spec.rb
|
352
|
-
- spec/active_interaction/filters/object_filter_spec.rb
|
353
|
-
- spec/active_interaction/filters/record_filter_spec.rb
|
354
|
-
- spec/active_interaction/filters/string_filter_spec.rb
|
355
|
-
- spec/active_interaction/filters/symbol_filter_spec.rb
|
356
|
-
- spec/active_interaction/filters/time_filter_spec.rb
|
357
|
-
- spec/active_interaction/grouped_input_spec.rb
|
358
|
-
- spec/active_interaction/hash_input_spec.rb
|
359
|
-
- spec/active_interaction/i18n_spec.rb
|
360
|
-
- spec/active_interaction/inputs_spec.rb
|
361
|
-
- spec/active_interaction/integration/array_interaction_spec.rb
|
362
|
-
- spec/active_interaction/integration/boolean_interaction_spec.rb
|
363
|
-
- spec/active_interaction/integration/date_interaction_spec.rb
|
364
|
-
- spec/active_interaction/integration/date_time_interaction_spec.rb
|
365
|
-
- spec/active_interaction/integration/file_interaction_spec.rb
|
366
|
-
- spec/active_interaction/integration/float_interaction_spec.rb
|
367
|
-
- spec/active_interaction/integration/hash_interaction_spec.rb
|
368
|
-
- spec/active_interaction/integration/integer_interaction_spec.rb
|
369
|
-
- spec/active_interaction/integration/interface_interaction_spec.rb
|
370
|
-
- spec/active_interaction/integration/object_interaction_spec.rb
|
371
|
-
- spec/active_interaction/integration/record_integration_spec.rb
|
372
|
-
- spec/active_interaction/integration/string_interaction_spec.rb
|
373
|
-
- spec/active_interaction/integration/symbol_interaction_spec.rb
|
374
|
-
- spec/active_interaction/integration/time_interaction_spec.rb
|
375
|
-
- spec/active_interaction/modules/validation_spec.rb
|
376
|
-
- spec/spec_helper.rb
|
377
|
-
- spec/support/concerns.rb
|
378
|
-
- spec/support/filters.rb
|
379
|
-
- spec/support/interactions.rb
|
293
|
+
test_files: []
|
@@ -1,166 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveInteraction::ArrayInput do
|
4
|
-
subject(:input) do
|
5
|
-
described_class.new(filter,
|
6
|
-
value: value,
|
7
|
-
error: error,
|
8
|
-
index_errors: index_errors,
|
9
|
-
children: children
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:filter) do
|
14
|
-
ActiveInteraction::ArrayFilter.new(:a, &block)
|
15
|
-
end
|
16
|
-
let(:block) { proc { integer } }
|
17
|
-
let(:value) { nil }
|
18
|
-
let(:error) { nil }
|
19
|
-
let(:index_errors) { false }
|
20
|
-
let(:children) { [] }
|
21
|
-
|
22
|
-
describe '#errors' do
|
23
|
-
context 'with no errors' do
|
24
|
-
it 'returns an empty array' do
|
25
|
-
expect(input.errors).to be_empty
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with an error on the array' do
|
30
|
-
let(:error) { ActiveInteraction::Filter::Error.new(filter, :invalid_type) }
|
31
|
-
|
32
|
-
it 'returns one error in the array' do
|
33
|
-
expect(input.errors.size).to be 1
|
34
|
-
|
35
|
-
error = input.errors.first
|
36
|
-
expect(error.name).to be filter.name
|
37
|
-
expect(error.type).to be :invalid_type
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with children with errors' do
|
42
|
-
let(:child_filter) { ActiveInteraction::IntegerFilter.new(:'') }
|
43
|
-
let(:child_error) { ActiveInteraction::Filter::Error.new(child_filter, :invalid_type) }
|
44
|
-
let(:child1) { ActiveInteraction::Input.new(child_filter, value: 'a', error: child_error) }
|
45
|
-
let(:child2) { ActiveInteraction::Input.new(child_filter, value: 'b', error: child_error) }
|
46
|
-
let(:children) { [child1, child2] }
|
47
|
-
|
48
|
-
context 'with an error on the array' do
|
49
|
-
let(:error) { ActiveInteraction::Filter::Error.new(filter, :invalid_type) }
|
50
|
-
|
51
|
-
it 'returns one error in the array' do
|
52
|
-
expect(input.errors.size).to be 1
|
53
|
-
|
54
|
-
error = input.errors.first
|
55
|
-
expect(error.name).to be filter.name
|
56
|
-
expect(error.type).to be :invalid_type
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'without :index_errors' do
|
61
|
-
it 'promotes the first child error and returns it in the array' do
|
62
|
-
expect(input.errors.size).to be 1
|
63
|
-
|
64
|
-
error = input.errors.first
|
65
|
-
expect(error.name).to be filter.name
|
66
|
-
expect(error.type).to be :invalid_type
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'with :index_errors' do
|
71
|
-
let(:index_errors) { true }
|
72
|
-
|
73
|
-
it 'lists all child errors in the array' do
|
74
|
-
expect(input.errors.size).to be 2
|
75
|
-
|
76
|
-
input.errors.each_with_index do |error, i|
|
77
|
-
expect(error.name).to be :"#{filter.name}[#{i}]"
|
78
|
-
expect(error.type).to be :invalid_type
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'with a nested array' do
|
83
|
-
let(:invalid_value) { Object.new }
|
84
|
-
let(:array_child) do
|
85
|
-
filter = ActiveInteraction::IntegerFilter.new(:'')
|
86
|
-
ActiveInteraction::Input.new(filter,
|
87
|
-
value: invalid_value,
|
88
|
-
error: ActiveInteraction::Filter::Error.new(filter, :invalid_type)
|
89
|
-
)
|
90
|
-
end
|
91
|
-
let(:child_filter) { ActiveInteraction::ArrayFilter.new(:'') { integer } }
|
92
|
-
let(:child) do
|
93
|
-
described_class.new(child_filter,
|
94
|
-
value: [invalid_value],
|
95
|
-
index_errors: index_errors,
|
96
|
-
children: [array_child]
|
97
|
-
)
|
98
|
-
end
|
99
|
-
let(:children) { [child] }
|
100
|
-
|
101
|
-
it 'returns the error' do
|
102
|
-
expect(input.errors.size).to be 1
|
103
|
-
|
104
|
-
error = input.errors.first
|
105
|
-
expect(error.name).to be :"#{filter.name}[0][0]"
|
106
|
-
expect(error.type).to be :invalid_type
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'with a nested hash' do
|
111
|
-
let(:hash_child_a) do
|
112
|
-
filter = ActiveInteraction::IntegerFilter.new(:a)
|
113
|
-
ActiveInteraction::Input.new(filter,
|
114
|
-
value: nil,
|
115
|
-
error: ActiveInteraction::Filter::Error.new(filter, :missing)
|
116
|
-
)
|
117
|
-
end
|
118
|
-
let(:hash_child_b) do
|
119
|
-
filter = ActiveInteraction::IntegerFilter.new(:b)
|
120
|
-
ActiveInteraction::Input.new(filter,
|
121
|
-
value: nil,
|
122
|
-
error: ActiveInteraction::Filter::Error.new(filter, :missing)
|
123
|
-
)
|
124
|
-
end
|
125
|
-
let(:child_filter) { ActiveInteraction::HashFilter.new(:'') { integer :a, :b } }
|
126
|
-
let(:child) do
|
127
|
-
ActiveInteraction::HashInput.new(child_filter, value: {}, children: { a: hash_child_a, b: hash_child_b })
|
128
|
-
end
|
129
|
-
let(:children) { [child] }
|
130
|
-
|
131
|
-
it 'list all child errors' do
|
132
|
-
expect(input.errors.size).to be 2
|
133
|
-
|
134
|
-
error = input.errors.first
|
135
|
-
expect(error.name).to be :"#{filter.name}[0].a"
|
136
|
-
expect(error.type).to be :missing
|
137
|
-
|
138
|
-
error = input.errors.last
|
139
|
-
expect(error.name).to be :"#{filter.name}[0].b"
|
140
|
-
expect(error.type).to be :missing
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'with an invalid hash' do
|
144
|
-
let(:child_filter) { ActiveInteraction::HashFilter.new(:'') }
|
145
|
-
let(:child) do
|
146
|
-
ActiveInteraction::HashInput.new(child_filter,
|
147
|
-
value: Object.new,
|
148
|
-
error: ActiveInteraction::Filter::Error.new(child_filter, :invalid_type),
|
149
|
-
children: {}
|
150
|
-
)
|
151
|
-
end
|
152
|
-
let(:children) { [child] }
|
153
|
-
|
154
|
-
it 'list all child errors' do
|
155
|
-
expect(input.errors.size).to be 1
|
156
|
-
|
157
|
-
error = input.errors.first
|
158
|
-
expect(error.name).to be :"#{filter.name}[0]"
|
159
|
-
expect(error.type).to be :invalid_type
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|