active_interaction 4.0.6 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +156 -7
  3. data/CONTRIBUTING.md +11 -3
  4. data/README.md +260 -219
  5. data/lib/active_interaction/array_input.rb +77 -0
  6. data/lib/active_interaction/base.rb +14 -98
  7. data/lib/active_interaction/concerns/active_recordable.rb +3 -3
  8. data/lib/active_interaction/concerns/missable.rb +2 -2
  9. data/lib/active_interaction/errors.rb +6 -88
  10. data/lib/active_interaction/exceptions.rb +47 -0
  11. data/lib/active_interaction/filter/column.rb +59 -0
  12. data/lib/active_interaction/filter/error.rb +40 -0
  13. data/lib/active_interaction/filter.rb +44 -53
  14. data/lib/active_interaction/filters/abstract_date_time_filter.rb +9 -6
  15. data/lib/active_interaction/filters/abstract_numeric_filter.rb +7 -3
  16. data/lib/active_interaction/filters/array_filter.rb +40 -6
  17. data/lib/active_interaction/filters/boolean_filter.rb +4 -3
  18. data/lib/active_interaction/filters/date_filter.rb +1 -1
  19. data/lib/active_interaction/filters/date_time_filter.rb +1 -1
  20. data/lib/active_interaction/filters/decimal_filter.rb +1 -1
  21. data/lib/active_interaction/filters/float_filter.rb +1 -1
  22. data/lib/active_interaction/filters/hash_filter.rb +23 -15
  23. data/lib/active_interaction/filters/integer_filter.rb +1 -1
  24. data/lib/active_interaction/filters/interface_filter.rb +12 -12
  25. data/lib/active_interaction/filters/object_filter.rb +9 -3
  26. data/lib/active_interaction/filters/record_filter.rb +21 -11
  27. data/lib/active_interaction/filters/string_filter.rb +1 -1
  28. data/lib/active_interaction/filters/symbol_filter.rb +1 -1
  29. data/lib/active_interaction/filters/time_filter.rb +4 -4
  30. data/lib/active_interaction/hash_input.rb +43 -0
  31. data/lib/active_interaction/input.rb +23 -0
  32. data/lib/active_interaction/inputs.rb +161 -46
  33. data/lib/active_interaction/locale/en.yml +0 -1
  34. data/lib/active_interaction/locale/fr.yml +0 -1
  35. data/lib/active_interaction/locale/it.yml +0 -1
  36. data/lib/active_interaction/locale/ja.yml +0 -1
  37. data/lib/active_interaction/locale/pt-BR.yml +0 -1
  38. data/lib/active_interaction/modules/validation.rb +6 -17
  39. data/lib/active_interaction/version.rb +1 -1
  40. data/lib/active_interaction.rb +41 -36
  41. data/spec/active_interaction/array_input_spec.rb +166 -0
  42. data/spec/active_interaction/base_spec.rb +34 -248
  43. data/spec/active_interaction/concerns/active_modelable_spec.rb +3 -3
  44. data/spec/active_interaction/concerns/active_recordable_spec.rb +7 -7
  45. data/spec/active_interaction/concerns/hashable_spec.rb +8 -8
  46. data/spec/active_interaction/concerns/missable_spec.rb +9 -9
  47. data/spec/active_interaction/concerns/runnable_spec.rb +34 -32
  48. data/spec/active_interaction/errors_spec.rb +60 -43
  49. data/spec/active_interaction/{filter_column_spec.rb → filter/column_spec.rb} +3 -10
  50. data/spec/active_interaction/filter_spec.rb +6 -6
  51. data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +2 -2
  52. data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +2 -2
  53. data/spec/active_interaction/filters/array_filter_spec.rb +109 -16
  54. data/spec/active_interaction/filters/boolean_filter_spec.rb +12 -11
  55. data/spec/active_interaction/filters/date_filter_spec.rb +32 -27
  56. data/spec/active_interaction/filters/date_time_filter_spec.rb +34 -29
  57. data/spec/active_interaction/filters/decimal_filter_spec.rb +20 -18
  58. data/spec/active_interaction/filters/file_filter_spec.rb +7 -7
  59. data/spec/active_interaction/filters/float_filter_spec.rb +19 -17
  60. data/spec/active_interaction/filters/hash_filter_spec.rb +16 -18
  61. data/spec/active_interaction/filters/integer_filter_spec.rb +24 -22
  62. data/spec/active_interaction/filters/interface_filter_spec.rb +105 -82
  63. data/spec/active_interaction/filters/object_filter_spec.rb +52 -36
  64. data/spec/active_interaction/filters/record_filter_spec.rb +61 -39
  65. data/spec/active_interaction/filters/string_filter_spec.rb +7 -7
  66. data/spec/active_interaction/filters/symbol_filter_spec.rb +6 -6
  67. data/spec/active_interaction/filters/time_filter_spec.rb +57 -34
  68. data/spec/active_interaction/hash_input_spec.rb +58 -0
  69. data/spec/active_interaction/i18n_spec.rb +22 -17
  70. data/spec/active_interaction/inputs_spec.rb +170 -18
  71. data/spec/active_interaction/integration/array_interaction_spec.rb +3 -7
  72. data/spec/active_interaction/integration/record_integration_spec.rb +5 -0
  73. data/spec/active_interaction/modules/validation_spec.rb +8 -31
  74. data/spec/spec_helper.rb +9 -0
  75. data/spec/support/concerns.rb +2 -2
  76. data/spec/support/filters.rb +27 -51
  77. data/spec/support/interactions.rb +4 -4
  78. metadata +50 -50
  79. data/lib/active_interaction/filter_column.rb +0 -57
