active_interaction 4.0.5 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +149 -6
- data/README.md +67 -32
- 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 +36 -10
- 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 -24
- 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 +45 -95
- data/lib/active_interaction/filter_column.rb +0 -57
@@ -1,22 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'active_record'
|
3
|
-
|
4
|
-
require 'sqlite3'
|
5
|
-
end
|
3
|
+
require 'sqlite3'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
)
|
12
|
-
end
|
5
|
+
ActiveRecord::Base.establish_connection(
|
6
|
+
adapter: 'sqlite3',
|
7
|
+
database: ':memory:'
|
8
|
+
)
|
13
9
|
|
14
10
|
describe ActiveInteraction::Errors do
|
15
|
-
|
16
|
-
Class.new do
|
17
|
-
include ActiveInteraction::ActiveModelable
|
11
|
+
subject(:errors) { described_class.new(klass.new) }
|
18
12
|
|
19
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
161
|
-
|
168
|
+
validates :name, presence: true
|
169
|
+
end
|
170
|
+
end
|
162
171
|
|
163
|
-
|
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
|
-
|
183
|
+
stub_const('A', a_klass)
|
184
|
+
stub_const('B', b_klass)
|
185
|
+
end
|
168
186
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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::
|
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(
|
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(:
|
13
|
+
let(:klass) { Class.new(described_class) }
|
14
14
|
|
15
15
|
describe '.slug' do
|
16
16
|
it 'is nil' do
|
17
|
-
expect(
|
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
|
-
|
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
|
-
|
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 '#
|
6
|
+
describe '#process' do
|
7
7
|
let(:value) { nil }
|
8
8
|
|
9
9
|
it 'raises an error' do
|
10
|
-
expect { filter.
|
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 '#
|
6
|
+
describe '#process' do
|
7
7
|
let(:value) { nil }
|
8
8
|
|
9
9
|
it 'raises an error' do
|
10
|
-
expect { filter.
|
10
|
+
expect { filter.process(value, nil) }.to raise_error NameError
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -25,22 +25,22 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
let(:
|
30
|
-
|
31
|
-
it 'raises an error' do
|
32
|
-
expect { filter }.to raise_error ActiveInteraction::InvalidDefaultError
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#cast' do
|
37
|
-
let(:result) { filter.send(:cast, value, nil) }
|
28
|
+
describe '#process' do
|
29
|
+
let(:result) { filter.process(value, nil) }
|
38
30
|
|
39
31
|
context 'with an Array' do
|
40
32
|
let(:value) { [] }
|
41
33
|
|
34
|
+
it 'returns an ArrayInput' do
|
35
|
+
expect(result).to be_an_instance_of ActiveInteraction::ArrayInput
|
36
|
+
end
|
37
|
+
|
42
38
|
it 'returns the Array' do
|
43
|
-
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 []
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -54,7 +54,7 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'returns the Array' do
|
57
|
-
expect(result).to eql value.to_ary
|
57
|
+
expect(result.value).to eql value.to_ary
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,7 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
62
62
|
let(:value) { [[], false, 0.0, {}, 0, '', :''] }
|
63
63
|
|
64
64
|
it 'returns the Array' do
|
65
|
-
expect(result).to eql value
|
65
|
+
expect(result.value).to eql value
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,10 +70,31 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
70
70
|
let(:block) { proc { array } }
|
71
71
|
|
72
72
|
context 'with an Array' do
|
73
|
-
let(:
|
73
|
+
let(:child_value) { [] }
|
74
|
+
let(:value) { [child_value, child_value] }
|
74
75
|
|
75
76
|
it 'returns the Array' do
|
76
|
-
expect(result).to eql value
|
77
|
+
expect(result.value).to eql value
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'has children' do
|
81
|
+
expect(result.children.size).to be 2
|
82
|
+
result.children.each do |child|
|
83
|
+
expect(child).to be_an_instance_of ActiveInteraction::ArrayInput
|
84
|
+
expect(child.value).to be child_value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'given a nil value' do
|
89
|
+
let(:value) { nil }
|
90
|
+
|
91
|
+
it 'returns an error' do
|
92
|
+
error = result.errors.first
|
93
|
+
|
94
|
+
expect(result.value).to eql value
|
95
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
96
|
+
expect(error.type).to be :missing
|
97
|
+
end
|
77
98
|
end
|
78
99
|
end
|
79
100
|
|
@@ -81,17 +102,71 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
81
102
|
let(:value) { [[]] }
|
82
103
|
|
83
104
|
it 'returns the Array' do
|
84
|
-
expect(result).to eql value
|
105
|
+
expect(result.value).to eql value
|
85
106
|
end
|
86
107
|
end
|
87
108
|
|
88
109
|
context 'with a heterogenous Array' do
|
89
|
-
let(:value) { [[], false, 0.0
|
110
|
+
let(:value) { [[], false, 0.0] }
|
90
111
|
|
91
|
-
it '
|
92
|
-
|
93
|
-
|
94
|
-
|
112
|
+
it 'indicates an error' do
|
113
|
+
error = result.errors.first
|
114
|
+
|
115
|
+
expect(result.errors.size).to be 1
|
116
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
117
|
+
expect(error.name).to be filter.name
|
118
|
+
expect(error.type).to be :invalid_type
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when :index_errors is true' do
|
122
|
+
before do
|
123
|
+
options[:index_errors] = true
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'shows the index of where the error occurred' do
|
127
|
+
expect(result.errors.size).to be 2
|
128
|
+
|
129
|
+
result.errors.each.with_index(1) do |error, i|
|
130
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
131
|
+
expect(error.name).to be :"#{filter.name}[#{i}]"
|
132
|
+
expect(error.type).to be :invalid_type
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when ActiveRecord.index_nested_attribute_errors is true' do
|
138
|
+
before do
|
139
|
+
if ::ActiveRecord.respond_to?(:index_nested_attribute_errors)
|
140
|
+
allow(::ActiveRecord).to receive(:index_nested_attribute_errors).and_return(true)
|
141
|
+
else
|
142
|
+
allow(::ActiveRecord::Base).to receive(:index_nested_attribute_errors).and_return(true)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'shows the index of where the error occurred' do
|
147
|
+
expect(result.errors.size).to be 2
|
148
|
+
|
149
|
+
result.errors.each.with_index(1) do |error, i|
|
150
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
151
|
+
expect(error.name).to be :"#{filter.name}[#{i}]"
|
152
|
+
expect(error.type).to be :invalid_type
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when :index_errors is false' do
|
157
|
+
before do
|
158
|
+
options[:index_errors] = false
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'does not attach the index' do
|
162
|
+
error = result.errors.first
|
163
|
+
|
164
|
+
expect(result.errors.size).to be 1
|
165
|
+
expect(error).to be_an_instance_of ActiveInteraction::Filter::Error
|
166
|
+
expect(error.name).to be filter.name
|
167
|
+
expect(error.type).to be :invalid_type
|
168
|
+
end
|
169
|
+
end
|
95
170
|
end
|
96
171
|
end
|
97
172
|
end
|
@@ -144,9 +219,9 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
144
219
|
|
145
220
|
it 'has a filter with the right options' do
|
146
221
|
expect(filter.filters[:'0'].options).to have_key(:class)
|
147
|
-
expect(filter.filters[:'0'].options[:class]).to
|
222
|
+
expect(filter.filters[:'0'].options[:class]).to be :Object
|
148
223
|
expect(filter.filters[:'0'].options).to have_key(:converter)
|
149
|
-
expect(filter.filters[:'0'].options[:converter]).to
|
224
|
+
expect(filter.filters[:'0'].options[:converter]).to be :new
|
150
225
|
end
|
151
226
|
end
|
152
227
|
end
|
@@ -154,7 +229,7 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
154
229
|
|
155
230
|
describe '#database_column_type' do
|
156
231
|
it 'returns :string' do
|
157
|
-
expect(filter.database_column_type).to
|
232
|
+
expect(filter.database_column_type).to be :string
|
158
233
|
end
|
159
234
|
end
|
160
235
|
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 '#
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 '
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
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 '#
|
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
|
|