active_interaction 4.1.0 → 5.0.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 +128 -1
- data/README.md +63 -28
- 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 +44 -53
- 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 +34 -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 +157 -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 +43 -36
- data/spec/active_interaction/array_input_spec.rb +166 -0
- data/spec/active_interaction/base_spec.rb +15 -240
- 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 +6 -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 +99 -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 +167 -23
- data/spec/active_interaction/integration/array_interaction_spec.rb +3 -7
- data/spec/active_interaction/modules/validation_spec.rb +8 -31
- data/spec/spec_helper.rb +8 -0
- data/spec/support/concerns.rb +2 -2
- data/spec/support/filters.rb +27 -51
- data/spec/support/interactions.rb +4 -4
- metadata +40 -91
- data/lib/active_interaction/filter_column.rb +0 -57
@@ -12,14 +12,14 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '#
|
16
|
-
let(:result) { filter.
|
15
|
+
describe '#process' do
|
16
|
+
let(:result) { filter.process(value, nil) }
|
17
17
|
|
18
18
|
context 'with a Date' do
|
19
19
|
let(:value) { Date.new }
|
20
20
|
|
21
21
|
it 'returns the Date' do
|
22
|
-
expect(result).to eql value
|
22
|
+
expect(result.value).to eql value
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,7 +27,7 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
27
27
|
let(:value) { '2011-12-13' }
|
28
28
|
|
29
29
|
it 'returns a Date' do
|
30
|
-
expect(result).to eql Date.parse(value)
|
30
|
+
expect(result.value).to eql Date.parse(value)
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'with format' do
|
@@ -36,7 +36,7 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
36
36
|
let(:value) { '13/12/2011' }
|
37
37
|
|
38
38
|
it 'returns a Date' do
|
39
|
-
expect(result).to eql Date.strptime(value, format)
|
39
|
+
expect(result.value).to eql Date.strptime(value, format)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -44,19 +44,21 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
44
44
|
context 'with an invalid String' do
|
45
45
|
let(:value) { 'invalid' }
|
46
46
|
|
47
|
-
it '
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
it 'indicates an error' do
|
48
|
+
error = result.errors.first
|
49
|
+
|
50
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
51
|
+
expect(error.type).to be :invalid_type
|
51
52
|
end
|
52
53
|
|
53
54
|
context 'with format' do
|
54
55
|
include_context 'with format'
|
55
56
|
|
56
57
|
it 'raises an error' do
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
error = result.errors.first
|
59
|
+
|
60
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
61
|
+
expect(error.type).to be :invalid_type
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -71,7 +73,7 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'returns a Date' do
|
74
|
-
expect(result).to eql Date.parse(value)
|
76
|
+
expect(result.value).to eql Date.parse(value)
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
@@ -88,17 +90,18 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
88
90
|
include_context 'optional'
|
89
91
|
|
90
92
|
it 'returns the default' do
|
91
|
-
expect(result).to eql options[:default]
|
93
|
+
expect(result.value).to eql options[:default]
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
97
|
context 'required' do
|
96
98
|
include_context 'required'
|
97
99
|
|
98
|
-
it '
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
it 'indicates an error' do
|
101
|
+
error = result.errors.first
|
102
|
+
|
103
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
104
|
+
expect(error.type).to be :missing
|
102
105
|
end
|
103
106
|
end
|
104
107
|
end
|
@@ -116,7 +119,7 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
116
119
|
end
|
117
120
|
|
118
121
|
it 'returns a Date' do
|
119
|
-
expect(result).to eql Date.new(year, month, day)
|
122
|
+
expect(result.value).to eql Date.new(year, month, day)
|
120
123
|
end
|
121
124
|
end
|
122
125
|
|
@@ -124,10 +127,11 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
124
127
|
context 'empty' do
|
125
128
|
let(:value) { ActiveInteraction::GroupedInput.new }
|
126
129
|
|
127
|
-
it '
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
it 'indicates an error' do
|
131
|
+
error = result.errors.first
|
132
|
+
|
133
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
134
|
+
expect(error.type).to be :invalid_type
|
131
135
|
end
|
132
136
|
end
|
133
137
|
|
@@ -139,9 +143,10 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
139
143
|
end
|
140
144
|
|
141
145
|
it 'raises an error' do
|
142
|
-
|
143
|
-
|
144
|
-
|
146
|
+
error = result.errors.first
|
147
|
+
|
148
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
149
|
+
expect(error.type).to be :invalid_type
|
145
150
|
end
|
146
151
|
end
|
147
152
|
end
|
@@ -149,7 +154,7 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
149
154
|
|
150
155
|
describe '#database_column_type' do
|
151
156
|
it 'returns :date' do
|
152
|
-
expect(filter.database_column_type).to
|
157
|
+
expect(filter.database_column_type).to be :date
|
153
158
|
end
|
154
159
|
end
|
155
160
|
|
@@ -12,14 +12,14 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '#
|
16
|
-
let(:result) { filter.
|
15
|
+
describe '#process' do
|
16
|
+
let(:result) { filter.process(value, nil) }
|
17
17
|
|
18
18
|
context 'with a Datetime' do
|
19
19
|
let(:value) { DateTime.new }
|
20
20
|
|
21
21
|
it 'returns the DateTime' do
|
22
|
-
expect(result).to eql value
|
22
|
+
expect(result.value).to eql value
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,7 +27,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
27
27
|
let(:value) { '2011-12-13T14:15:16+17:18' }
|
28
28
|
|
29
29
|
it 'returns a DateTime' do
|
30
|
-
expect(result).to eql DateTime.parse(value)
|
30
|
+
expect(result.value).to eql DateTime.parse(value)
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'with format' do
|
@@ -36,7 +36,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
36
36
|
let(:value) { '13/12/2011 14:15:16 +17:18' }
|
37
37
|
|
38
38
|
it 'returns a DateTime' do
|
39
|
-
expect(result).to eql DateTime.strptime(value, format)
|
39
|
+
expect(result.value).to eql DateTime.strptime(value, format)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -44,19 +44,21 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
44
44
|
context 'with an invalid String' do
|
45
45
|
let(:value) { 'invalid' }
|
46
46
|
|
47
|
-
it '
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
it 'indicates an error' do
|
48
|
+
error = result.errors.first
|
49
|
+
|
50
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
51
|
+
expect(error.type).to be :invalid_type
|
51
52
|
end
|
52
53
|
|
53
54
|
context 'with format' do
|
54
55
|
include_context 'with format'
|
55
56
|
|
56
|
-
it '
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
it 'indicates an error' do
|
58
|
+
error = result.errors.first
|
59
|
+
|
60
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
61
|
+
expect(error.type).to be :invalid_type
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -71,7 +73,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'returns a DateTime' do
|
74
|
-
expect(result).to eql DateTime.parse(value)
|
76
|
+
expect(result.value).to eql DateTime.parse(value)
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
@@ -88,17 +90,18 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
88
90
|
include_context 'optional'
|
89
91
|
|
90
92
|
it 'returns the default' do
|
91
|
-
expect(result).to eql options[:default]
|
93
|
+
expect(result.value).to eql options[:default]
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
97
|
context 'required' do
|
96
98
|
include_context 'required'
|
97
99
|
|
98
|
-
it '
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
it 'indicates an error' do
|
101
|
+
error = result.errors.first
|
102
|
+
|
103
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
104
|
+
expect(error.type).to be :missing
|
102
105
|
end
|
103
106
|
end
|
104
107
|
end
|
@@ -123,7 +126,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
123
126
|
|
124
127
|
it 'returns a DateTime' do
|
125
128
|
expect(
|
126
|
-
result
|
129
|
+
result.value
|
127
130
|
).to eql DateTime.new(year, month, day, hour, min, sec)
|
128
131
|
end
|
129
132
|
end
|
@@ -132,10 +135,11 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
132
135
|
context 'empty' do
|
133
136
|
let(:value) { ActiveInteraction::GroupedInput.new }
|
134
137
|
|
135
|
-
it '
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
it 'indicates an error' do
|
139
|
+
error = result.errors.first
|
140
|
+
|
141
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
142
|
+
expect(error.type).to be :invalid_type
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
@@ -146,10 +150,11 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
146
150
|
)
|
147
151
|
end
|
148
152
|
|
149
|
-
it '
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
+
it 'indicates an error' do
|
154
|
+
error = result.errors.first
|
155
|
+
|
156
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
157
|
+
expect(error.type).to be :invalid_type
|
153
158
|
end
|
154
159
|
end
|
155
160
|
end
|
@@ -157,7 +162,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
157
162
|
|
158
163
|
describe '#database_column_type' do
|
159
164
|
it 'returns :datetime' do
|
160
|
-
expect(filter.database_column_type).to
|
165
|
+
expect(filter.database_column_type).to be :datetime
|
161
166
|
end
|
162
167
|
end
|
163
168
|
|
@@ -12,14 +12,14 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '#
|
16
|
-
let(:result) { filter.
|
15
|
+
describe '#process' do
|
16
|
+
let(:result) { filter.process(value, nil) }
|
17
17
|
|
18
18
|
context 'with a Float' do
|
19
19
|
let(:value) { rand }
|
20
20
|
|
21
21
|
it 'returns the BigDecimal' do
|
22
|
-
expect(result).to eql BigDecimal(value, 0)
|
22
|
+
expect(result.value).to eql BigDecimal(value, 0)
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'with :digits option' do
|
@@ -28,7 +28,7 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
28
28
|
let(:value) { 1.23456789 }
|
29
29
|
|
30
30
|
it 'returns BigDecimal with given digits' do
|
31
|
-
expect(result).to eql BigDecimal('1.235')
|
31
|
+
expect(result.value).to eql BigDecimal('1.235')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -43,7 +43,7 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns a BigDecimal' do
|
46
|
-
expect(result).to eql BigDecimal(value.to_int)
|
46
|
+
expect(result.value).to eql BigDecimal(value.to_int)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
51
51
|
let(:value) { rand(1 << 16) }
|
52
52
|
|
53
53
|
it 'returns a BigDecimal' do
|
54
|
-
expect(result).to eql BigDecimal(value)
|
54
|
+
expect(result.value).to eql BigDecimal(value)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,17 +59,18 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
59
59
|
let(:value) { rand.to_s }
|
60
60
|
|
61
61
|
it 'returns a BigDecimal' do
|
62
|
-
expect(result).to eql BigDecimal(value)
|
62
|
+
expect(result.value).to eql BigDecimal(value)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'with an invalid String' do
|
67
67
|
let(:value) { 'invalid' }
|
68
68
|
|
69
|
-
it '
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
it 'indicates an error' do
|
70
|
+
error = result.errors.first
|
71
|
+
|
72
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
73
|
+
expect(error.type).to be :invalid_type
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -83,7 +84,7 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
83
84
|
end
|
84
85
|
|
85
86
|
it 'returns a BigDecimal' do
|
86
|
-
expect(result).to eql BigDecimal(value)
|
87
|
+
expect(result.value).to eql BigDecimal(value)
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
@@ -100,17 +101,18 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
100
101
|
include_context 'optional'
|
101
102
|
|
102
103
|
it 'returns the default' do
|
103
|
-
expect(result).to eql options[:default]
|
104
|
+
expect(result.value).to eql options[:default]
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
108
|
context 'required' do
|
108
109
|
include_context 'required'
|
109
110
|
|
110
|
-
it '
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
it 'indicates an error' do
|
112
|
+
error = result.errors.first
|
113
|
+
|
114
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
115
|
+
expect(error.type).to be :missing
|
114
116
|
end
|
115
117
|
end
|
116
118
|
end
|
@@ -118,7 +120,7 @@ describe ActiveInteraction::DecimalFilter, :filter do
|
|
118
120
|
|
119
121
|
describe '#database_column_type' do
|
120
122
|
it 'returns :decimal' do
|
121
|
-
expect(filter.database_column_type).to
|
123
|
+
expect(filter.database_column_type).to be :decimal
|
122
124
|
end
|
123
125
|
end
|
124
126
|
end
|
@@ -4,14 +4,14 @@ describe ActiveInteraction::FileFilter, :filter do
|
|
4
4
|
include_context 'filters'
|
5
5
|
it_behaves_like 'a filter'
|
6
6
|
|
7
|
-
describe '#
|
8
|
-
let(:result) { filter.
|
7
|
+
describe '#process' do
|
8
|
+
let(:result) { filter.process(value, nil) }
|
9
9
|
|
10
10
|
context 'with a File' do
|
11
11
|
let(:value) { File.new(__FILE__) }
|
12
12
|
|
13
13
|
it 'returns the File' do
|
14
|
-
expect(result).to eql value
|
14
|
+
expect(result.value).to eql value
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -19,22 +19,22 @@ describe ActiveInteraction::FileFilter, :filter do
|
|
19
19
|
let(:value) { Tempfile.new(SecureRandom.hex) }
|
20
20
|
|
21
21
|
it 'returns the Tempfile' do
|
22
|
-
expect(result).to eq value
|
22
|
+
expect(result.value).to eq value
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'with an object that responds to #rewind' do
|
27
|
-
let(:value) { double(rewind: nil) }
|
27
|
+
let(:value) { double(rewind: nil) } # rubocop:disable RSpec/VerifiedDoubles
|
28
28
|
|
29
29
|
it 'returns the object' do
|
30
|
-
expect(result).to eq value
|
30
|
+
expect(result.value).to eq value
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#database_column_type' do
|
36
36
|
it 'returns :file' do
|
37
|
-
expect(filter.database_column_type).to
|
37
|
+
expect(filter.database_column_type).to be :file
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -5,14 +5,14 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
5
5
|
include_context 'filters'
|
6
6
|
it_behaves_like 'a filter'
|
7
7
|
|
8
|
-
describe '#
|
9
|
-
let(:result) { filter.
|
8
|
+
describe '#process' do
|
9
|
+
let(:result) { filter.process(value, nil) }
|
10
10
|
|
11
11
|
context 'with a Float' do
|
12
12
|
let(:value) { rand }
|
13
13
|
|
14
14
|
it 'returns the Float' do
|
15
|
-
expect(result).to eql value
|
15
|
+
expect(result.value).to eql value
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -26,7 +26,7 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'returns a Float' do
|
29
|
-
expect(result).to eql value.to_int.to_f
|
29
|
+
expect(result.value).to eql value.to_int.to_f
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
34
34
|
let(:value) { BigDecimal('1.2') }
|
35
35
|
|
36
36
|
it 'returns a Float' do
|
37
|
-
expect(result).to eql value.to_f
|
37
|
+
expect(result.value).to eql value.to_f
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,17 +42,18 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
42
42
|
let(:value) { rand.to_s }
|
43
43
|
|
44
44
|
it 'returns a Float' do
|
45
|
-
expect(result).to eql Float(value)
|
45
|
+
expect(result.value).to eql Float(value)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'with an invalid String' do
|
50
50
|
let(:value) { 'invalid' }
|
51
51
|
|
52
|
-
it '
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it 'indicates an error' do
|
53
|
+
error = result.errors.first
|
54
|
+
|
55
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
56
|
+
expect(error.type).to be :invalid_type
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -67,7 +68,7 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
67
68
|
|
68
69
|
it 'returns a Float' do
|
69
70
|
# apparently `Float()` doesn't do this even though `Integer()` does
|
70
|
-
expect(result).to eql Float(value.to_str)
|
71
|
+
expect(result.value).to eql Float(value.to_str)
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
@@ -84,17 +85,18 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
84
85
|
include_context 'optional'
|
85
86
|
|
86
87
|
it 'returns the default' do
|
87
|
-
expect(result).to eql options[:default]
|
88
|
+
expect(result.value).to eql options[:default]
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
91
92
|
context 'required' do
|
92
93
|
include_context 'required'
|
93
94
|
|
94
|
-
it '
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
it 'indicates an error' do
|
96
|
+
error = result.errors.first
|
97
|
+
|
98
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
99
|
+
expect(error.type).to be :missing
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
@@ -102,7 +104,7 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
102
104
|
|
103
105
|
describe '#database_column_type' do
|
104
106
|
it 'returns :float' do
|
105
|
-
expect(filter.database_column_type).to
|
107
|
+
expect(filter.database_column_type).to be :float
|
106
108
|
end
|
107
109
|
end
|
108
110
|
end
|
@@ -12,14 +12,15 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '#
|
16
|
-
let(:result) { filter.
|
15
|
+
describe '#process' do
|
16
|
+
let(:result) { filter.process(value, nil) }
|
17
17
|
|
18
18
|
context 'with a Hash' do
|
19
19
|
let(:value) { {} }
|
20
20
|
|
21
21
|
it 'returns the Hash' do
|
22
|
-
expect(result).to eql value
|
22
|
+
expect(result.value).to eql value
|
23
|
+
expect(result.value).to be_an_instance_of HashWithIndifferentAccess
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -33,7 +34,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'returns the Hash' do
|
36
|
-
expect(result).to eql value.to_hash
|
37
|
+
expect(result.value).to eql value.to_hash
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -41,7 +42,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
41
42
|
let(:value) { { a: {} } }
|
42
43
|
|
43
44
|
it 'returns an empty Hash' do
|
44
|
-
expect(result).to eql({})
|
45
|
+
expect(result.value).to eql({})
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -52,7 +53,8 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
52
53
|
let(:value) { { 'a' => {} } }
|
53
54
|
|
54
55
|
it 'returns the Hash' do
|
55
|
-
expect(result).to eql value
|
56
|
+
expect(result.value).to eql value
|
57
|
+
expect(result.value).to be_an_instance_of HashWithIndifferentAccess
|
56
58
|
end
|
57
59
|
|
58
60
|
context 'with String keys' do
|
@@ -71,17 +73,13 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
71
73
|
let(:v) { double }
|
72
74
|
let(:value) { { k => v } }
|
73
75
|
|
74
|
-
it '
|
75
|
-
|
76
|
-
result
|
77
|
-
end.to raise_error ActiveInteraction::InvalidNestedValueError
|
78
|
-
end
|
76
|
+
it 'indicates an error' do
|
77
|
+
error = result.errors.first
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
expect(
|
84
|
-
expect(e.input_value).to eql v
|
79
|
+
expect(result.errors.size).to be 1
|
80
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
81
|
+
expect(error.name).to be :"#{filter.name}.#{error.filter.name}"
|
82
|
+
expect(error.type).to be :invalid_type
|
85
83
|
end
|
86
84
|
end
|
87
85
|
end
|
@@ -93,7 +91,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
93
91
|
let(:value) { { 'a' => {} } }
|
94
92
|
|
95
93
|
it 'returns an empty Hash' do
|
96
|
-
expect(result).to eql value
|
94
|
+
expect(result.value).to eql value
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
@@ -125,7 +123,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
125
123
|
|
126
124
|
describe '#database_column_type' do
|
127
125
|
it 'returns :string' do
|
128
|
-
expect(filter.database_column_type).to
|
126
|
+
expect(filter.database_column_type).to be :string
|
129
127
|
end
|
130
128
|
end
|
131
129
|
end
|