@@ -1,22 +1,19 @@
1
1
  require 'spec_helper'
2
2
  require 'active_record'
3
- unless defined?(JRUBY_VERSION) # rubocop:disable Style/IfUnlessModifier
4
- require 'sqlite3'
5
- end
3
+ require 'sqlite3'
6
4
 
7
- unless defined?(JRUBY_VERSION)
8
- ActiveRecord::Base.establish_connection(
9
- adapter: 'sqlite3',
10
- database: ':memory:'
11
- )
12
- end
5
+ ActiveRecord::Base.establish_connection(
6
+ adapter: 'sqlite3',
7
+ database: ':memory:'
8
+ )
13
9
 
14
10
  describe ActiveInteraction::Errors do
15
- let(:klass) do
16
- Class.new do
17
- include ActiveInteraction::ActiveModelable
11
+ subject(:errors) { described_class.new(klass.new) }
18
12
 
19
- attr_reader :attribute
13
+ let(:klass) do
14
+ Class.new(ActiveInteraction::Base) do
15
+ string :attribute, defualt: nil
16
+ array :array, defualt: nil
20
17
 
21
18
  def self.name
22
19
  @name ||= SecureRandom.hex
@@ -24,8 +21,6 @@ describe ActiveInteraction::Errors do
24
21
  end
25
22
  end
26
23
 
27
- subject(:errors) { described_class.new(klass.new) }
28
-
29
24
  describe '#merge!' do
30
25
  let(:other) { described_class.new(klass.new) }
31
26
 
@@ -124,6 +119,25 @@ describe ActiveInteraction::Errors do
124
119
  end
125
120
  end
126
121
 
122
+ context 'with nested index errors' do
123
+ let(:other) { described_class.new(klass.new) }
124
+
125
+ before do
126
+ if ActiveRecord.respond_to?(:index_nested_attribute_errors)
127
+ allow(ActiveRecord).to receive(:index_nested_attribute_errors).and_return(true)
128
+ else
129
+ allow(ActiveRecord::Base).to receive(:index_nested_attribute_errors).and_return(true)
130
+ end
131
+
132
+ other.add(:'array[0]')
133
+ end
134
+
135
+ it 'adds the error' do
136
+ errors.merge!(other)
137
+ expect(errors.messages[:'array[0]']).to eql ['is invalid']
138
+ end
139
+ end
140
+
127
141
  context 'with ActiveModel errors' do
