active_interaction 3.8.3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +157 -0
- data/README.md +93 -107
- data/lib/active_interaction.rb +1 -7
- data/lib/active_interaction/base.rb +23 -26
- data/lib/active_interaction/concerns/active_modelable.rb +1 -3
- data/lib/active_interaction/concerns/active_recordable.rb +1 -6
- data/lib/active_interaction/concerns/hashable.rb +0 -1
- data/lib/active_interaction/concerns/missable.rb +0 -1
- data/lib/active_interaction/concerns/runnable.rb +6 -12
- data/lib/active_interaction/errors.rb +3 -6
- data/lib/active_interaction/filter.rb +51 -37
- data/lib/active_interaction/filter_column.rb +0 -3
- data/lib/active_interaction/filters/abstract_date_time_filter.rb +34 -36
- data/lib/active_interaction/filters/abstract_numeric_filter.rb +27 -17
- data/lib/active_interaction/filters/array_filter.rb +57 -36
- data/lib/active_interaction/filters/boolean_filter.rb +26 -12
- data/lib/active_interaction/filters/date_filter.rb +1 -2
- data/lib/active_interaction/filters/date_time_filter.rb +1 -2
- data/lib/active_interaction/filters/decimal_filter.rb +10 -28
- data/lib/active_interaction/filters/file_filter.rb +6 -5
- data/lib/active_interaction/filters/float_filter.rb +1 -2
- data/lib/active_interaction/filters/hash_filter.rb +37 -27
- data/lib/active_interaction/filters/integer_filter.rb +7 -8
- data/lib/active_interaction/filters/interface_filter.rb +48 -14
- data/lib/active_interaction/filters/object_filter.rb +23 -50
- data/lib/active_interaction/filters/record_filter.rb +10 -35
- data/lib/active_interaction/filters/string_filter.rb +21 -12
- data/lib/active_interaction/filters/symbol_filter.rb +13 -7
- data/lib/active_interaction/filters/time_filter.rb +19 -22
- data/lib/active_interaction/grouped_input.rb +0 -3
- data/lib/active_interaction/inputs.rb +89 -0
- data/lib/active_interaction/modules/input_processor.rb +1 -4
- data/lib/active_interaction/modules/validation.rb +9 -12
- data/lib/active_interaction/version.rb +1 -3
- data/spec/active_interaction/base_spec.rb +13 -41
- data/spec/active_interaction/concerns/active_modelable_spec.rb +0 -2
- data/spec/active_interaction/concerns/active_recordable_spec.rb +0 -2
- data/spec/active_interaction/concerns/hashable_spec.rb +1 -3
- data/spec/active_interaction/concerns/missable_spec.rb +0 -2
- data/spec/active_interaction/concerns/runnable_spec.rb +9 -13
- data/spec/active_interaction/errors_spec.rb +4 -25
- data/spec/active_interaction/filter_column_spec.rb +0 -2
- data/spec/active_interaction/filter_spec.rb +0 -2
- data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +1 -3
- data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +1 -3
- data/spec/active_interaction/filters/array_filter_spec.rb +41 -15
- data/spec/active_interaction/filters/boolean_filter_spec.rb +58 -4
- data/spec/active_interaction/filters/date_filter_spec.rb +43 -3
- data/spec/active_interaction/filters/date_time_filter_spec.rb +43 -3
- data/spec/active_interaction/filters/decimal_filter_spec.rb +57 -3
- data/spec/active_interaction/filters/file_filter_spec.rb +1 -3
- data/spec/active_interaction/filters/float_filter_spec.rb +60 -4
- data/spec/active_interaction/filters/hash_filter_spec.rb +19 -9
- data/spec/active_interaction/filters/integer_filter_spec.rb +49 -7
- data/spec/active_interaction/filters/interface_filter_spec.rb +397 -24
- data/spec/active_interaction/filters/object_filter_spec.rb +23 -59
- data/spec/active_interaction/filters/record_filter_spec.rb +23 -49
- data/spec/active_interaction/filters/string_filter_spec.rb +15 -3
- data/spec/active_interaction/filters/symbol_filter_spec.rb +15 -3
- data/spec/active_interaction/filters/time_filter_spec.rb +65 -3
- data/spec/active_interaction/grouped_input_spec.rb +0 -2
- data/spec/active_interaction/i18n_spec.rb +3 -7
- data/spec/active_interaction/{modules/input_processor_spec.rb → inputs_spec.rb} +3 -5
- data/spec/active_interaction/integration/array_interaction_spec.rb +18 -22
- data/spec/active_interaction/integration/boolean_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/date_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/date_time_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/file_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/float_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/hash_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/integer_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/interface_interaction_spec.rb +1 -3
- data/spec/active_interaction/integration/object_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/string_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/symbol_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/time_interaction_spec.rb +14 -18
- data/spec/active_interaction/modules/validation_spec.rb +1 -3
- data/spec/spec_helper.rb +2 -6
- data/spec/support/concerns.rb +0 -2
- data/spec/support/filters.rb +13 -9
- data/spec/support/interactions.rb +22 -14
- metadata +77 -52
- data/lib/active_interaction/backports.rb +0 -59
- data/lib/active_interaction/filters/abstract_filter.rb +0 -19
- data/spec/active_interaction/filters/abstract_filter_spec.rb +0 -8
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ActiveInteraction::FileFilter, :filter do
|
@@ -7,7 +5,7 @@ describe ActiveInteraction::FileFilter, :filter do
|
|
7
5
|
it_behaves_like 'a filter'
|
8
6
|
|
9
7
|
describe '#cast' do
|
10
|
-
let(:result) { filter.cast
|
8
|
+
let(:result) { filter.send(:cast, value, nil) }
|
11
9
|
|
12
10
|
context 'with a File' do
|
13
11
|
let(:value) { File.new(__FILE__) }
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'bigdecimal'
|
3
2
|
require 'spec_helper'
|
4
3
|
|
5
4
|
describe ActiveInteraction::FloatFilter, :filter do
|
@@ -7,7 +6,7 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
7
6
|
it_behaves_like 'a filter'
|
8
7
|
|
9
8
|
describe '#cast' do
|
10
|
-
let(:result) { filter.cast
|
9
|
+
let(:result) { filter.send(:cast, value, nil) }
|
11
10
|
|
12
11
|
context 'with a Float' do
|
13
12
|
let(:value) { rand }
|
@@ -17,8 +16,22 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
19
|
+
context 'with an implicit Integer' do
|
20
|
+
let(:value) do
|
21
|
+
Class.new do
|
22
|
+
def to_int
|
23
|
+
@to_int ||= rand(1 << 16)
|
24
|
+
end
|
25
|
+
end.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns a Float' do
|
29
|
+
expect(result).to eql value.to_int.to_f
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
20
33
|
context 'with a Numeric' do
|
21
|
-
let(:value) {
|
34
|
+
let(:value) { BigDecimal('1.2') }
|
22
35
|
|
23
36
|
it 'returns a Float' do
|
24
37
|
expect(result).to eql value.to_f
|
@@ -42,6 +55,49 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
42
55
|
end.to raise_error ActiveInteraction::InvalidValueError
|
43
56
|
end
|
44
57
|
end
|
58
|
+
|
59
|
+
context 'with an implicit String' do
|
60
|
+
let(:value) do
|
61
|
+
Class.new do
|
62
|
+
def to_str
|
63
|
+
'1.1'
|
64
|
+
end
|
65
|
+
end.new
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns a Float' do
|
69
|
+
# apparently `Float()` doesn't do this even though `Integer()` does
|
70
|
+
expect(result).to eql Float(value.to_str)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with a blank String' do
|
75
|
+
let(:value) do
|
76
|
+
Class.new do
|
77
|
+
def to_str
|
78
|
+
' '
|
79
|
+
end
|
80
|
+
end.new
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'optional' do
|
84
|
+
include_context 'optional'
|
85
|
+
|
86
|
+
it 'returns the default' do
|
87
|
+
expect(result).to eql options[:default]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'required' do
|
92
|
+
include_context 'required'
|
93
|
+
|
94
|
+
it 'raises an error' do
|
95
|
+
expect do
|
96
|
+
result
|
97
|
+
end.to raise_error ActiveInteraction::MissingValueError
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
45
101
|
end
|
46
102
|
|
47
103
|
describe '#database_column_type' do
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ActiveInteraction::HashFilter, :filter do
|
@@ -15,7 +13,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
15
13
|
end
|
16
14
|
|
17
15
|
describe '#cast' do
|
18
|
-
let(:result) { filter.cast
|
16
|
+
let(:result) { filter.send(:cast, value, nil) }
|
19
17
|
|
20
18
|
context 'with a Hash' do
|
21
19
|
let(:value) { {} }
|
@@ -25,6 +23,20 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
26
|
+
context 'with an implicit Hash' do
|
27
|
+
let(:value) do
|
28
|
+
Class.new do
|
29
|
+
def to_hash
|
30
|
+
{}
|
31
|
+
end
|
32
|
+
end.new
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the Hash' do
|
36
|
+
expect(result).to eql value.to_hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
28
40
|
context 'with a non-empty Hash' do
|
29
41
|
let(:value) { { a: {} } }
|
30
42
|
|
@@ -66,12 +78,10 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
66
78
|
end
|
67
79
|
|
68
80
|
it 'populates the error' do
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
expect(e.input_value).to eql v
|
74
|
-
end
|
81
|
+
result
|
82
|
+
rescue ActiveInteraction::InvalidNestedValueError => e
|
83
|
+
expect(e.filter_name).to eql k
|
84
|
+
expect(e.input_value).to eql v
|
75
85
|
end
|
76
86
|
end
|
77
87
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ActiveInteraction::IntegerFilter, :filter do
|
@@ -7,7 +5,7 @@ describe ActiveInteraction::IntegerFilter, :filter do
|
|
7
5
|
it_behaves_like 'a filter'
|
8
6
|
|
9
7
|
describe '#cast' do
|
10
|
-
let(:result) { filter.cast
|
8
|
+
let(:result) { filter.send(:cast, value, nil) }
|
11
9
|
|
12
10
|
context 'with an Integer' do
|
13
11
|
let(:value) { rand(1 << 16) }
|
@@ -29,7 +27,7 @@ describe ActiveInteraction::IntegerFilter, :filter do
|
|
29
27
|
let(:value) { rand(1 << 16).to_s }
|
30
28
|
|
31
29
|
it 'returns an Integer' do
|
32
|
-
expect(result).to eql Integer(value)
|
30
|
+
expect(result).to eql Integer(value, 10)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
@@ -43,12 +41,56 @@ describe ActiveInteraction::IntegerFilter, :filter do
|
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
44
|
+
context 'with an implicit String' do
|
45
|
+
let(:value) do
|
46
|
+
Class.new do
|
47
|
+
def to_str
|
48
|
+
'1'
|
49
|
+
end
|
50
|
+
end.new
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns an Integer' do
|
54
|
+
# jRuby freezes on the implicit string value
|
55
|
+
expect(result).to eql Integer(value.to_str, 10)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with a blank String' do
|
60
|
+
let(:value) do
|
61
|
+
Class.new do
|
62
|
+
def to_str
|
63
|
+
' '
|
64
|
+
end
|
65
|
+
end.new
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'optional' do
|
69
|
+
include_context 'optional'
|
70
|
+
|
71
|
+
it 'returns the default' do
|
72
|
+
expect(result).to eql options[:default]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'required' do
|
77
|
+
include_context 'required'
|
78
|
+
|
79
|
+
it 'raises an error' do
|
80
|
+
expect do
|
81
|
+
result
|
82
|
+
end.to raise_error ActiveInteraction::MissingValueError
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
46
87
|
it 'supports different bases' do
|
47
|
-
expect(
|
88
|
+
expect(
|
89
|
+
described_class.new(name, base: 8).send(:cast, '071', nil)
|
90
|
+
).to eql 57
|
48
91
|
expect do
|
49
|
-
|
92
|
+
described_class.new(name, base: 8).send(:cast, '081', nil)
|
50
93
|
end.to raise_error ActiveInteraction::InvalidValueError
|
51
|
-
expect(described_class.new(name, base: 10).cast('08', nil)).to eql 8
|
52
94
|
end
|
53
95
|
end
|
54
96
|
|
@@ -1,47 +1,420 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
|
-
|
5
|
-
|
2
|
+
|
3
|
+
module InterfaceModule; end
|
4
|
+
|
5
|
+
class InterfaceClass; end # rubocop:disable Lint/EmptyClass
|
6
6
|
|
7
7
|
describe ActiveInteraction::InterfaceFilter, :filter do
|
8
8
|
include_context 'filters'
|
9
|
-
it_behaves_like 'a filter'
|
10
|
-
|
11
|
-
|
9
|
+
it_behaves_like 'a filter' do
|
10
|
+
let(:name) { :interface_module }
|
11
|
+
end
|
12
12
|
|
13
13
|
describe '#cast' do
|
14
|
-
let(:result) { filter.cast
|
14
|
+
let(:result) { filter.send(:cast, value, nil) }
|
15
15
|
|
16
|
-
context 'with
|
17
|
-
|
16
|
+
context 'with an implicit constant name' do
|
17
|
+
context 'passed an instance' do
|
18
|
+
context 'with the module included' do
|
19
|
+
let(:name) { :interface_module }
|
20
|
+
let(:value) do
|
21
|
+
Class.new do
|
22
|
+
include InterfaceModule
|
23
|
+
end.new
|
24
|
+
end
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
it 'returns a the value' do
|
27
|
+
expect(result).to eql value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with the class inherited from' do
|
32
|
+
let(:name) { :interface_class }
|
33
|
+
let(:value) do
|
34
|
+
Class.new(InterfaceClass) {}.new # rubocop:disable Lint/EmptyBlock
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns a the value' do
|
38
|
+
expect(result).to eql value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'that is extended by the ancestor' do
|
43
|
+
let(:name) { :interface_module }
|
44
|
+
let(:value) do
|
45
|
+
Class.new {}.new.extend(InterfaceModule) # rubocop:disable Lint/EmptyBlock
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns a the value' do
|
49
|
+
expect(result).to eql value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'that does not match' do
|
54
|
+
let(:name) { :interface_module }
|
55
|
+
let(:value) { Class.new }
|
56
|
+
|
57
|
+
it 'raises an error' do
|
58
|
+
expect do
|
59
|
+
result
|
60
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'with the class itself' do
|
65
|
+
let(:name) { :interface_class }
|
66
|
+
let(:value) do
|
67
|
+
InterfaceClass.new
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'raises an error' do
|
71
|
+
expect do
|
72
|
+
result
|
73
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'passed a class' do
|
79
|
+
context 'with the class inherited from' do
|
80
|
+
let(:name) { :interface_class }
|
81
|
+
let(:value) do
|
82
|
+
Class.new(InterfaceClass) {} # rubocop:disable Lint/EmptyBlock
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns a the value' do
|
86
|
+
expect(result).to eql value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'that is extended by the ancestor' do
|
91
|
+
let(:name) { :interface_module }
|
92
|
+
let(:value) do
|
93
|
+
Class.new do
|
94
|
+
extend InterfaceModule
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'returns a the value' do
|
99
|
+
expect(result).to eql value
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'that does not match' do
|
104
|
+
let(:name) { :interface_class }
|
105
|
+
let(:value) { Class }
|
106
|
+
|
107
|
+
it 'raises an error' do
|
108
|
+
expect do
|
109
|
+
result
|
110
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with the class itself' do
|
115
|
+
let(:name) { :interface_class }
|
116
|
+
let(:value) { InterfaceClass }
|
117
|
+
|
118
|
+
it 'raises an error' do
|
119
|
+
expect do
|
120
|
+
result
|
121
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'passed a module' do
|
127
|
+
context 'that is extended by the ancestor' do
|
128
|
+
let(:name) { :interface_module }
|
129
|
+
let(:value) do
|
130
|
+
Module.new do
|
131
|
+
extend InterfaceModule
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'returns a the value' do
|
136
|
+
expect(result).to eql value
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'that does not match' do
|
141
|
+
let(:name) { :interface_module }
|
142
|
+
let(:value) { Module.new }
|
143
|
+
|
144
|
+
it 'raises an error' do
|
145
|
+
expect do
|
146
|
+
result
|
147
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'with the module itself' do
|
152
|
+
let(:name) { :interface_module }
|
153
|
+
let(:value) { InterfaceModule }
|
154
|
+
|
155
|
+
it 'raises an error' do
|
156
|
+
expect do
|
157
|
+
result
|
158
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'given an invalid name' do
|
164
|
+
let(:name) { :invalid }
|
165
|
+
let(:value) { Object }
|
166
|
+
|
167
|
+
it 'raises an error' do
|
168
|
+
expect do
|
169
|
+
result
|
170
|
+
end.to raise_error ActiveInteraction::InvalidNameError
|
171
|
+
end
|
21
172
|
end
|
22
173
|
end
|
23
174
|
|
24
|
-
context 'with
|
25
|
-
|
175
|
+
context 'with a constant given' do
|
176
|
+
context 'passed an instance' do
|
177
|
+
context 'with the module included' do
|
178
|
+
before { options.merge!(from: :interface_module) }
|
179
|
+
let(:value) do
|
180
|
+
Class.new do
|
181
|
+
include InterfaceModule
|
182
|
+
end.new
|
183
|
+
end
|
26
184
|
|
27
|
-
|
28
|
-
|
185
|
+
it 'returns a the value' do
|
186
|
+
expect(result).to eql value
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'with the class inherited from' do
|
191
|
+
before { options.merge!(from: :interface_class) }
|
192
|
+
let(:value) do
|
193
|
+
Class.new(InterfaceClass) {}.new # rubocop:disable Lint/EmptyBlock
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'returns a the value' do
|
197
|
+
expect(result).to eql value
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context 'that is extended by the ancestor' do
|
202
|
+
before { options.merge!(from: :interface_module) }
|
203
|
+
let(:value) do
|
204
|
+
Class.new {}.new.extend(InterfaceModule) # rubocop:disable Lint/EmptyBlock
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'returns a the value' do
|
208
|
+
expect(result).to eql value
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'that does not match' do
|
213
|
+
let(:name) { :interface_class }
|
214
|
+
let(:value) { Class.new }
|
215
|
+
|
216
|
+
it 'raises an error' do
|
217
|
+
expect do
|
218
|
+
result
|
219
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'with the class itself' do
|
224
|
+
let(:name) { :interface_class }
|
225
|
+
let(:value) { InterfaceClass.new }
|
226
|
+
|
227
|
+
it 'raises an error' do
|
228
|
+
expect do
|
229
|
+
result
|
230
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'passed a class' do
|
236
|
+
context 'with the class inherited from' do
|
237
|
+
before { options.merge!(from: :interface_class) }
|
238
|
+
let(:value) do
|
239
|
+
Class.new(InterfaceClass) {} # rubocop:disable Lint/EmptyBlock
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'returns a the value' do
|
243
|
+
expect(result).to eql value
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'that is extended by the ancestor' do
|
248
|
+
before { options.merge!(from: :interface_module) }
|
249
|
+
let(:value) do
|
250
|
+
Class.new do
|
251
|
+
extend InterfaceModule
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'returns a the value' do
|
256
|
+
expect(result).to eql value
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context 'that does not match' do
|
261
|
+
let(:name) { :interface_class }
|
262
|
+
let(:value) { Class }
|
263
|
+
|
264
|
+
it 'raises an error' do
|
265
|
+
expect do
|
266
|
+
result
|
267
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'with the class itself' do
|
272
|
+
let(:name) { :interface_class }
|
273
|
+
let(:value) { InterfaceClass }
|
274
|
+
|
275
|
+
it 'raises an error' do
|
276
|
+
expect do
|
277
|
+
result
|
278
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'passed a module' do
|
284
|
+
context 'that is extended by the ancestor' do
|
285
|
+
before { options.merge!(from: :interface_module) }
|
286
|
+
let(:value) do
|
287
|
+
Module.new do
|
288
|
+
extend InterfaceModule
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'returns a the value' do
|
293
|
+
expect(result).to eql value
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'that does not match' do
|
298
|
+
let(:name) { :interface_module }
|
299
|
+
let(:value) { Module.new }
|
300
|
+
|
301
|
+
it 'raises an error' do
|
302
|
+
expect do
|
303
|
+
result
|
304
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'with the module itself' do
|
309
|
+
let(:name) { :interface_module }
|
310
|
+
let(:value) { InterfaceModule }
|
311
|
+
|
312
|
+
it 'raises an error' do
|
313
|
+
expect do
|
314
|
+
result
|
315
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
context 'given an invalid name' do
|
321
|
+
before { options.merge!(from: :invalid) }
|
322
|
+
let(:value) { Object }
|
323
|
+
|
324
|
+
it 'raises an error' do
|
325
|
+
expect do
|
326
|
+
result
|
327
|
+
end.to raise_error ActiveInteraction::InvalidNameError
|
328
|
+
end
|
29
329
|
end
|
30
330
|
end
|
31
331
|
|
32
|
-
context 'with
|
33
|
-
|
332
|
+
context 'with methods passed' do
|
333
|
+
before { options[:methods] = %i[dump load] }
|
334
|
+
|
335
|
+
context 'passed an valid instance' do
|
336
|
+
let(:value) do
|
337
|
+
Class.new do
|
338
|
+
def dump; end
|
34
339
|
|
35
|
-
|
36
|
-
|
340
|
+
def load; end
|
341
|
+
end.new
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'returns a the value' do
|
345
|
+
expect(result).to eql value
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context 'passed an invalid instance' do
|
350
|
+
let(:value) { Class.new }
|
351
|
+
|
352
|
+
it 'raises an error' do
|
353
|
+
expect do
|
354
|
+
result
|
355
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context 'passed a class' do
|
360
|
+
let(:value) do
|
361
|
+
Class.new do
|
362
|
+
def self.dump; end
|
363
|
+
|
364
|
+
def self.load; end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
it 'returns a the value' do
|
369
|
+
expect(result).to eql value
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
context 'passed an invalid class' do
|
374
|
+
let(:value) { Class }
|
375
|
+
|
376
|
+
it 'raises an error' do
|
377
|
+
expect do
|
378
|
+
result
|
379
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
context 'passed a module' do
|
384
|
+
let(:value) do
|
385
|
+
Module.new do
|
386
|
+
def self.dump; end
|
387
|
+
|
388
|
+
def self.load; end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'returns a the value' do
|
393
|
+
expect(result).to eql value
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context 'passed an invalid module' do
|
398
|
+
let(:value) { Module.new }
|
399
|
+
|
400
|
+
it 'raises an error' do
|
401
|
+
expect do
|
402
|
+
result
|
403
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
404
|
+
end
|
37
405
|
end
|
38
406
|
end
|
39
407
|
|
40
|
-
context 'with
|
41
|
-
|
408
|
+
context 'with from and methods passed' do
|
409
|
+
before do
|
410
|
+
options[:from] = :module
|
411
|
+
options[:methods] = %i[dump load]
|
412
|
+
end
|
42
413
|
|
43
|
-
it '
|
44
|
-
expect
|
414
|
+
it 'raises an error' do
|
415
|
+
expect do
|
416
|
+
filter
|
417
|
+
end.to raise_error ActiveInteraction::InvalidFilterError
|
45
418
|
end
|
46
419
|
end
|
47
420
|
end
|