active_interaction 4.0.5 → 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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -6
  3. data/README.md +67 -32
  4. data/lib/active_interaction/array_input.rb +77 -0
  5. data/lib/active_interaction/base.rb +14 -98
  6. data/lib/active_interaction/concerns/active_recordable.rb +3 -3
  7. data/lib/active_interaction/concerns/missable.rb +2 -2
  8. data/lib/active_interaction/errors.rb +6 -88
  9. data/lib/active_interaction/exceptions.rb +47 -0
  10. data/lib/active_interaction/filter/column.rb +59 -0
  11. data/lib/active_interaction/filter/error.rb +40 -0
  12. data/lib/active_interaction/filter.rb +44 -53
  13. data/lib/active_interaction/filters/abstract_date_time_filter.rb +9 -6
  14. data/lib/active_interaction/filters/abstract_numeric_filter.rb +7 -3
  15. data/lib/active_interaction/filters/array_filter.rb +36 -10
  16. data/lib/active_interaction/filters/boolean_filter.rb +4 -3
  17. data/lib/active_interaction/filters/date_filter.rb +1 -1
  18. data/lib/active_interaction/filters/date_time_filter.rb +1 -1
  19. data/lib/active_interaction/filters/decimal_filter.rb +1 -1
  20. data/lib/active_interaction/filters/float_filter.rb +1 -1
  21. data/lib/active_interaction/filters/hash_filter.rb +23 -15
  22. data/lib/active_interaction/filters/integer_filter.rb +1 -1
  23. data/lib/active_interaction/filters/interface_filter.rb +12 -12
  24. data/lib/active_interaction/filters/object_filter.rb +9 -3
  25. data/lib/active_interaction/filters/record_filter.rb +21 -11
  26. data/lib/active_interaction/filters/string_filter.rb +1 -1
  27. data/lib/active_interaction/filters/symbol_filter.rb +1 -1
  28. data/lib/active_interaction/filters/time_filter.rb +4 -4
  29. data/lib/active_interaction/hash_input.rb +43 -0
  30. data/lib/active_interaction/input.rb +23 -0
  31. data/lib/active_interaction/inputs.rb +157 -46
  32. data/lib/active_interaction/locale/en.yml +0 -1
  33. data/lib/active_interaction/locale/fr.yml +0 -1
  34. data/lib/active_interaction/locale/it.yml +0 -1
  35. data/lib/active_interaction/locale/ja.yml +0 -1
  36. data/lib/active_interaction/locale/pt-BR.yml +0 -1
  37. data/lib/active_interaction/modules/validation.rb +6 -17
  38. data/lib/active_interaction/version.rb +1 -1
  39. data/lib/active_interaction.rb +43 -36
  40. data/spec/active_interaction/array_input_spec.rb +166 -0
  41. data/spec/active_interaction/base_spec.rb +15 -240
  42. data/spec/active_interaction/concerns/active_modelable_spec.rb +3 -3
  43. data/spec/active_interaction/concerns/active_recordable_spec.rb +7 -7
  44. data/spec/active_interaction/concerns/hashable_spec.rb +8 -8
  45. data/spec/active_interaction/concerns/missable_spec.rb +9 -9
  46. data/spec/active_interaction/concerns/runnable_spec.rb +34 -32
  47. data/spec/active_interaction/errors_spec.rb +60 -43
  48. data/spec/active_interaction/{filter_column_spec.rb → filter/column_spec.rb} +3 -10
  49. data/spec/active_interaction/filter_spec.rb +6 -6
  50. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +2 -2
  51. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +2 -2
  52. data/spec/active_interaction/filters/array_filter_spec.rb +99 -24
  53. data/spec/active_interaction/filters/boolean_filter_spec.rb +12 -11
  54. data/spec/active_interaction/filters/date_filter_spec.rb +32 -27
  55. data/spec/active_interaction/filters/date_time_filter_spec.rb +34 -29
  56. data/spec/active_interaction/filters/decimal_filter_spec.rb +20 -18
  57. data/spec/active_interaction/filters/file_filter_spec.rb +7 -7
  58. data/spec/active_interaction/filters/float_filter_spec.rb +19 -17
  59. data/spec/active_interaction/filters/hash_filter_spec.rb +16 -18
  60. data/spec/active_interaction/filters/integer_filter_spec.rb +24 -22
  61. data/spec/active_interaction/filters/interface_filter_spec.rb +105 -82
  62. data/spec/active_interaction/filters/object_filter_spec.rb +52 -36
  63. data/spec/active_interaction/filters/record_filter_spec.rb +61 -39
  64. data/spec/active_interaction/filters/string_filter_spec.rb +7 -7
  65. data/spec/active_interaction/filters/symbol_filter_spec.rb +6 -6
  66. data/spec/active_interaction/filters/time_filter_spec.rb +57 -34
  67. data/spec/active_interaction/hash_input_spec.rb +58 -0
  68. data/spec/active_interaction/i18n_spec.rb +22 -17
  69. data/spec/active_interaction/inputs_spec.rb +167 -23
  70. data/spec/active_interaction/integration/array_interaction_spec.rb +3 -7
  71. data/spec/active_interaction/modules/validation_spec.rb +8 -31
  72. data/spec/spec_helper.rb +8 -0
  73. data/spec/support/concerns.rb +2 -2
  74. data/spec/support/filters.rb +27 -51
  75. data/spec/support/interactions.rb +4 -4
  76. metadata +45 -95
  77. data/lib/active_interaction/filter_column.rb +0 -57
@@ -12,14 +12,14 @@ describe ActiveInteraction::DateTimeFilter, :filter do
12
12
  end
13
13
  end
14
14
 