128
142
  let(:other) { ActiveModel::Errors.new(klass.new) }
129
143
 
@@ -139,40 +153,43 @@ describe ActiveInteraction::Errors do
139
153
  end
140
154
  end
141
155
 
142
- unless defined?(JRUBY_VERSION)
143
- context 'with nested errors' do
144
- before do
145
- # suppress create_table output
146
- allow($stdout).to receive(:puts)
147
- ActiveRecord::Schema.define do
148
- create_table(:as)
149
- create_table(:bs) do |t|
150
- t.column :a_id, :integer
151
- t.column :name, :string
152
- end
153
- end
154
-
155
- class A < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
156
- has_one :b
157
- accepts_nested_attributes_for :b
158
- end
156
+ context 'with nested errors' do
157
+ let(:a_klass) do
158
+ Class.new(ActiveRecord::Base) do
159
+ has_one :b
160
+ accepts_nested_attributes_for :b
161
+ end
162
+ end
163
+ let(:a) { A.create(b_attributes: { name: nil }) }
164
+ let(:b_klass) do
165
+ Class.new(ActiveRecord::Base) do
166
+ belongs_to :a
159
167
 
160
- class B < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
161
- belongs_to :a
168
+ validates :name, presence: true
169
+ end
170
+ end
162
171
 
163
- validates :name, presence: true
172
+ before do
173
+ # suppress create_table output
174
+ allow($stdout).to receive(:puts)
175
+ ActiveRecord::Schema.define do
176
+ create_table(:as)
177
+ create_table(:bs) do |t|
178
+ t.column :a_id, :integer
179
+ t.column :name, :string
164
180
  end
165
181
  end
166
182
 
167
- let(:a) { A.create(b_attributes: { name: nil }) }
183
+ stub_const('A', a_klass)
184
+ stub_const('B', b_klass)
185
+ end
168
186
 
169
- it 'merges the nested errors' do
170
- a.valid?
171
- expect(a.errors.messages).to eq('b.name': ["can't be blank"])
172
- expect(a.errors.size).to eql 1
173
- expect { errors.merge!(a.errors) }.to_not raise_error
174
- expect(errors.size).to eql 1
175
- end
187
+ it 'merges the nested errors' do
188
+ a.valid?
189
+ expect(a.errors.messages).to eq('b.name': ["can't be blank"])
190
+ expect(a.errors.size).to be 1
191
+ expect { errors.merge!(a.errors) }.to_not raise_error
192
+ expect(errors.size).to be 1
176
193
  end
177
194
  end
178
195
  end
@@ -1,9 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveInteraction::FilterColumn do
4
- let(:type) { :float }
3
+ describe ActiveInteraction::Filter::Column do
5
4
  subject(:column) { described_class.intern(type) }
6
5
 
6
+ let(:type) { :float }
7
+
7
8
  describe '.intern(type)' do
8
9
  it 'returns the same object for each type' do
9
10
  expect(described_class.intern(type)).to equal column
@@ -83,12 +84,4 @@ describe ActiveInteraction::FilterColumn do
83
84
  end
84
85
  end
85
86
  end
86
-
87
- describe '#type' do
88
- let(:type) { :float }
89
-
90
- it 'returns the type' do
91
- expect(column.type).to eql type
92
- end
93
- end
94
87
  end
@@ -5,30 +5,30 @@ describe ActiveInteraction::Filter, :filter do
5
5
 
6
6
  describe '#database_column_type' do
7
7
  it 'returns `:string`' do
8
- expect(subject.database_column_type).to eql :string
8
+ expect(filter.database_column_type).to be :string
9
9
  end
10
10
  end
11
11
 
12
12
  context 'with an unregistered subclass' do
13
- let(:described_class) { Class.new(ActiveInteraction::Filter) }
13
+ let(:klass) { Class.new(described_class) }
14
14
 
15
15
  describe '.slug' do
