active_interaction 4.1.0 → 5.1.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 +150 -1
- data/CONTRIBUTING.md +11 -3
- data/README.md +256 -215
- data/lib/active_interaction/array_input.rb +77 -0
- data/lib/active_interaction/base.rb +14 -98
- data/lib/active_interaction/concerns/active_recordable.rb +3 -3
- data/lib/active_interaction/concerns/missable.rb +2 -2
- data/lib/active_interaction/errors.rb +6 -88
- data/lib/active_interaction/exceptions.rb +47 -0
- data/lib/active_interaction/filter/column.rb +59 -0
- data/lib/active_interaction/filter/error.rb +40 -0
- data/lib/active_interaction/filter.rb +40 -52
- data/lib/active_interaction/filters/abstract_date_time_filter.rb +9 -6
- data/lib/active_interaction/filters/abstract_numeric_filter.rb +7 -3
- data/lib/active_interaction/filters/array_filter.rb +40 -6
- data/lib/active_interaction/filters/boolean_filter.rb +4 -3
- data/lib/active_interaction/filters/date_filter.rb +1 -1
- data/lib/active_interaction/filters/date_time_filter.rb +1 -1
- data/lib/active_interaction/filters/decimal_filter.rb +1 -1
- data/lib/active_interaction/filters/float_filter.rb +1 -1
- data/lib/active_interaction/filters/hash_filter.rb +23 -15
- data/lib/active_interaction/filters/integer_filter.rb +1 -1
- data/lib/active_interaction/filters/interface_filter.rb +12 -12
- data/lib/active_interaction/filters/object_filter.rb +9 -3
- data/lib/active_interaction/filters/record_filter.rb +21 -11
- data/lib/active_interaction/filters/string_filter.rb +1 -1
- data/lib/active_interaction/filters/symbol_filter.rb +1 -1
- data/lib/active_interaction/filters/time_filter.rb +4 -4
- data/lib/active_interaction/hash_input.rb +43 -0
- data/lib/active_interaction/input.rb +23 -0
- data/lib/active_interaction/inputs.rb +161 -46
- data/lib/active_interaction/locale/en.yml +0 -1
- data/lib/active_interaction/locale/fr.yml +0 -1
- data/lib/active_interaction/locale/it.yml +0 -1
- data/lib/active_interaction/locale/ja.yml +0 -1
- data/lib/active_interaction/locale/pt-BR.yml +0 -1
- data/lib/active_interaction/modules/validation.rb +6 -17
- data/lib/active_interaction/version.rb +1 -1
- data/lib/active_interaction.rb +41 -36
- data/spec/active_interaction/array_input_spec.rb +166 -0
- data/spec/active_interaction/base_spec.rb +34 -248
- data/spec/active_interaction/concerns/active_modelable_spec.rb +3 -3
- data/spec/active_interaction/concerns/active_recordable_spec.rb +7 -7
- data/spec/active_interaction/concerns/hashable_spec.rb +8 -8
- data/spec/active_interaction/concerns/missable_spec.rb +9 -9
- data/spec/active_interaction/concerns/runnable_spec.rb +34 -32
- data/spec/active_interaction/errors_spec.rb +60 -43
- data/spec/active_interaction/{filter_column_spec.rb → filter/column_spec.rb} +3 -10
- data/spec/active_interaction/filter_spec.rb +27 -6
- data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +2 -2
- data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +2 -2
- data/spec/active_interaction/filters/array_filter_spec.rb +109 -16
- data/spec/active_interaction/filters/boolean_filter_spec.rb +12 -11
- data/spec/active_interaction/filters/date_filter_spec.rb +32 -27
- data/spec/active_interaction/filters/date_time_filter_spec.rb +34 -29
- data/spec/active_interaction/filters/decimal_filter_spec.rb +20 -18
- data/spec/active_interaction/filters/file_filter_spec.rb +7 -7
- data/spec/active_interaction/filters/float_filter_spec.rb +19 -17
- data/spec/active_interaction/filters/hash_filter_spec.rb +16 -18
- data/spec/active_interaction/filters/integer_filter_spec.rb +24 -22
- data/spec/active_interaction/filters/interface_filter_spec.rb +105 -82
- data/spec/active_interaction/filters/object_filter_spec.rb +52 -36
- data/spec/active_interaction/filters/record_filter_spec.rb +61 -39
- data/spec/active_interaction/filters/string_filter_spec.rb +7 -7
- data/spec/active_interaction/filters/symbol_filter_spec.rb +6 -6
- data/spec/active_interaction/filters/time_filter_spec.rb +57 -34
- data/spec/active_interaction/hash_input_spec.rb +58 -0
- data/spec/active_interaction/i18n_spec.rb +22 -17
- data/spec/active_interaction/inputs_spec.rb +170 -18
- data/spec/active_interaction/integration/array_interaction_spec.rb +3 -7
- data/spec/active_interaction/integration/record_integration_spec.rb +5 -0
- data/spec/active_interaction/modules/validation_spec.rb +8 -31
- data/spec/spec_helper.rb +9 -0
- data/spec/support/concerns.rb +2 -2
- data/spec/support/filters.rb +27 -51
- data/spec/support/interactions.rb +4 -4
- metadata +43 -44
- data/lib/active_interaction/filter_column.rb +0 -57
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveInteraction::Inputs do
|
4
|
-
subject(:inputs) { described_class.new }
|
4
|
+
subject(:inputs) { described_class.new(args, base_class.new) }
|
5
|
+
|
6
|
+
let(:args) { {} }
|
7
|
+
let(:base_class) { ActiveInteraction::Base }
|
5
8
|
|
6
9
|
describe '.reserved?(name)' do
|
7
10
|
it 'returns true for anything starting with "_interaction_"' do
|
8
|
-
expect(described_class.
|
11
|
+
expect(described_class).to be_reserved('_interaction_')
|
9
12
|
end
|
10
13
|
|
11
14
|
it 'returns true for existing instance methods' do
|
@@ -13,21 +16,20 @@ describe ActiveInteraction::Inputs do
|
|
13
16
|
(ActiveInteraction::Base.instance_methods - Object.instance_methods) +
|
14
17
|
(ActiveInteraction::Base.private_instance_methods - Object.private_instance_methods)
|
15
18
|
).each do |method|
|
16
|
-
expect(described_class.
|
19
|
+
expect(described_class).to be_reserved(method)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
it 'returns false for anything else' do
|
21
|
-
expect(described_class.
|
24
|
+
expect(described_class).to_not be_reserved(SecureRandom.hex)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
describe '
|
26
|
-
let(:
|
27
|
-
let(:result) { described_class.process(inputs) }
|
28
|
+
describe '#normalized' do
|
29
|
+
let(:result) { inputs.normalized }
|
28
30
|
|
29
31
|
context 'with invalid inputs' do
|
30
|
-
let(:
|
32
|
+
let(:args) { nil }
|
31
33
|
|
32
34
|
it 'raises an error' do
|
33
35
|
expect { result }.to raise_error ArgumentError
|
@@ -35,23 +37,23 @@ describe ActiveInteraction::Inputs do
|
|
35
37
|
end
|
36
38
|
|
37
39
|
context 'with non-hash inputs' do
|
38
|
-
let(:
|
40
|
+
let(:args) { [%i[k v]] }
|
39
41
|
|
40
42
|
it 'raises an error' do
|
41
43
|
expect { result }.to raise_error ArgumentError
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
context 'with
|
46
|
-
let(:
|
47
|
+
context 'with ActiveInteraction::Inputs inputs' do
|
48
|
+
let(:args) { described_class.new({ key: :value }, base_class.new) }
|
47
49
|
|
48
50
|
it 'does not raise an error' do
|
49
51
|
expect { result }.to_not raise_error
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
context 'with
|
54
|
-
let(:
|
55
|
+
context 'with ActionController::Parameters inputs' do
|
56
|
+
let(:args) { ::ActionController::Parameters.new }
|
55
57
|
|
56
58
|
it 'does not raise an error' do
|
57
59
|
expect { result }.to_not raise_error
|
@@ -59,17 +61,17 @@ describe ActiveInteraction::Inputs do
|
|
59
61
|
end
|
60
62
|
|
61
63
|
context 'with simple inputs' do
|
62
|
-
before {
|
64
|
+
before { args[:key] = :value }
|
63
65
|
|
64
66
|
it 'sends them straight through' do
|
65
|
-
expect(result).to eql
|
67
|
+
expect(result).to eql args
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
71
|
context 'with groupable inputs' do
|
70
72
|
context 'without a matching simple input' do
|
71
73
|
before do
|
72
|
-
|
74
|
+
args.merge!(
|
73
75
|
'key(1i)' => :value1,
|
74
76
|
'key(2i)' => :value2
|
75
77
|
)
|
@@ -87,7 +89,7 @@ describe ActiveInteraction::Inputs do
|
|
87
89
|
|
88
90
|
context 'with a matching simple input' do
|
89
91
|
before do
|
90
|
-
|
92
|
+
args.merge!(
|
91
93
|
'key(1i)' => :value1,
|
92
94
|
key: :value2
|
93
95
|
)
|
@@ -104,11 +106,161 @@ describe ActiveInteraction::Inputs do
|
|
104
106
|
end
|
105
107
|
|
106
108
|
context 'with a reserved name' do
|
107
|
-
before {
|
109
|
+
before { args[:_interaction_key] = :value }
|
108
110
|
|
109
111
|
it 'skips the input' do
|
110
112
|
expect(result).to_not have_key(:_interaction_key)
|
111
113
|
end
|
112
114
|
end
|
113
115
|
end
|
116
|
+
|
117
|
+
describe '#given?' do
|
118
|
+
let(:base_class) do
|
119
|
+
Class.new(ActiveInteraction::Base) do
|
120
|
+
float :x,
|
121
|
+
default: nil
|
122
|
+
|
123
|
+
def execute; end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'is false when the input is not given' do
|
128
|
+
expect(inputs.given?(:x)).to be false
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'is true when the input is nil' do
|
132
|
+
args[:x] = nil
|
133
|
+
expect(inputs.given?(:x)).to be true
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'is true when the input is given' do
|
137
|
+
args[:x] = rand
|
138
|
+
expect(inputs.given?(:x)).to be true
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'symbolizes its argument' do
|
142
|
+
args[:x] = rand
|
143
|
+
expect(inputs.given?('x')).to be true
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'only tracks inputs with filters' do
|
147
|
+
args[:y] = rand
|
148
|
+
expect(inputs.given?(:y)).to be false
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'nested hash values' do
|
152
|
+
let(:base_class) do
|
153
|
+
Class.new(ActiveInteraction::Base) do
|
154
|
+
hash :x, default: {} do
|
155
|
+
boolean :y,
|
156
|
+
default: true
|
157
|
+
end
|
158
|
+
|
159
|
+
def execute; end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'is true when the nested inputs symbols are given' do
|
164
|
+
described_class.class_exec do
|
165
|
+
def execute
|
166
|
+
given?(:x, :y)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
args[:x] = { y: false }
|
171
|
+
expect(inputs.given?(:x, :y)).to be true
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'is true when the nested inputs strings are given' do
|
175
|
+
args['x'] = { 'y' => false }
|
176
|
+
expect(inputs.given?(:x, :y)).to be true
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'is false when the nested input is not given' do
|
180
|
+
args[:x] = {}
|
181
|
+
expect(inputs.given?(:x, :y)).to be false
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'is false when the first input is not given' do
|
185
|
+
expect(inputs.given?(:x, :y)).to be false
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'is false when the first input is nil' do
|
189
|
+
args[:x] = nil
|
190
|
+
expect(inputs.given?(:x, :y)).to be false
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'returns false if you go too far' do
|
194
|
+
args[:x] = { y: true }
|
195
|
+
expect(inputs.given?(:x, :y, :z)).to be false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'nested array values' do
|
200
|
+
let(:base_class) do
|
201
|
+
Class.new(ActiveInteraction::Base) do
|
202
|
+
array :x do
|
203
|
+
hash do
|
204
|
+
boolean :y, default: true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def execute; end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'has a positive index' do
|
213
|
+
it 'returns true if found' do
|
214
|
+
args[:x] = [{ y: true }]
|
215
|
+
expect(inputs.given?(:x, 0, :y)).to be true
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'returns false if not found' do
|
219
|
+
args[:x] = []
|
220
|
+
expect(inputs.given?(:x, 0, :y)).to be false
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'has a negative index' do
|
225
|
+
it 'returns true if found' do
|
226
|
+
args[:x] = [{ y: true }]
|
227
|
+
expect(inputs.given?(:x, -1, :y)).to be true
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'returns false if not found' do
|
231
|
+
args[:x] = []
|
232
|
+
expect(inputs.given?(:x, -1, :y)).to be false
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'returns false if you go too far' do
|
237
|
+
args[:x] = [{}]
|
238
|
+
expect(inputs.given?(:x, 10, :y)).to be false
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context 'multi-part date values' do
|
243
|
+
let(:base_class) do
|
244
|
+
Class.new(ActiveInteraction::Base) do
|
245
|
+
date :thing,
|
246
|
+
default: nil
|
247
|
+
|
248
|
+
def execute; end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'returns true when the input is given' do
|
253
|
+
args.merge!(
|
254
|
+
'thing(1i)' => '2020',
|
255
|
+
'thing(2i)' => '12',
|
256
|
+
'thing(3i)' => '31'
|
257
|
+
)
|
258
|
+
expect(inputs.given?(:thing)).to be true
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'returns false if not found' do
|
262
|
+
expect(inputs.given?(:thing)).to be false
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
114
266
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'active_record'
|
3
|
-
|
4
|
-
require 'activerecord-jdbcsqlite3-adapter'
|
5
|
-
else
|
6
|
-
require 'sqlite3'
|
7
|
-
end
|
3
|
+
require 'sqlite3'
|
8
4
|
|
9
5
|
ActiveRecord::Base.establish_connection(
|
10
6
|
adapter: 'sqlite3',
|
@@ -36,8 +32,8 @@ end
|
|
36
32
|
describe ArrayInteraction do
|
37
33
|
include_context 'interactions'
|
38
34
|
it_behaves_like 'an interaction', :array, -> { [] }
|
39
|
-
it_behaves_like 'an interaction', :array, -> { Element.where('1 = 1') }
|
40
|
-
it_behaves_like 'an interaction', :array, -> { List.create!.elements }
|
35
|
+
it_behaves_like 'an interaction', :array, -> { Element.where('1 = 1') }, ->(result) { result.to_a }
|
36
|
+
it_behaves_like 'an interaction', :array, -> { List.create!.elements }, ->(result) { result.to_a }
|
41
37
|
|
42
38
|
context 'with inputs[:a]' do
|
43
39
|
let(:a) { [[]] }
|
@@ -22,11 +22,11 @@ describe ActiveInteraction::Validation do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context 'filter
|
25
|
+
context 'filter returns no errors' do
|
26
26
|
let(:inputs) { { name: 1 } }
|
27
27
|
|
28
28
|
before do
|
29
|
-
allow(filter).to receive(:
|
29
|
+
allow(filter).to receive(:process).and_return(ActiveInteraction::Input.new(filter, value: 1))
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns no errors' do
|
@@ -34,14 +34,15 @@ describe ActiveInteraction::Validation do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context 'filter
|
37
|
+
context 'filter returns with errors' do
|
38
38
|
before do
|
39
|
-
allow(filter).to receive(:
|
39
|
+
allow(filter).to receive(:process).and_return(ActiveInteraction::Input.new(filter, error: exception))
|
40
40
|
end
|
41
41
|
|
42
|
-
context '
|
43
|
-
let(:
|
44
|
-
|
42
|
+
context 'Filter::Error' do
|
43
|
+
let(:filter) { ActiveInteraction::ArrayFilter.new(:name, [1.0, 'a']) { float } }
|
44
|
+
|
45
|
+
let(:exception) { ActiveInteraction::Filter::Error.new(filter, :invalid_type) }
|
45
46
|
|
46
47
|
it 'returns an :invalid_type error' do
|
47
48
|
type = I18n.translate(
|
@@ -51,30 +52,6 @@ describe ActiveInteraction::Validation do
|
|
51
52
|
expect(result).to eql [[filter.name, :invalid_type, { type: type }]]
|
52
53
|
end
|
53
54
|
end
|
54
|
-
|
55
|
-
context 'MissingValueError' do
|
56
|
-
let(:exception) { ActiveInteraction::MissingValueError }
|
57
|
-
|
58
|
-
it 'returns a :missing error' do
|
59
|
-
expect(result).to eql [[filter.name, :missing]]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'InvalidNestedValueError' do
|
64
|
-
let(:exception) do
|
65
|
-
ActiveInteraction::InvalidNestedValueError.new(name, value)
|
66
|
-
end
|
67
|
-
let(:name) { SecureRandom.hex.to_sym }
|
68
|
-
let(:value) { double }
|
69
|
-
|
70
|
-
it 'returns an :invalid_nested error' do
|
71
|
-
expect(result).to eql [[
|
72
|
-
filter.name,
|
73
|
-
:invalid_nested,
|
74
|
-
{ name: name.inspect, value: value.inspect }
|
75
|
-
]]
|
76
|
-
end
|
77
|
-
end
|
78
55
|
end
|
79
56
|
end
|
80
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,19 @@ require 'i18n'
|
|
2
2
|
I18n.config.enforce_available_locales = true if I18n.config.respond_to?(:enforce_available_locales)
|
3
3
|
|
4
4
|
require 'active_interaction'
|
5
|
+
require 'active_record'
|
5
6
|
|
6
7
|
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
7
8
|
|
8
9
|
RSpec.configure do |config|
|
9
10
|
config.run_all_when_everything_filtered = true
|
10
11
|
config.filter_run_including :focus
|
12
|
+
|
13
|
+
config.before(:suite) do
|
14
|
+
if ActiveRecord.respond_to?(:index_nested_attribute_errors)
|
15
|
+
ActiveRecord.index_nested_attribute_errors = false
|
16
|
+
else
|
17
|
+
ActiveRecord::Base.index_nested_attribute_errors = false
|
18
|
+
end
|
19
|
+
end
|
11
20
|
end
|
data/spec/support/concerns.rb
CHANGED
data/spec/support/filters.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
shared_context 'filters' do
|
2
|
+
subject(:filter) { described_class.new(name, options, &block) }
|
3
|
+
|
2
4
|
let(:block) { nil }
|
3
5
|
let(:name) { SecureRandom.hex.to_sym }
|
4
6
|
let(:options) { {} }
|
5
7
|
|
6
|
-
subject(:filter) { described_class.new(name, options, &block) }
|
7
|
-
|
8
8
|
shared_context 'optional' do
|
9
9
|
before do
|
10
10
|
options[:default] = nil
|
@@ -45,71 +45,35 @@ shared_examples_for 'a filter' do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe '#
|
49
|
-
let(:value) { nil }
|
50
|
-
let(:result) { filter.send(:cast, value, nil) }
|
51
|
-
|
52
|
-
context 'optional' do
|
53
|
-
include_context 'optional'
|
54
|
-
|
55
|
-
it 'returns nil' do
|
56
|
-
expect(result).to be_nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'required' do
|
61
|
-
include_context 'required'
|
62
|
-
|
63
|
-
it 'raises an error' do
|
64
|
-
expect { result }.to raise_error ActiveInteraction::MissingValueError
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'with an invalid default' do
|
68
|
-
let(:value) { Object.new }
|
69
|
-
|
70
|
-
it 'raises an error' do
|
71
|
-
expect { result }.to raise_error ActiveInteraction::InvalidValueError
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# BasicObject is missing a lot of methods
|
77
|
-
context 'with a BasicObject' do
|
78
|
-
let(:value) { BasicObject.new }
|
79
|
-
|
80
|
-
it 'raises an error' do
|
81
|
-
expect { result }.to raise_error ActiveInteraction::InvalidValueError
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#clean' do
|
48
|
+
describe '#process' do
|
87
49
|
let(:value) { nil }
|
88
50
|
|
89
51
|
context 'optional' do
|
90
52
|
include_context 'optional'
|
91
53
|
|
92
54
|
it 'returns the default' do
|
93
|
-
expect(filter.
|
55
|
+
expect(filter.process(value, nil).value).to eql options[:default]
|
94
56
|
end
|
95
57
|
end
|
96
58
|
|
97
59
|
context 'required' do
|
98
60
|
include_context 'required'
|
99
61
|
|
100
|
-
it '
|
101
|
-
|
102
|
-
|
103
|
-
|
62
|
+
it 'indicates an error' do
|
63
|
+
error = filter.process(value, nil).errors.first
|
64
|
+
|
65
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
66
|
+
expect(error.type).to be :missing
|
104
67
|
end
|
105
68
|
|
106
69
|
context 'with an invalid value' do
|
107
70
|
let(:value) { Object.new }
|
108
71
|
|
109
|
-
it '
|
110
|
-
|
111
|
-
|
112
|
-
|
72
|
+
it 'indicates an error' do
|
73
|
+
error = filter.process(value, nil).errors.first
|
74
|
+
|
75
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
76
|
+
expect(error.type).to be :invalid_type
|
113
77
|
end
|
114
78
|
end
|
115
79
|
end
|
@@ -121,10 +85,22 @@ shared_examples_for 'a filter' do
|
|
121
85
|
|
122
86
|
it 'raises an error' do
|
123
87
|
expect do
|
124
|
-
filter.
|
88
|
+
filter.process(value, nil)
|
125
89
|
end.to raise_error ActiveInteraction::InvalidDefaultError
|
126
90
|
end
|
127
91
|
end
|
92
|
+
|
93
|
+
# BasicObject is missing a lot of methods
|
94
|
+
context 'with a BasicObject' do
|
95
|
+
let(:value) { BasicObject.new }
|
96
|
+
|
97
|
+
it 'indicates an error' do
|
98
|
+
error = filter.process(value, nil).errors.first
|
99
|
+
|
100
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
101
|
+
expect(error.type).to be :invalid_type
|
102
|
+
end
|
103
|
+
end
|
128
104
|
end
|
129
105
|
|
130
106
|
describe '#default' do
|
@@ -14,7 +14,7 @@ shared_context 'interactions' do
|
|
14
14
|
let(:result) { outcome.result }
|
15
15
|
end
|
16
16
|
|
17
|
-
shared_examples_for 'an interaction' do |type, generator,
|
17
|
+
shared_examples_for 'an interaction' do |type, generator, adjust_output = nil, **filter_options|
|
18
18
|
include_context 'interactions'
|
19
19
|
|
20
20
|
let(:described_class) do
|
@@ -73,7 +73,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'returns the correct value for :required' do
|
76
|
-
expect(result[:required]).to eql required
|
76
|
+
expect(result[:required]).to eql(adjust_output ? adjust_output.call(required) : required)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'returns nil for :optional' do
|
@@ -107,7 +107,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
107
107
|
before { inputs[:optional] = optional }
|
108
108
|
|
109
109
|
it 'returns the correct value for :optional' do
|
110
|
-
expect(result[:optional]).to eql optional
|
110
|
+
expect(result[:optional]).to eql(adjust_output ? adjust_output.call(optional) : optional)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -117,7 +117,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
117
117
|
before { inputs[:default] = default }
|
118
118
|
|
119
119
|
it 'returns the correct value for :default' do
|
120
|
-
expect(result[:default]).to eql default
|
120
|
+
expect(result[:default]).to eql(adjust_output ? adjust_output.call(default) : default)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|