active_interaction 5.3.0 → 5.4.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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +2 -2
  4. data/lib/active_interaction/errors.rb +1 -1
  5. data/lib/active_interaction/version.rb +1 -1
  6. metadata +26 -112
  7. data/spec/active_interaction/array_input_spec.rb +0 -164
  8. data/spec/active_interaction/base_spec.rb +0 -536
  9. data/spec/active_interaction/concerns/active_modelable_spec.rb +0 -43
  10. data/spec/active_interaction/concerns/active_recordable_spec.rb +0 -47
  11. data/spec/active_interaction/concerns/hashable_spec.rb +0 -44
  12. data/spec/active_interaction/concerns/missable_spec.rb +0 -97
  13. data/spec/active_interaction/concerns/runnable_spec.rb +0 -395
  14. data/spec/active_interaction/errors_spec.rb +0 -223
  15. data/spec/active_interaction/filter/column_spec.rb +0 -85
  16. data/spec/active_interaction/filter_spec.rb +0 -58
  17. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +0 -11
  18. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +0 -11
  19. data/spec/active_interaction/filters/array_filter_spec.rb +0 -248
  20. data/spec/active_interaction/filters/boolean_filter_spec.rb +0 -85
  21. data/spec/active_interaction/filters/date_filter_spec.rb +0 -176
  22. data/spec/active_interaction/filters/date_time_filter_spec.rb +0 -187
  23. data/spec/active_interaction/filters/decimal_filter_spec.rb +0 -124
  24. data/spec/active_interaction/filters/file_filter_spec.rb +0 -38
  25. data/spec/active_interaction/filters/float_filter_spec.rb +0 -109
  26. data/spec/active_interaction/filters/hash_filter_spec.rb +0 -127
  27. data/spec/active_interaction/filters/integer_filter_spec.rb +0 -102
  28. data/spec/active_interaction/filters/interface_filter_spec.rb +0 -459
  29. data/spec/active_interaction/filters/object_filter_spec.rb +0 -235
  30. data/spec/active_interaction/filters/record_filter_spec.rb +0 -204
  31. data/spec/active_interaction/filters/string_filter_spec.rb +0 -58
  32. data/spec/active_interaction/filters/symbol_filter_spec.rb +0 -44
  33. data/spec/active_interaction/filters/time_filter_spec.rb +0 -249
  34. data/spec/active_interaction/grouped_input_spec.rb +0 -15
  35. data/spec/active_interaction/hash_input_spec.rb +0 -56
  36. data/spec/active_interaction/i18n_spec.rb +0 -111
  37. data/spec/active_interaction/inputs_spec.rb +0 -264
  38. data/spec/active_interaction/integration/array_interaction_spec.rb +0 -87
  39. data/spec/active_interaction/integration/boolean_interaction_spec.rb +0 -11
  40. data/spec/active_interaction/integration/date_interaction_spec.rb +0 -3
  41. data/spec/active_interaction/integration/date_time_interaction_spec.rb +0 -3
  42. data/spec/active_interaction/integration/file_interaction_spec.rb +0 -17
  43. data/spec/active_interaction/integration/float_interaction_spec.rb +0 -3
  44. data/spec/active_interaction/integration/hash_interaction_spec.rb +0 -106
  45. data/spec/active_interaction/integration/integer_interaction_spec.rb +0 -3
  46. data/spec/active_interaction/integration/interface_interaction_spec.rb +0 -18
  47. data/spec/active_interaction/integration/object_interaction_spec.rb +0 -12
  48. data/spec/active_interaction/integration/record_integration_spec.rb +0 -3
  49. data/spec/active_interaction/integration/string_interaction_spec.rb +0 -3
  50. data/spec/active_interaction/integration/symbol_interaction_spec.rb +0 -3
  51. data/spec/active_interaction/integration/time_interaction_spec.rb +0 -86
  52. data/spec/active_interaction/modules/validation_spec.rb +0 -55
  53. data/spec/spec_helper.rb +0 -22
  54. data/spec/support/concerns.rb +0 -13
  55. data/spec/support/filters.rb +0 -227
  56. data/spec/support/interactions.rb +0 -124