16
16
  it 'is nil' do
17
- expect(described_class.slug).to be_nil
17
+ expect(klass.slug).to be_nil
18
18
  end
19
19
  end
20
20
  end
21
21
 
22
22
  context 'with a registered subclass' do
23
- it_behaves_like 'a filter'
24
-
23
+ let(:slug) { SecureRandom.hex.to_sym }
25
24
  let(:described_class) do
26
25
  s = slug
27
26
  Class.new(ActiveInteraction::Filter) do
28
27
  register s
29
28
  end
30
29
  end
31
- let(:slug) { SecureRandom.hex.to_sym }
30
+
31
+ it_behaves_like 'a filter'
32
32
 
33
33
  describe '.slug' do
34
34
  it 'returns the registered slug' do
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe ActiveInteraction::AbstractDateTimeFilter, :filter do
4
4
  include_context 'filters'
5
5
 
6
- describe '#cast' do
6
+ describe '#process' do
7
7
  let(:value) { nil }
8
8
 
9
9
  it 'raises an error' do
10
- expect { filter.send(:cast, value, nil) }.to raise_error NameError
10
+ expect { filter.process(value, nil) }.to raise_error NameError
11
11
  end
12
12
  end
13
13
  end
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe ActiveInteraction::AbstractNumericFilter, :filter do
4
4
  include_context 'filters'
5
5
 
6
- describe '#cast' do
6
+ describe '#process' do
7
7
  let(:value) { nil }
8
8
 
9
9
  it 'raises an error' do
10
- expect { filter.send(:cast, value, nil) }.to raise_error NameError
10
+ expect { filter.process(value, nil) }.to raise_error NameError
11
11
  end
12
12
  end
13
13
  end
@@ -25,14 +25,22 @@ describe ActiveInteraction::ArrayFilter, :filter do
25
25
  end
26
26
  end
27
27
 
28
- describe '#cast' do
29
- let(:result) { filter.send(:cast, value, nil) }
28
+ describe '#process' do
29
+ let(:result) { filter.process(value, nil) }
30
30
 
31
31
  context 'with an Array' do
32
32
  let(:value) { [] }
33
33
 
34
+ it 'returns an ArrayInput' do
35
+ expect(result).to be_an_instance_of ActiveInteraction::ArrayInput
36
+ end
37
+
34
38
  it 'returns the Array' do
35
- expect(result).to eql value
39
+ expect(result.value).to eql value
40
+ end
41
+
42
+ it 'has no children' do
43
+ expect(result.children).to eql []
36
44
  end
37
45
  end
38
46
 
@@ -46,7 +54,7 @@ describe ActiveInteraction::ArrayFilter, :filter do
46
54
  end
47
55
 
48
56
  it 'returns the Array' do
49
- expect(result).to eql value.to_ary
57
+ expect(result.value).to eql value.to_ary
50
58
  end
51
59
  end
52
60
 
@@ -54,7 +62,17 @@ describe ActiveInteraction::ArrayFilter, :filter do
54
62
  let(:value) { [[], false, 0.0, {}, 0, '', :''] }
55
63
 
56
64
  it 'returns the Array' do
57
- expect(result).to eql value
65
+ expect(result.value).to eql value
66
+ end
67
+ end
68
+
69
+ context 'with a nested filter where the value transforms' do
70
+ let(:block) { proc { symbol } }
71
+ let(:name) { :test }
72
+ let(:value) { ['test'] }
73
+
74
+ it 'returns the transformed value' do
75
+ expect(result.value).to eql [:test]
58
76
  end
59
77
  end
60
78
 
@@ -62,10 +80,31 @@ describe ActiveInteraction::ArrayFilter, :filter do
62
80
  let(:block) { proc { array } }
63
81
 
64
82
  context 'with an Array' do
65
- let(:value) { [] }
83
+ let(:child_value) { [] }
84
+ let(:value) { [child_value, child_value] }
66
85
 
67
86
  it 'returns the Array' do