15
- describe '#cast' do
16
- let(:result) { filter.send(:cast, value, nil) }
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 'raises an error' do
48
- expect do
49
- result
50
- end.to raise_error ActiveInteraction::InvalidValueError
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 'raises an error' do
57
- expect do
58
- result
59
- end.to raise_error ActiveInteraction::InvalidValueError
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 'raises an error' do
99
- expect do
100
- result
101
- end.to raise_error ActiveInteraction::MissingValueError
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 'raises an error' do
136
- expect do
137
- result
138
- end.to raise_error ActiveInteraction::InvalidValueError
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 'raises an error' do
150
- expect do
151
- result
152
- end.to raise_error ActiveInteraction::InvalidValueError
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 eql :datetime
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 '#cast' do
16
- let(:result) { filter.send(:cast, value, nil) }
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 'raises an error' do
70
- expect do
71
- result
72
- end.to raise_error ActiveInteraction::InvalidValueError
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 'raises an error' do
111
- expect do
112
- result
113
- end.to raise_error ActiveInteraction::MissingValueError
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 eql :decimal
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 '#cast' do
8
- let(:result) { filter.send(:cast, value, nil) }
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 eql :file
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 '#cast' do
9
- let(:result) { filter.send(:cast, value, nil) }
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 'raises an error' do
53
- expect do
54
- result
55
- end.to raise_error ActiveInteraction::InvalidValueError
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 'raises an error' do
95
- expect do
96
- result
97
- end.to raise_error ActiveInteraction::MissingValueError
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 eql :float
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 '#cast' do
16
- let(:result) { filter.send(:cast, value, nil) }
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 'raises an error' do
75
- expect do
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
- it 'populates the error' do
81
- result
82
- rescue ActiveInteraction::InvalidNestedValueError => e
83
- expect(e.filter_name).to eql k
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 eql :string
126
+ expect(filter.database_column_type).to be :string
129
127
  end
130
128
  end
131
129
  end
@@ -4,14 +4,14 @@ describe ActiveInteraction::IntegerFilter, :filter do
4
4
  include_context 'filters'
5
5
  it_behaves_like 'a filter'
6
6
 
7
- describe '#cast' do
8
- let(:result) { filter.send(:cast, value, nil) }
7
+ describe '#process' do
8
+ let(:result) { filter.process(value, nil) }
9
9
 
10
10
  context 'with an Integer' do
11
11
  let(:value) { rand(1 << 16) }
12
12
 
13
13
  it 'returns the Integer' do
14
- expect(result).to eql value
14
+ expect(result.value).to eql value
15
15
  end
16
16
  end
17
17
 
@@ -19,7 +19,7 @@ describe ActiveInteraction::IntegerFilter, :filter do
19
19
  let(:value) { rand(1 << 16) + rand }
20
20
 
21
21
  it 'returns an Integer' do
22
- expect(result).to eql value.to_i
22
+ expect(result.value).to eql value.to_i
23
23
  end
24
24
  end
25
25
 
@@ -27,17 +27,18 @@ describe ActiveInteraction::IntegerFilter, :filter do
27
27
  let(:value) { rand(1 << 16).to_s }
28
28
 
29
29
  it 'returns an Integer' do
30
- expect(result).to eql Integer(value, 10)
30
+ expect(result.value).to eql Integer(value, 10)
31
31
  end
32
32
  end
33
33
 
34
34
  context 'with an invalid String' do
35
35
  let(:value) { 'invalid' }
36
36
 
37
- it 'raises an error' do
38
- expect do
39
- result
40
- end.to raise_error ActiveInteraction::InvalidValueError
37
+ it 'indicates an error' do
38
+ error = result.errors.first
39
+
40
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
41
+ expect(error.type).to be :invalid_type
41
42
  end
42
43
  end
43
44
 
@@ -51,8 +52,7 @@ describe ActiveInteraction::IntegerFilter, :filter do
51
52
  end
52
53
 
53
54
  it 'returns an Integer' do
54
- # jRuby freezes on the implicit string value
55
- expect(result).to eql Integer(value.to_str, 10)
55
+ expect(result.value).to eql Integer(value.to_str, 10)
56
56
  end
57
57
  end
58
58
 
@@ -69,34 +69,36 @@ describe ActiveInteraction::IntegerFilter, :filter do
69
69
  include_context 'optional'
70
70
 
71
71
  it 'returns the default' do
72
- expect(result).to eql options[:default]
72
+ expect(result.value).to eql options[:default]
73
73
  end
74
74
  end
75
75
 
76
76
  context 'required' do
77
77
  include_context 'required'
78
78
 
79
- it 'raises an error' do
80
- expect do
81
- result
82
- end.to raise_error ActiveInteraction::MissingValueError
79
+ it 'indicates an error' do
80
+ error = result.errors.first
81
+
82
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
83
+ expect(error.type).to be :missing
83
84
  end
84
85
  end
85
86
  end
86
87
 
87
88
  it 'supports different bases' do
88
89
  expect(
89
- described_class.new(name, base: 8).send(:cast, '071', nil)
90
- ).to eql 57
91
- expect do
92
- described_class.new(name, base: 8).send(:cast, '081', nil)
93
- end.to raise_error ActiveInteraction::InvalidValueError
90
+ described_class.new(name, base: 8).process('071', nil).value
91
+ ).to be 57
92
+ error = described_class.new(name, base: 8).process('081', nil).errors.first
93
+
94
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
95
+ expect(error.type).to be :invalid_type
94
96
  end
95
97
  end
96
98
 
97
99
  describe '#database_column_type' do
98
100
  it 'returns :integer' do
99
- expect(filter.database_column_type).to eql :integer
101
+ expect(filter.database_column_type).to be :integer
100
102
  end
101
103
  end
102
104
  end