@@ -1,187 +0,0 @@
1
- RSpec.describe ActiveInteraction::DateTimeFilter, :filter do
2
- include_context 'filters'
3
- it_behaves_like 'a filter'
4
-
5
- shared_context 'with format' do
6
- let(:format) { '%d/%m/%Y %H:%M:%S %:z' }
7
-
8
- before do
9
- options[:format] = format
10
- end
11
- end
12
-
13
- describe '#process' do
14
- let(:result) { filter.process(value, nil) }
15
-
16
- context 'with a Datetime' do
17
- let(:value) { DateTime.new }
18
-
19
- it 'returns the DateTime' do
20
- expect(result.value).to eql value
21
- end
22
- end
23
-
24
- context 'with a String' do
25
- let(:value) { '2011-12-13T14:15:16+17:18' }
26
-
27
- it 'returns a DateTime' do
28
- expect(result.value).to eql DateTime.parse(value)
29
- end
30
-
31
- context 'with format' do
32
- include_context 'with format'
33
-
34
- let(:value) { '13/12/2011 14:15:16 +17:18' }
35
-
36
- it 'returns a DateTime' do
37
- expect(result.value).to eql DateTime.strptime(value, format)
38
- end
39
- end
40
- end
41
-
42
- context 'with an invalid String' do
43
- let(:value) { 'invalid' }
44
-
45
- it 'indicates an error' do
46
- error = result.errors.first
47
-
48
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
49
- expect(error.type).to be :invalid_type
50
- end
51
-
52
- context 'with format' do
53
- include_context 'with format'
54
-
55
- it 'indicates an error' do
56
- error = result.errors.first
57
-
58
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
59
- expect(error.type).to be :invalid_type
60
- end
61
- end
62
- end
63
-
64
- context 'with an implicit String' do
65
- let(:value) do
66
- Class.new do
67
- def to_str
68
- '2011-12-13T14:15:16+17:18'
69
- end
70
- end.new
71
- end
72
-
73
- it 'returns a DateTime' do
74
- expect(result.value).to eql DateTime.parse(value)
75
- end
76
- end
77
-
78
- context 'with a blank String' do
79
- let(:value) do
80
- Class.new do
81
- def to_str
82
- ' '
83
- end
84
- end.new
85
- end
86
-
87
- context 'optional' do
88
- include_context 'optional'
89
-
90
- it 'returns the default' do
91
- expect(result.value).to eql options[:default]
92
- end
93
- end
94
-
95
- context 'required' do
96
- include_context 'required'
97
-
98
- it 'indicates an error' do
99
- error = result.errors.first
100
-
101
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
102
- expect(error.type).to be :missing
103
- end
104
- end
105
- end
106
-
107
- context 'with a GroupedInput' do
108
- let(:year) { 2012 }
109
- let(:month) { 1 }
110
- let(:day) { 2 }
111
- let(:hour) { 3 }
112
- let(:min) { 4 }
113
- let(:sec) { 5 }
114
- let(:value) do
115
- ActiveInteraction::GroupedInput.new(
116
- '1' => year.to_s,
117
- '2' => month.to_s,
118
- '3' => day.to_s,
119
- '4' => hour.to_s,
120
- '5' => min.to_s,
121
- '6' => sec.to_s
122
- )
123
- end
124
-
125
- it 'returns a DateTime' do
126
- expect(
127
- result.value
128
- ).to eql DateTime.new(year, month, day, hour, min, sec)
129
- end
130
- end
131
-
132
- context 'with an invalid GroupedInput' do
133
- context 'empty' do
134
- let(:value) { ActiveInteraction::GroupedInput.new }
135
-
136
- it 'indicates an error' do
137
- error = result.errors.first
138
-
139
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
140
- expect(error.type).to be :invalid_type
141
- end
142
- end
143
-
144
- context 'partial inputs' do
145
- let(:value) do
146
- ActiveInteraction::GroupedInput.new(
147
- '2' => '1'
148
- )
149
- end
150
-
151
- it 'indicates an error' do
152
- error = result.errors.first
153
-
154
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
155
- expect(error.type).to be :invalid_type
156
- end
157
- end
158
- end
159
- end
160
-
161
- describe '#database_column_type' do
162
- it 'returns :datetime' do
163
- expect(filter.database_column_type).to be :datetime
164
- end
165
- end
166
-
167
- describe '#default' do
168
- context 'with a GroupedInput' do
169
- before do
170
- options[:default] = ActiveInteraction::GroupedInput.new(
171
- '1' => '2012',
172
- '2' => '1',
173
- '3' => '2',
174
- '4' => '3',
175
- '5' => '4',
176
- '6' => '5'
177
- )
178
- end
179
-
180
- it 'raises an error' do
181
- expect do
182
- filter.default(nil)
183
- end.to raise_error ActiveInteraction::InvalidDefaultError
184
- end
185
- end
186
- end
187
- end
@@ -1,124 +0,0 @@
1
- RSpec.describe ActiveInteraction::DecimalFilter, :filter do
2
- include_context 'filters'
3
- it_behaves_like 'a filter'
4
-
5
- shared_context 'with digits' do
6
- let(:digits) { 4 }
7
-
8
- before do
9
- options[:digits] = digits
10
- end
11
- end
12
-
13
- describe '#process' do
14
- let(:result) { filter.process(value, nil) }
15
-
16
- context 'with a Float' do
17
- let(:value) { rand }
18
-
19
- it 'returns the BigDecimal' do
20
- expect(result.value).to eql BigDecimal(value, 0)
21
- end
22
-
23
- context 'with :digits option' do
24
- include_context 'with digits'
25
-
26
- let(:value) { 1.23456789 }
27
-
28
- it 'returns BigDecimal with given digits' do
29
- expect(result.value).to eql BigDecimal('1.235')
30
- end
31
- end
32
- end
33
-
34
- context 'with an implicit Integer' do
35
- let(:value) do
36
- Class.new do
37
- def to_int
38
- @to_int ||= rand(1 << 16)
39
- end
40
- end.new
41
- end
42
-
43
- it 'returns a BigDecimal' do
44
- expect(result.value).to eql BigDecimal(value.to_int)
45
- end
46
- end
47
-
48
- context 'with a Numeric' do
49
- let(:value) { rand(1 << 16) }
50
-
51
- it 'returns a BigDecimal' do
52
- expect(result.value).to eql BigDecimal(value)
53
- end
54
- end
55
-
56
- context 'with a String' do
57
- let(:value) { rand.to_s }
58
-
59
- it 'returns a BigDecimal' do
60
- expect(result.value).to eql BigDecimal(value)
61
- end
62
- end
63
-
64
- context 'with an invalid String' do
65
- let(:value) { 'invalid' }
66
-
67
- it 'indicates an error' do
68
- error = result.errors.first
69
-
70
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
71
- expect(error.type).to be :invalid_type
72
- end
73
- end
74
-
75
- context 'with an implicit String' do
76
- let(:value) do
77
- Class.new do
78
- def to_str
79
- '1.1'
80
- end
81
- end.new
82
- end
83
-
84
- it 'returns a BigDecimal' do
85
- expect(result.value).to eql BigDecimal(value)
86
- end
87
- end
88
-
89
- context 'with a blank String' do
90
- let(:value) do
91
- Class.new do
92
- def to_str
93
- ' '
94
- end
95
- end.new
96
- end
97
-
98
- context 'optional' do
99
- include_context 'optional'
100
-
101
- it 'returns the default' do
102
- expect(result.value).to eql options[:default]
103
- end
104
- end
105
-
106
- context 'required' do
107
- include_context 'required'
108
-
109
- it 'indicates an error' do
110
- error = result.errors.first
111
-
112
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
113
- expect(error.type).to be :missing
114
- end
115
- end
116
- end
117
- end
118
-
119
- describe '#database_column_type' do
120
- it 'returns :decimal' do
121
- expect(filter.database_column_type).to be :decimal
122
- end
123
- end
124
- end
@@ -1,38 +0,0 @@
1
- RSpec.describe ActiveInteraction::FileFilter, :filter do
2
- include_context 'filters'
3
- it_behaves_like 'a filter'
4
-
5
- describe '#process' do
6
- let(:result) { filter.process(value, nil) }
7
-
8
- context 'with a File' do
9
- let(:value) { File.new(__FILE__) }
10
-
11
- it 'returns the File' do
12
- expect(result.value).to eql value
13
- end
14
- end
15
-
16
- context 'with a Tempfile' do
17
- let(:value) { Tempfile.new(SecureRandom.hex) }
18
-
19
- it 'returns the Tempfile' do
20
- expect(result.value).to eq value
21
- end
22
- end
23
-
24
- context 'with an object that responds to #rewind' do
25
- let(:value) { double(rewind: nil) } # rubocop:disable RSpec/VerifiedDoubles
26
-
27
- it 'returns the object' do
28
- expect(result.value).to eq value
29
- end
30
- end
31
- end
32
-
33
- describe '#database_column_type' do
34
- it 'returns :file' do
35
- expect(filter.database_column_type).to be :file
36
- end
37
- end
38
- end
@@ -1,109 +0,0 @@
1
- require 'bigdecimal'
2
-
3
- RSpec.describe ActiveInteraction::FloatFilter, :filter do
4
- include_context 'filters'
5
- it_behaves_like 'a filter'
6
-
7
- describe '#process' do
8
- let(:result) { filter.process(value, nil) }
9
-
10
- context 'with a Float' do
11
- let(:value) { rand }
12
-
13
- it 'returns the Float' do
14
- expect(result.value).to eql value
15
- end
16
- end
17
-
18
- context 'with an implicit Integer' do
19
- let(:value) do
20
- Class.new do
21
- def to_int
22
- @to_int ||= rand(1 << 16)
23
- end
24
- end.new
25
- end
26
-
27
- it 'returns a Float' do
28
- expect(result.value).to eql value.to_int.to_f
29
- end
30
- end
31
-
32
- context 'with a Numeric' do
33
- let(:value) { BigDecimal('1.2') }
34
-
35
- it 'returns a Float' do
36
- expect(result.value).to eql value.to_f
37
- end
38
- end
39
-
40
- context 'with a String' do
41
- let(:value) { rand.to_s }
42
-
43
- it 'returns a Float' do
44
- expect(result.value).to eql Float(value)
45
- end
46
- end
47
-
48
- context 'with an invalid String' do
49
- let(:value) { 'invalid' }
50
-
51
- it 'indicates an error' do
52
- error = result.errors.first
53
-
54
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
55
- expect(error.type).to be :invalid_type
56
- end
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.value).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.value).to eql options[:default]
88
- end
89
- end
90
-
91
- context 'required' do
92
- include_context 'required'
93
-
94
- it 'indicates an error' do
95
- error = result.errors.first
96
-
97
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
98
- expect(error.type).to be :missing
99
- end
100
- end
101
- end
102
- end
103
-
104
- describe '#database_column_type' do
105
- it 'returns :float' do
106
- expect(filter.database_column_type).to be :float
107
- end
108
- end
109
- end
@@ -1,127 +0,0 @@
1
- RSpec.describe ActiveInteraction::HashFilter, :filter do
2
- include_context 'filters'
3
- it_behaves_like 'a filter'
4
-
5
- context 'with a nested nameless filter' do
6
- let(:block) { proc { hash } }
7
-
8
- it 'raises an error' do
9
- expect { filter }.to raise_error ActiveInteraction::InvalidFilterError
10
- end
11
- end
12
-
13
- describe '#process' do
14
- let(:result) { filter.process(value, nil) }
15
-
16
- context 'with a Hash' do
17
- let(:value) { {} }
18
-
19
- it 'returns the Hash' do
20
- expect(result.value).to eql value
21
- expect(result.value).to be_an_instance_of HashWithIndifferentAccess
22
- end
23
- end
24
-
25
- context 'with an implicit Hash' do
26
- let(:value) do
27
- Class.new do
28
- def to_hash
29
- {}
30
- end
31
- end.new
32
- end
33
-
34
- it 'returns the Hash' do
35
- expect(result.value).to eql value.to_hash
36
- end
37
- end
38
-
39
- context 'with a non-empty Hash' do
40
- let(:value) { { a: {} } }
41
-
42
- it 'returns an empty Hash' do
43
- expect(result.value).to eql({})
44
- end
45
- end
46
-
47
- context 'with a nested filter' do
48
- let(:block) { proc { hash :a } }
49
-
50
- context 'with a Hash' do
51
- let(:value) { { 'a' => {} } }
52
-
53
- it 'returns the Hash' do
54
- expect(result.value).to eql value
55
- expect(result.value).to be_an_instance_of HashWithIndifferentAccess
56
- end
57
-
58
- context 'with String keys' do
59
- before do
60
- value.stringify_keys!
61
- end
62
-
63
- it 'does not raise an error' do
64
- expect { result }.to_not raise_error
65
- end
66
- end
67
- end
68
-
69
- context 'without a Hash' do
70
- let(:k) { 'a' }
71
- let(:v) { double }
72
- let(:value) { { k => v } }
73
-
74
- it 'indicates an error' do
75
- error = result.errors.first
76
-
77
- expect(result.errors.size).to be 1
78
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
79
- expect(error.name).to be :"#{filter.name}.#{error.filter.name}"
80
- expect(error.type).to be :invalid_type
81
- end
82
- end
83
- end
84
-
85
- context 'with :strip false' do
86
- let(:options) { { strip: false } }
87
-
88
- context 'with a non-empty Hash' do
89
- let(:value) { { 'a' => {} } }
90
-
91
- it 'returns an empty Hash' do
92
- expect(result.value).to eql value
93
- end
94
- end
95
- end
96
- end
97
-
98
- describe '#default' do
99
- context 'with a Hash' do
100
- before do
101
- options[:default] = {}
102
- end
103
-
104
- it 'returns the Hash' do
105
- expect(filter.default(nil)).to eql options[:default]
106
- end
107
- end
108
-
109
- context 'with a non-empty Hash' do
110
- before do
111
- options[:default] = { a: {} }
112
- end
113
-
114
- it 'raises an error' do
115
- expect do
116
- filter.default(nil)
117
- end.to raise_error ActiveInteraction::InvalidDefaultError
118
- end
119
- end
120
- end
121
-
122
- describe '#database_column_type' do
123
- it 'returns :string' do
124
- expect(filter.database_column_type).to be :string
125
- end
126
- end
127
- end
@@ -1,102 +0,0 @@
1
- RSpec.describe ActiveInteraction::IntegerFilter, :filter do
2
- include_context 'filters'
3
- it_behaves_like 'a filter'
4
-
5
- describe '#process' do
6
- let(:result) { filter.process(value, nil) }
7
-
8
- context 'with an Integer' do
9
- let(:value) { rand(1 << 16) }
10
-
11
- it 'returns the Integer' do
12
- expect(result.value).to eql value
13
- end
14
- end
15
-
16
- context 'with a Numeric' do
17
- let(:value) { rand(1 << 16) + rand }
18
-
19
- it 'returns an Integer' do
20
- expect(result.value).to eql value.to_i
21
- end
22
- end
23
-
24
- context 'with a String' do
25
- let(:value) { rand(1 << 16).to_s }
26
-
27
- it 'returns an Integer' do
28
- expect(result.value).to eql Integer(value, 10)
29
- end
30
- end
31
-
32
- context 'with an invalid String' do
33
- let(:value) { 'invalid' }
34
-
35
- it 'indicates an error' do
36
- error = result.errors.first
37
-
38
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
39
- expect(error.type).to be :invalid_type
40
- end
41
- end
42
-
43
- context 'with an implicit String' do
44
- let(:value) do
45
- Class.new do
46
- def to_str
47
- '1'
48
- end
49
- end.new
50
- end
51
-
52
- it 'returns an Integer' do
53
- expect(result.value).to eql Integer(value.to_str, 10)
54
- end
55
- end
56
-
57
- context 'with a blank String' do
58
- let(:value) do
59
- Class.new do
60
- def to_str
61
- ' '
62
- end
63
- end.new
64
- end
65
-
66
- context 'optional' do
67
- include_context 'optional'
68
-
69
- it 'returns the default' do
70
- expect(result.value).to eql options[:default]
71
- end
72
- end
73
-
74
- context 'required' do
75
- include_context 'required'
76
-
77
- it 'indicates an error' do
78
- error = result.errors.first
79
-
80
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
81
- expect(error.type).to be :missing
82
- end
83
- end
84
- end
85
-
86
- it 'supports different bases' do
87
- expect(
88
- described_class.new(name, base: 8).process('071', nil).value
89
- ).to be 57
90
- error = described_class.new(name, base: 8).process('081', nil).errors.first
91
-
92
- expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
93
- expect(error.type).to be :invalid_type
94
- end
95
- end
96
-
97
- describe '#database_column_type' do
98
- it 'returns :integer' do
99
- expect(filter.database_column_type).to be :integer
100
- end
101
- end
102
- end