68
- expect(result).to eql value
87
+ expect(result.value).to eql value
88
+ end
89
+
90
+ it 'has children' do
91
+ expect(result.children.size).to be 2
92
+ result.children.each do |child|
93
+ expect(child).to be_an_instance_of ActiveInteraction::ArrayInput
94
+ expect(child.value).to eql child_value
95
+ end
96
+ end
97
+
98
+ context 'given a nil value' do
99
+ let(:value) { nil }
100
+
101
+ it 'returns an error' do
102
+ error = result.errors.first
103
+
104
+ expect(result.value).to eql value
105
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
106
+ expect(error.type).to be :missing
107
+ end
69
108
  end
70
109
  end
71
110
 
@@ -73,17 +112,71 @@ describe ActiveInteraction::ArrayFilter, :filter do
73
112
  let(:value) { [[]] }
74
113
 
75
114
  it 'returns the Array' do
76
- expect(result).to eql value
115
+ expect(result.value).to eql value
77
116
  end
78
117
  end
79
118
 
80
119
  context 'with a heterogenous Array' do
81
- let(:value) { [[], false, 0.0, {}, 0, '', :''] }
120
+ let(:value) { [[], false, 0.0] }
121
+
122
+ it 'indicates an error' do
123
+ error = result.errors.first
82
124
 
83
- it 'raises an error' do
84
- expect do
85
- result
86
- end.to raise_error ActiveInteraction::InvalidValueError
125
+ expect(result.errors.size).to be 1
126
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
127
+ expect(error.name).to be filter.name
128
+ expect(error.type).to be :invalid_type
129
+ end
130
+
131
+ context 'when :index_errors is true' do
132
+ before do
133
+ options[:index_errors] = true
134
+ end
135
+
136
+ it 'shows the index of where the error occurred' do
137
+ expect(result.errors.size).to be 2
138
+
139
+ result.errors.each.with_index(1) do |error, i|
140
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
141
+ expect(error.name).to be :"#{filter.name}[#{i}]"
142
+ expect(error.type).to be :invalid_type
143
+ end
144
+ end
145
+ end
146
+
147
+ context 'when ActiveRecord.index_nested_attribute_errors is true' do
148
+ before do
149
+ if ActiveRecord.respond_to?(:index_nested_attribute_errors)
150
+ allow(ActiveRecord).to receive(:index_nested_attribute_errors).and_return(true)
151
+ else
152
+ allow(ActiveRecord::Base).to receive(:index_nested_attribute_errors).and_return(true)
153
+ end
154
+ end
155
+
156
+ it 'shows the index of where the error occurred' do
157
+ expect(result.errors.size).to be 2
158
+
159
+ result.errors.each.with_index(1) do |error, i|
160
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
161
+ expect(error.name).to be :"#{filter.name}[#{i}]"
162
+ expect(error.type).to be :invalid_type
163
+ end
164
+ end
165
+
166
+ context 'when :index_errors is false' do
167
+ before do
168
+ options[:index_errors] = false
169
+ end
170
+
171
+ it 'does not attach the index' do
172
+ error = result.errors.first
173
+
174
+ expect(result.errors.size).to be 1
175
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
176
+ expect(error.name).to be filter.name
177
+ expect(error.type).to be :invalid_type
178
+ end
179
+ end
87
180
  end
88
181
  end
89
182
  end
@@ -136,9 +229,9 @@ describe ActiveInteraction::ArrayFilter, :filter do
136
229
 
137
230
  it 'has a filter with the right options' do
138
231
  expect(filter.filters[:'0'].options).to have_key(:class)
139
- expect(filter.filters[:'0'].options[:class]).to eql :Object
232
+ expect(filter.filters[:'0'].options[:class]).to be :Object
140
233
  expect(filter.filters[:'0'].options).to have_key(:converter)
141
- expect(filter.filters[:'0'].options[:converter]).to eql :new
234
+ expect(filter.filters[:'0'].options[:converter]).to be :new
142
235
  end
143
236
  end
144
237
  end
