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