active_interaction 5.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -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/grouped_input.rb +23 -3
- data/lib/active_interaction/version.rb +1 -1
- metadata +12 -115
- 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: 9e3c0c4b273d6133644463ea773ea4551331ee7a9eb92c9dc9b3ff4b069aff55
|
4
|
+
data.tar.gz: bc874a3de1e5557e2baf01a59b62822fb073721f4e639559e47ce72ce50c41ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3af5f93ea4049897a6d10bf3da4e11d3eccfa14fd8a0180eeb84c6e695fadd9bc2990c0058bb605a9f7667c0759e32187797984128d3ab36b4e06ff176e26ea
|
7
|
+
data.tar.gz: 4b3fdc8b15977f1e0e46f654e97574581da9ebbdd851b7c91355c5ea32906fdd9b68e220bf89cc57973041995e47b3f9a8183155fbf5a1e8167d3be213c3ad8e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# [5.5.0][] (2025-02-02)
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
- Support for Ruby 3.4.
|
6
|
+
|
7
|
+
## Fixed
|
8
|
+
|
9
|
+
- OStruct was listed as a development dependency instead of a runtime dependency.
|
10
|
+
The need for OStruct has been removed entirely.
|
11
|
+
|
12
|
+
# [5.4.0][] (2024-11-23)
|
13
|
+
|
14
|
+
## Added
|
15
|
+
|
16
|
+
- [#579][] Support for Rails 8. Thanks @bvalentino!
|
17
|
+
|
18
|
+
## Fixed
|
19
|
+
|
20
|
+
- [#577][] Manually pull in the `ostruct` gem since it's being removed from stdlib.
|
21
|
+
|
22
|
+
# [5.3.0][] (2023-05-06)
|
23
|
+
|
24
|
+
## Added
|
25
|
+
|
26
|
+
- Added predicate methods for boolean values. Thanks @heka1024
|
27
|
+
|
28
|
+
## Fixed
|
29
|
+
|
30
|
+
- [#554][] - Non-detailed error should not lose options when merged.
|
31
|
+
- [#553][] - Improve error handling and documentation for hash filter defaults.
|
32
|
+
|
1
33
|
# [5.2.0][] (2022-10-22)
|
2
34
|
|
3
35
|
## Added
|
@@ -1130,6 +1162,9 @@ Example.run
|
|
1130
1162
|
|
1131
1163
|
- Initial release.
|
1132
1164
|
|
1165
|
+
[5.5.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.4.0...v5.5.0
|
1166
|
+
[5.4.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.3.0...v5.4.0
|
1167
|
+
[5.3.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.2.0...v5.3.0
|
1133
1168
|
[5.2.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.1.1...v5.2.0
|
1134
1169
|
[5.1.1]: https://github.com/AaronLasseigne/active_interaction/compare/v5.1.0...v5.1.1
|
1135
1170
|
[5.1.0]: https://github.com/AaronLasseigne/active_interaction/compare/v5.0.0...v5.1.0
|
@@ -1361,3 +1396,7 @@ Example.run
|
|
1361
1396
|
[#537]: https://github.com/AaronLasseigne/active_interaction/issues/537
|
1362
1397
|
[#539]: https://github.com/AaronLasseigne/active_interaction/issues/539
|
1363
1398
|
[#545]: https://github.com/AaronLasseigne/active_interaction/issues/545
|
1399
|
+
[#554]: https://github.com/AaronLasseigne/active_interaction/issues/554
|
1400
|
+
[#553]: https://github.com/AaronLasseigne/active_interaction/issues/553
|
1401
|
+
[#577]: https://github.com/AaronLasseigne/active_interaction/issues/577
|
1402
|
+
[#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.5'
|
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.5'
|
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
|
@@ -1,11 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
3
|
module ActiveInteraction
|
6
4
|
# Holds a group of inputs together for passing from {Base} to {Filter}s.
|
7
5
|
#
|
8
6
|
# @private
|
9
|
-
class GroupedInput
|
7
|
+
class GroupedInput
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
attr_reader :data
|
11
|
+
protected :data
|
12
|
+
|
13
|
+
def initialize(**data)
|
14
|
+
@data = data
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](key)
|
18
|
+
@data[key]
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(key, value)
|
22
|
+
@data[key] = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def <=>(other)
|
26
|
+
return nil unless other.is_a?(self.class)
|
27
|
+
|
28
|
+
data <=> other.data
|
29
|
+
end
|
10
30
|
end
|
11
31
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
8
8
|
- Taylor Fausak
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2025-02-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activemodel
|
@@ -20,7 +19,7 @@ dependencies:
|
|
20
19
|
version: '5.2'
|
21
20
|
- - "<"
|
22
21
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
22
|
+
version: '9'
|
24
23
|
type: :runtime
|
25
24
|
prerelease: false
|
26
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +29,7 @@ dependencies:
|
|
30
29
|
version: '5.2'
|
31
30
|
- - "<"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
32
|
+
version: '9'
|
34
33
|
- !ruby/object:Gem::Dependency
|
35
34
|
name: activesupport
|
36
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,7 +39,7 @@ dependencies:
|
|
40
39
|
version: '5.2'
|
41
40
|
- - "<"
|
42
41
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
42
|
+
version: '9'
|
44
43
|
type: :runtime
|
45
44
|
prerelease: false
|
46
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -50,7 +49,7 @@ dependencies:
|
|
50
49
|
version: '5.2'
|
51
50
|
- - "<"
|
52
51
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
52
|
+
version: '9'
|
54
53
|
- !ruby/object:Gem::Dependency
|
55
54
|
name: actionpack
|
56
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,14 +126,14 @@ dependencies:
|
|
127
126
|
requirements:
|
128
127
|
- - "~>"
|
129
128
|
- !ruby/object:Gem::Version
|
130
|
-
version: 1.
|
129
|
+
version: 1.68.0
|
131
130
|
type: :development
|
132
131
|
prerelease: false
|
133
132
|
version_requirements: !ruby/object:Gem::Requirement
|
134
133
|
requirements:
|
135
134
|
- - "~>"
|
136
135
|
- !ruby/object:Gem::Version
|
137
|
-
version: 1.
|
136
|
+
version: 1.68.0
|
138
137
|
- !ruby/object:Gem::Dependency
|
139
138
|
name: rubocop-rake
|
140
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,14 +154,14 @@ dependencies:
|
|
155
154
|
requirements:
|
156
155
|
- - "~>"
|
157
156
|
- !ruby/object:Gem::Version
|
158
|
-
version: 2.
|
157
|
+
version: 3.2.0
|
159
158
|
type: :development
|
160
159
|
prerelease: false
|
161
160
|
version_requirements: !ruby/object:Gem::Requirement
|
162
161
|
requirements:
|
163
162
|
- - "~>"
|
164
163
|
- !ruby/object:Gem::Version
|
165
|
-
version: 2.
|
164
|
+
version: 3.2.0
|
166
165
|
- !ruby/object:Gem::Dependency
|
167
166
|
name: sqlite3
|
168
167
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,56 +248,6 @@ files:
|
|
249
248
|
- lib/active_interaction/locale/pt-BR.yml
|
250
249
|
- lib/active_interaction/modules/validation.rb
|
251
250
|
- 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
251
|
homepage: https://github.com/AaronLasseigne/active_interaction
|
303
252
|
licenses:
|
304
253
|
- MIT
|
@@ -307,7 +256,6 @@ metadata:
|
|
307
256
|
source_code_uri: https://github.com/AaronLasseigne/active_interaction
|
308
257
|
changelog_uri: https://github.com/AaronLasseigne/active_interaction/blob/main/CHANGELOG.md
|
309
258
|
rubygems_mfa_required: 'true'
|
310
|
-
post_install_message:
|
311
259
|
rdoc_options: []
|
312
260
|
require_paths:
|
313
261
|
- lib
|
@@ -322,58 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
270
|
- !ruby/object:Gem::Version
|
323
271
|
version: '0'
|
324
272
|
requirements: []
|
325
|
-
rubygems_version: 3.
|
326
|
-
signing_key:
|
273
|
+
rubygems_version: 3.6.2
|
327
274
|
specification_version: 4
|
328
275
|
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
|
276
|
+
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
|