@@ -146,7 +239,7 @@ describe ActiveInteraction::ArrayFilter, :filter do
146
239
 
147
240
  describe '#database_column_type' do
148
241
  it 'returns :string' do
149
- expect(filter.database_column_type).to eql :string
242
+ expect(filter.database_column_type).to be :string
150
243
  end
151
244
  end
152
245
  end
@@ -4,11 +4,11 @@ describe ActiveInteraction::BooleanFilter, :filter do
4
4
  include_context 'filters'
5
5
  it_behaves_like 'a filter'
6
6
 
7
- describe '#cast' do
7
+ describe '#process' do
8
8
  context 'falsey' do
9
9
  [false, '0', 'false', 'FALSE', 'off', 'OFF'].each do |value|
10
10
  it "returns false for #{value.inspect}" do
11
- expect(filter.send(:cast, value, nil)).to be_falsey
11
+ expect(filter.process(value, nil).value).to be_falsey
12
12
  end
13
13
  end
14
14
 
@@ -22,7 +22,7 @@ describe ActiveInteraction::BooleanFilter, :filter do
22
22
  end
23
23
 
24
24
  it 'returns false' do
25
- expect(filter.send(:cast, value, nil)).to be_falsey
25
+ expect(filter.process(value, nil).value).to be_falsey
26
26
  end
27
27
  end
28
28
  end
@@ -30,7 +30,7 @@ describe ActiveInteraction::BooleanFilter, :filter do
30
30
  context 'truthy' do
31
31
  [true, '1', 'true', 'TRUE', 'on', 'ON'].each do |value|
32
32
  it "returns true for #{value.inspect}" do
33
- expect(filter.send(:cast, value, nil)).to be_truthy
33
+ expect(filter.process(value, nil).value).to be_truthy
34
34
  end
35
35
  end
36
36
 
@@ -44,7 +44,7 @@ describe ActiveInteraction::BooleanFilter, :filter do
44
44
  end
45
45
 
46
46
  it 'returns true' do
47
- expect(filter.send(:cast, value, nil)).to be_truthy
47
+ expect(filter.process(value, nil).value).to be_truthy
48
48
  end
49
49
  end
50
50
  end
@@ -62,17 +62,18 @@ describe ActiveInteraction::BooleanFilter, :filter do
62
62
  include_context 'optional'
63
63
 
64
64
  it 'returns the default' do
65
- expect(filter.send(:cast, value, nil)).to eql options[:default]
65
+ expect(filter.process(value, nil).value).to eql options[:default]
66
66
  end
67
67
  end
68
68
 
69
69
  context 'required' do
70
70
  include_context 'required'
71
71
 
72
- it 'raises an error' do
73
- expect do
74
- filter.send(:cast, value, nil)
75
- end.to raise_error ActiveInteraction::MissingValueError
72
+ it 'indicates an error' do
73
+ error = filter.process(value, nil).errors.first
74
+
75
+ expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
76
+ expect(error.type).to be :missing
76
77
  end
77
78
  end
78
79
  end
@@ -80,7 +81,7 @@ describe ActiveInteraction::BooleanFilter, :filter do
80
81
 
81
82
  describe '#database_column_type' do
82
83
  it 'returns :boolean' do
83
- expect(filter.database_column_type).to eql :boolean
84
+ expect(filter.database_column_type).to be :boolean
84
85
  end
85
86
  end
86
87
  end
@@ -12,14 +12,14 @@ describe ActiveInteraction::DateFilter, :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 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 '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
57
  it 'raises an error' do
57
- expect do
58
- result
59
- end.to raise_error ActiveInteraction::InvalidValueError
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 '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
@@ -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 'raises an error' do
128
- expect do
129
- result
130
- end.to raise_error ActiveInteraction::InvalidValueError
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
- expect do
143
- result
144
- end.to raise_error ActiveInteraction::InvalidValueError
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 eql :date
157
+ expect(filter.database_column_type).to be :date
153
158
  end
154
159
  end
155
160