active_interaction 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/active_interaction/base.rb +1 -1
- data/lib/active_interaction/errors.rb +10 -2
- data/lib/active_interaction/filter.rb +1 -1
- data/lib/active_interaction/filters/abstract_date_time_filter.rb +1 -1
- data/lib/active_interaction/filters/abstract_numeric_filter.rb +1 -1
- data/lib/active_interaction/filters/time_filter.rb +1 -1
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +12 -11
- data/spec/active_interaction/concerns/runnable_spec.rb +1 -1
- data/spec/active_interaction/errors_spec.rb +20 -5
- data/spec/active_interaction/filters/date_filter_spec.rb +5 -7
- data/spec/active_interaction/filters/date_time_filter_spec.rb +8 -10
- data/spec/active_interaction/filters/decimal_filter_spec.rb +1 -1
- data/spec/active_interaction/filters/hash_filter_spec.rb +2 -2
- data/spec/active_interaction/filters/object_filter_spec.rb +4 -4
- data/spec/active_interaction/filters/string_filter_spec.rb +1 -1
- data/spec/active_interaction/filters/time_filter_spec.rb +8 -10
- data/spec/active_interaction/integration/array_interaction_spec.rb +1 -1
- data/spec/active_interaction/integration/hash_interaction_spec.rb +1 -1
- data/spec/active_interaction/integration/time_interaction_spec.rb +2 -1
- data/spec/support/filters.rb +4 -4
- data/spec/support/interactions.rb +4 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 570d5eae8a7122f5acf5ea497d191574073c80d1
|
4
|
+
data.tar.gz: f5a66f3defbfd2cee1dabf0a60f7d4799544b043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af716412dbce18461deb2ff8a15878511c683ef9fc3bc499b027788ecba3d98ada05ed09ab615a0ec8adcfbcd61a39c57cd119a3095c26c3a0760891d9d74bd
|
7
|
+
data.tar.gz: 2911bf4456d0724b48804e4176ed96fcf40361b7dba671dfa7450f3a24180e3188a1509d4ffdeb8e41ed40e8895e80a4d2c5f96ce37651a14d208345c457ad82
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# [3.0.1][] (2016-01-15)
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- [#349][]: Merging errors on `:base` with a message that was a `String` attempted to translate it.
|
6
|
+
|
1
7
|
# [3.0.0][] (2016-01-13)
|
2
8
|
|
3
9
|
## Changed
|
@@ -504,6 +510,7 @@ For help upgrading to version 2, please read [the announcement post][].
|
|
504
510
|
|
505
511
|
- Initial release.
|
506
512
|
|
513
|
+
[3.0.1]: https://github.com/orgsync/active_interaction/compare/v3.0.0...v3.0.1
|
507
514
|
[3.0.0]: https://github.com/orgsync/active_interaction/compare/v2.2.0...v3.0.0
|
508
515
|
[2.2.0]: https://github.com/orgsync/active_interaction/compare/v2.1.5...v2.2.0
|
509
516
|
[2.1.5]: https://github.com/orgsync/active_interaction/compare/v2.1.4...v2.1.5
|
@@ -660,5 +667,6 @@ For help upgrading to version 2, please read [the announcement post][].
|
|
660
667
|
[#336]: https://github.com/orgsync/active_interaction/pull/336
|
661
668
|
[#344]: https://github.com/orgsync/active_interaction/pull/344
|
662
669
|
[#346]: https://github.com/orgsync/active_interaction/pull/346
|
670
|
+
[#349]: https://github.com/orgsync/active_interaction/pull/349
|
663
671
|
|
664
672
|
[the announcement post]: http://devblog.orgsync.com/2015/05/06/announcing-active-interaction-2/
|
@@ -254,7 +254,7 @@ module ActiveInteraction
|
|
254
254
|
begin
|
255
255
|
public_send("#{name}=", filter.clean(inputs[name], self))
|
256
256
|
rescue InvalidValueError, MissingValueError, NoDefaultError
|
257
|
-
# #type_check will add errors if appropriate.
|
257
|
+
nil # #type_check will add errors if appropriate.
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
@@ -121,8 +121,8 @@ module ActiveInteraction
|
|
121
121
|
if attribute?(attribute)
|
122
122
|
add(attribute, error, detail) unless added?(attribute, error, detail)
|
123
123
|
else
|
124
|
-
|
125
|
-
|
124
|
+
translated_error = translate(other, attribute, error)
|
125
|
+
message = full_message(attribute, translated_error)
|
126
126
|
attribute = :base
|
127
127
|
add(attribute, message) unless added?(attribute, message)
|
128
128
|
end
|
@@ -131,5 +131,13 @@ module ActiveInteraction
|
|
131
131
|
def attribute?(attribute)
|
132
132
|
@base.respond_to?(attribute)
|
133
133
|
end
|
134
|
+
|
135
|
+
def translate(other, attribute, error)
|
136
|
+
if error.is_a?(Symbol)
|
137
|
+
other.generate_message(attribute, error)
|
138
|
+
else
|
139
|
+
error
|
140
|
+
end
|
141
|
+
end
|
134
142
|
end
|
135
143
|
end
|
@@ -14,7 +14,7 @@ module ActiveInteraction
|
|
14
14
|
# Describes an input filter for an interaction.
|
15
15
|
class Filter
|
16
16
|
# @return [Hash{Symbol => Class}]
|
17
|
-
CLASSES = {}
|
17
|
+
CLASSES = {} # rubocop:disable Style/MutableConstant
|
18
18
|
private_constant :CLASSES
|
19
19
|
|
20
20
|
# @return [Hash{Symbol => Filter}]
|
@@ -36,7 +36,7 @@ describe ActiveInteraction::Base do
|
|
36
36
|
describe '.new(inputs = {})' do
|
37
37
|
it 'does not allow :_interaction_* as an option' do
|
38
38
|
key = :"_interaction_#{SecureRandom.hex}"
|
39
|
-
inputs
|
39
|
+
inputs[key] = nil
|
40
40
|
expect do
|
41
41
|
interaction
|
42
42
|
end.to raise_error ActiveInteraction::InvalidValueError
|
@@ -44,7 +44,7 @@ describe ActiveInteraction::Base do
|
|
44
44
|
|
45
45
|
it 'does not allow "_interaction_*" as an option' do
|
46
46
|
key = "_interaction_#{SecureRandom.hex}"
|
47
|
-
inputs
|
47
|
+
inputs[key] = nil
|
48
48
|
expect do
|
49
49
|
interaction
|
50
50
|
end.to raise_error ActiveInteraction::InvalidValueError
|
@@ -75,7 +75,7 @@ describe ActiveInteraction::Base do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
context 'passing' do
|
78
|
-
before { inputs
|
78
|
+
before { inputs[:thing] = SecureRandom.hex }
|
79
79
|
|
80
80
|
it 'returns a valid outcome' do
|
81
81
|
expect(interaction).to be_valid
|
@@ -85,7 +85,7 @@ describe ActiveInteraction::Base do
|
|
85
85
|
|
86
86
|
context 'with a single input' do
|
87
87
|
let(:thing) { SecureRandom.hex }
|
88
|
-
before { inputs
|
88
|
+
before { inputs[:thing] = thing }
|
89
89
|
|
90
90
|
it 'sets the attribute' do
|
91
91
|
expect(interaction.thing).to eql thing
|
@@ -98,7 +98,7 @@ describe ActiveInteraction::Base do
|
|
98
98
|
|
99
99
|
context 'validation' do
|
100
100
|
context 'failing' do
|
101
|
-
before { inputs
|
101
|
+
before { inputs[:thing] = thing }
|
102
102
|
|
103
103
|
context 'with an invalid value' do
|
104
104
|
let(:thing) { 'a' }
|
@@ -118,7 +118,7 @@ describe ActiveInteraction::Base do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
context 'passing' do
|
121
|
-
before { inputs
|
121
|
+
before { inputs[:thing] = 1 }
|
122
122
|
|
123
123
|
it 'returns a valid outcome' do
|
124
124
|
expect(interaction).to be_valid
|
@@ -127,7 +127,7 @@ describe ActiveInteraction::Base do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
context 'with a single input' do
|
130
|
-
before { inputs
|
130
|
+
before { inputs[:thing] = 1 }
|
131
131
|
|
132
132
|
it 'sets the attribute to the filtered value' do
|
133
133
|
expect(interaction.thing).to eql 1.0
|
@@ -248,7 +248,7 @@ describe ActiveInteraction::Base do
|
|
248
248
|
end
|
249
249
|
|
250
250
|
context 'passing validations' do
|
251
|
-
before { inputs
|
251
|
+
before { inputs[:thing] = thing }
|
252
252
|
|
253
253
|
context 'failing runtime validations' do
|
254
254
|
before do
|
@@ -311,7 +311,7 @@ describe ActiveInteraction::Base do
|
|
311
311
|
end
|
312
312
|
|
313
313
|
context 'passing validations' do
|
314
|
-
before { inputs
|
314
|
+
before { inputs[:thing] = thing }
|
315
315
|
|
316
316
|
it 'returns the result' do
|
317
317
|
expect(result[:thing]).to eql thing
|
@@ -341,7 +341,8 @@ describe ActiveInteraction::Base do
|
|
341
341
|
|
342
342
|
context 'with valid composition' do
|
343
343
|
before do
|
344
|
-
inputs
|
344
|
+
inputs[:x] = x
|
345
|
+
inputs[:z] = z
|
345
346
|
end
|
346
347
|
|
347
348
|
it 'is valid' do
|
@@ -485,7 +486,7 @@ describe ActiveInteraction::Base do
|
|
485
486
|
let(:thing) { rand }
|
486
487
|
|
487
488
|
before do
|
488
|
-
inputs
|
489
|
+
inputs[:thing] = thing
|
489
490
|
end
|
490
491
|
|
491
492
|
it 'returns true' do
|
@@ -57,13 +57,28 @@ describe ActiveInteraction::Errors do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'with a detailed error' do
|
60
|
-
|
61
|
-
|
60
|
+
context 'that is a symbol' do
|
61
|
+
before do
|
62
|
+
other.add(:attribute)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'adds the error' do
|
66
|
+
errors.merge!(other)
|
67
|
+
expect(errors.details[:attribute]).to eql [{ error: :invalid }]
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
|
-
|
65
|
-
|
66
|
-
|
71
|
+
context 'that is a string' do
|
72
|
+
let(:message) { SecureRandom.hex }
|
73
|
+
|
74
|
+
before do
|
75
|
+
other.add(:base, message)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'adds the error' do
|
79
|
+
errors.merge!(other)
|
80
|
+
expect(errors.details[:base]).to eql [{ error: message }]
|
81
|
+
end
|
67
82
|
end
|
68
83
|
end
|
69
84
|
|
@@ -10,7 +10,7 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
10
10
|
let(:format) { '%d/%m/%Y' }
|
11
11
|
|
12
12
|
before do
|
13
|
-
options
|
13
|
+
options[:format] = format
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -116,12 +116,10 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
116
116
|
describe '#default' do
|
117
117
|
context 'with a GroupedInput' do
|
118
118
|
before do
|
119
|
-
options.
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
'3' => '2'
|
124
|
-
)
|
119
|
+
options[:default] = ActiveInteraction::GroupedInput.new(
|
120
|
+
'1' => '2012',
|
121
|
+
'2' => '1',
|
122
|
+
'3' => '2'
|
125
123
|
)
|
126
124
|
end
|
127
125
|
|
@@ -10,7 +10,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
10
10
|
let(:format) { '%d/%m/%Y %H:%M:%S %:z' }
|
11
11
|
|
12
12
|
before do
|
13
|
-
options
|
13
|
+
options[:format] = format
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -124,15 +124,13 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
124
124
|
describe '#default' do
|
125
125
|
context 'with a GroupedInput' do
|
126
126
|
before do
|
127
|
-
options.
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
'6' => '5'
|
135
|
-
)
|
127
|
+
options[:default] = ActiveInteraction::GroupedInput.new(
|
128
|
+
'1' => '2012',
|
129
|
+
'2' => '1',
|
130
|
+
'3' => '2',
|
131
|
+
'4' => '3',
|
132
|
+
'5' => '4',
|
133
|
+
'6' => '5'
|
136
134
|
)
|
137
135
|
end
|
138
136
|
|
@@ -80,7 +80,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
80
80
|
describe '#default' do
|
81
81
|
context 'with a Hash' do
|
82
82
|
before do
|
83
|
-
options
|
83
|
+
options[:default] = {}
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'returns the Hash' do
|
@@ -90,7 +90,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
90
90
|
|
91
91
|
context 'with a non-empty Hash' do
|
92
92
|
before do
|
93
|
-
options
|
93
|
+
options[:default] = { a: {} }
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'raises an error' do
|
@@ -10,7 +10,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
|
|
10
10
|
it_behaves_like 'a filter'
|
11
11
|
|
12
12
|
before do
|
13
|
-
options
|
13
|
+
options[:class] = Thing
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#cast' do
|
@@ -101,7 +101,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
|
|
101
101
|
|
102
102
|
context 'with class as a superclass' do
|
103
103
|
before do
|
104
|
-
options
|
104
|
+
options[:class] = Thing.superclass
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'returns the instance' do
|
@@ -111,7 +111,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
|
|
111
111
|
|
112
112
|
context 'with class as a String' do
|
113
113
|
before do
|
114
|
-
options
|
114
|
+
options[:class] = Thing.name
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'returns the instance' do
|
@@ -131,7 +131,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
|
|
131
131
|
|
132
132
|
context 'with class as an invalid String' do
|
133
133
|
before do
|
134
|
-
options
|
134
|
+
options[:class] = 'invalid'
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'raises an error' do
|
@@ -10,7 +10,7 @@ describe ActiveInteraction::TimeFilter, :filter do
|
|
10
10
|
let(:format) { '%d/%m/%Y %H:%M:%S %z' }
|
11
11
|
|
12
12
|
before do
|
13
|
-
options
|
13
|
+
options[:format] = format
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -146,15 +146,13 @@ describe ActiveInteraction::TimeFilter, :filter do
|
|
146
146
|
describe '#default' do
|
147
147
|
context 'with a GroupedInput' do
|
148
148
|
before do
|
149
|
-
options.
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
'6' => '5'
|
157
|
-
)
|
149
|
+
options[:default] = ActiveInteraction::GroupedInput.new(
|
150
|
+
'1' => '2012',
|
151
|
+
'2' => '1',
|
152
|
+
'3' => '2',
|
153
|
+
'4' => '3',
|
154
|
+
'5' => '4',
|
155
|
+
'6' => '5'
|
158
156
|
)
|
159
157
|
end
|
160
158
|
|
@@ -10,6 +10,7 @@ TimeZone = Class.new do
|
|
10
10
|
def self.parse(*args)
|
11
11
|
TimeWithZone.new(Time.parse(*args))
|
12
12
|
rescue ArgumentError
|
13
|
+
nil
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -37,7 +38,7 @@ describe TimeInteraction do
|
|
37
38
|
let(:a) { nil }
|
38
39
|
|
39
40
|
before do
|
40
|
-
inputs
|
41
|
+
inputs[:a] = a
|
41
42
|
|
42
43
|
allow(Time).to receive(:zone).and_return(TimeZone)
|
43
44
|
end
|
data/spec/support/filters.rb
CHANGED
@@ -9,7 +9,7 @@ shared_context 'filters' do
|
|
9
9
|
|
10
10
|
shared_context 'optional' do
|
11
11
|
before do
|
12
|
-
options
|
12
|
+
options[:default] = nil
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -112,7 +112,7 @@ shared_examples_for 'a filter' do
|
|
112
112
|
|
113
113
|
context 'with an invalid default' do
|
114
114
|
before do
|
115
|
-
options
|
115
|
+
options[:default] = Object.new
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'raises an error' do
|
@@ -144,7 +144,7 @@ shared_examples_for 'a filter' do
|
|
144
144
|
|
145
145
|
context 'with an invalid default' do
|
146
146
|
before do
|
147
|
-
options
|
147
|
+
options[:default] = Object.new
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'raises an error' do
|
@@ -177,7 +177,7 @@ shared_examples_for 'a filter' do
|
|
177
177
|
let(:desc) { SecureRandom.hex }
|
178
178
|
|
179
179
|
before do
|
180
|
-
options
|
180
|
+
options[:desc] = desc
|
181
181
|
end
|
182
182
|
|
183
183
|
it 'returns the description' do
|
@@ -54,7 +54,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
54
54
|
context 'with inputs[:required]' do
|
55
55
|
let(:required) { generator.call }
|
56
56
|
|
57
|
-
before { inputs
|
57
|
+
before { inputs[:required] = required }
|
58
58
|
|
59
59
|
it 'is valid' do
|
60
60
|
expect(outcome).to be_valid
|
@@ -73,7 +73,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'does not return nil for :default when given nil' do
|
76
|
-
inputs
|
76
|
+
inputs[:default] = nil
|
77
77
|
expect(result[:default]).to_not be_nil
|
78
78
|
end
|
79
79
|
|
@@ -92,7 +92,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
92
92
|
context 'with inputs[:optional]' do
|
93
93
|
let(:optional) { generator.call }
|
94
94
|
|
95
|
-
before { inputs
|
95
|
+
before { inputs[:optional] = optional }
|
96
96
|
|
97
97
|
it 'returns the correct value for :optional' do
|
98
98
|
expect(result[:optional]).to eql optional
|
@@ -102,7 +102,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
102
102
|
context 'with inputs[:default]' do
|
103
103
|
let(:default) { generator.call }
|
104
104
|
|
105
|
-
before { inputs
|
105
|
+
before { inputs[:default] = default }
|
106
106
|
|
107
107
|
it 'returns the correct value for :default' do
|
108
108
|
expect(result[:default]).to eql default
|
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: 3.0.
|
4
|
+
version: 3.0.1
|
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: 2016-01-
|
12
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -163,14 +163,14 @@ dependencies:
|
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 0.36.0
|
167
167
|
type: :development
|
168
168
|
prerelease: false
|
169
169
|
version_requirements: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 0.36.0
|
174
174
|
- !ruby/object:Gem::Dependency
|
175
175
|
name: yard
|
176
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -300,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
300
300
|
version: '0'
|
301
301
|
requirements: []
|
302
302
|
rubyforge_project:
|
303
|
-
rubygems_version: 2.
|
303
|
+
rubygems_version: 2.5.1
|
304
304
|
signing_key:
|
305
305
|
specification_version: 4
|
306
306
|
summary: Manage application specific business logic.
|