active_interaction 5.2.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -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/filters/hash_filter.rb +5 -1
  7. data/lib/active_interaction/version.rb +1 -1
  8. metadata +26 -112
  9. data/spec/active_interaction/array_input_spec.rb +0 -166
  10. data/spec/active_interaction/base_spec.rb +0 -537
  11. data/spec/active_interaction/concerns/active_modelable_spec.rb +0 -45
  12. data/spec/active_interaction/concerns/active_recordable_spec.rb +0 -49
  13. data/spec/active_interaction/concerns/hashable_spec.rb +0 -46
  14. data/spec/active_interaction/concerns/missable_spec.rb +0 -99
  15. data/spec/active_interaction/concerns/runnable_spec.rb +0 -397
  16. data/spec/active_interaction/errors_spec.rb +0 -196
  17. data/spec/active_interaction/filter/column_spec.rb +0 -87
  18. data/spec/active_interaction/filter_spec.rb +0 -60
  19. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +0 -13
  20. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +0 -13
  21. data/spec/active_interaction/filters/array_filter_spec.rb +0 -250
  22. data/spec/active_interaction/filters/boolean_filter_spec.rb +0 -87
  23. data/spec/active_interaction/filters/date_filter_spec.rb +0 -178
  24. data/spec/active_interaction/filters/date_time_filter_spec.rb +0 -189
  25. data/spec/active_interaction/filters/decimal_filter_spec.rb +0 -126
  26. data/spec/active_interaction/filters/file_filter_spec.rb +0 -40
  27. data/spec/active_interaction/filters/float_filter_spec.rb +0 -110
  28. data/spec/active_interaction/filters/hash_filter_spec.rb +0 -129
  29. data/spec/active_interaction/filters/integer_filter_spec.rb +0 -104
  30. data/spec/active_interaction/filters/interface_filter_spec.rb +0 -461
  31. data/spec/active_interaction/filters/object_filter_spec.rb +0 -237
  32. data/spec/active_interaction/filters/record_filter_spec.rb +0 -206
  33. data/spec/active_interaction/filters/string_filter_spec.rb +0 -60
  34. data/spec/active_interaction/filters/symbol_filter_spec.rb +0 -46
  35. data/spec/active_interaction/filters/time_filter_spec.rb +0 -251
  36. data/spec/active_interaction/grouped_input_spec.rb +0 -17
  37. data/spec/active_interaction/hash_input_spec.rb +0 -58
  38. data/spec/active_interaction/i18n_spec.rb +0 -113
  39. data/spec/active_interaction/inputs_spec.rb +0 -266
  40. data/spec/active_interaction/integration/array_interaction_spec.rb +0 -88
  41. data/spec/active_interaction/integration/boolean_interaction_spec.rb +0 -5
  42. data/spec/active_interaction/integration/date_interaction_spec.rb +0 -5
  43. data/spec/active_interaction/integration/date_time_interaction_spec.rb +0 -5
  44. data/spec/active_interaction/integration/file_interaction_spec.rb +0 -18
  45. data/spec/active_interaction/integration/float_interaction_spec.rb +0 -5
  46. data/spec/active_interaction/integration/hash_interaction_spec.rb +0 -76
  47. data/spec/active_interaction/integration/integer_interaction_spec.rb +0 -5
  48. data/spec/active_interaction/integration/interface_interaction_spec.rb +0 -19
  49. data/spec/active_interaction/integration/object_interaction_spec.rb +0 -14
  50. data/spec/active_interaction/integration/record_integration_spec.rb +0 -5
  51. data/spec/active_interaction/integration/string_interaction_spec.rb +0 -5
  52. data/spec/active_interaction/integration/symbol_interaction_spec.rb +0 -5
  53. data/spec/active_interaction/integration/time_interaction_spec.rb +0 -88
  54. data/spec/active_interaction/modules/validation_spec.rb +0 -57
  55. data/spec/spec_helper.rb +0 -20
  56. data/spec/support/concerns.rb +0 -13
  57. data/spec/support/filters.rb +0 -227
  58. data/spec/support/interactions.rb +0 -124
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b90b2dc28188b224ed0aa986afb739056dbd2407061da2dfee81b825c5674ca9
4
- data.tar.gz: 755707a0f9554cee89a08567245f3d78d597a8b7ae7ec671c3eb572f4dd5a881
3
+ metadata.gz: f39aaac6de9ca228f9a223ef78ce39b17f7b934ac161e66067993b33968851c6
4
+ data.tar.gz: 9b16a1f1e0e0ecacb542709b103db93a79c9995a7cc90c5cff89d619ffcad204
5
5
  SHA512:
6
- metadata.gz: d24433ef35282b38531e2e18c1e426f69f9cc71692fdb2d96e21f3c420b56a6bb42c3f473b255890b457ab3d1764d6b132ec7f30260437d732ced70b083d217a
7
- data.tar.gz: dd2ce32a0c59afa9f5fe1a8134aa82e98404b1e0d5a3a3801b8dd7a726f75f28d16de46c72687c3e5f807db0576936e0a34abe3b26201dd2c58c90c798df10d5
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
  [![Version](https://img.shields.io/gem/v/active_interaction.svg?style=flat-square)](https://rubygems.org/gems/active_interaction)
7
- [![Test](https://img.shields.io/github/workflow/status/AaronLasseigne/active_interaction/Test?label=Test&style=flat-square)](https://github.com/AaronLasseigne/active_interaction/actions?query=workflow%3ATest)
8
-
9
- ---
10
-
11
- ActiveInteraction gives you a place to put your business logic. It also helps
12
- you write safer code by validating that your inputs conform to your
13
- expectations. If ActiveModel deals with your nouns, then ActiveInteraction
14
- handles your verbs.
9
+ [![Test](https://img.shields.io/github/actions/workflow/status/AaronLasseigne/active_interaction/test.yml?label=Test&style=flat-square&branch=main)](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.2'
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.2'
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,
@@ -147,6 +147,8 @@ module ActiveInteraction
147
147
 
148
148
  attr_accessor attribute
149
149
 
150
+ alias_method "#{attribute}?", attribute if filter.is_a?(BooleanFilter)
151
+
150
152
  eagerly_evaluate_default(filter)
151
153
  end
152
154
 
@@ -11,7 +11,15 @@ module ActiveInteraction
11
11
  #
12
12
  # @return [Errors]
13
13
  def merge!(other)
14
- merge_details!(other)
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
- def merge_details!(other)
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.merge(message: message)) unless added?(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
@@ -4,5 +4,5 @@ module ActiveInteraction
4
4
  # The version number.
5
5
  #
6
6
  # @return [Gem::Version]
7
- VERSION = Gem::Version.new('5.2.0')
7
+ VERSION = Gem::Version.new('5.4.0')
8
8
  end
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.2.0
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: 2022-10-22 00:00:00.000000000 Z
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: '8'
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: '8'
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: '8'
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: '8'
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.26.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.26.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.9.0
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.9.0
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.3.7
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