active_interaction 4.1.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +128 -1
- data/README.md +63 -28
- 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 +34 -6
- 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 -16
- 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 +40 -91
- data/lib/active_interaction/filter_column.rb +0 -57
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveInteraction::Runnable do
|
4
|
-
include_context 'concerns',
|
4
|
+
include_context 'concerns', described_class
|
5
5
|
|
6
6
|
class WrappableFailingInteraction # rubocop:disable Lint/ConstantDefinitionInBlock
|
7
7
|
include ActiveInteraction::Runnable
|
@@ -230,49 +230,51 @@ describe ActiveInteraction::Runnable do
|
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
|
-
context 'caches the
|
234
|
-
|
235
|
-
|
236
|
-
|
233
|
+
context 'caches the result of the run' do
|
234
|
+
context 'when it is invalid' do
|
235
|
+
let(:klass) do
|
236
|
+
Class.new(ActiveInteraction::Base) do
|
237
|
+
invalid = [false, true].cycle
|
237
238
|
|
238
|
-
|
239
|
-
|
240
|
-
|
239
|
+
validate do |interaction|
|
240
|
+
interaction.errors.add(:base, 'failed') unless invalid.next
|
241
|
+
end
|
241
242
|
|
242
|
-
|
243
|
-
|
243
|
+
def execute
|
244
|
+
true
|
245
|
+
end
|
244
246
|
end
|
245
247
|
end
|
246
|
-
end
|
247
248
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
249
|
+
it 'fails' do
|
250
|
+
expect(outcome).to_not be_valid
|
251
|
+
expect(outcome.result).to be_nil
|
252
|
+
expect(outcome).to_not be_valid
|
253
|
+
expect(outcome.result).to be_nil
|
254
|
+
end
|
253
255
|
end
|
254
|
-
end
|
255
256
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
257
|
+
context 'when it is valid' do
|
258
|
+
let(:klass) do
|
259
|
+
Class.new(ActiveInteraction::Base) do
|
260
|
+
valid = [true, false].cycle
|
260
261
|
|
261
|
-
|
262
|
-
|
263
|
-
|
262
|
+
validate do |interaction|
|
263
|
+
interaction.errors.add(:base, 'failed') unless valid.next
|
264
|
+
end
|
264
265
|
|
265
|
-
|
266
|
-
|
266
|
+
def execute
|
267
|
+
true
|
268
|
+
end
|
267
269
|
end
|
268
270
|
end
|
269
|
-
end
|
270
271
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
272
|
+
it 'succeeds' do
|
273
|
+
expect(outcome).to be_valid
|
274
|
+
expect(outcome.result).to be true
|
275
|
+
expect(outcome).to be_valid
|
276
|
+
expect(outcome.result).to be true
|
277
|
+
end
|
276
278
|
end
|
277
279
|
end
|
278
280
|
|
@@ -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,14 +25,22 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '#
|
29
|
-
let(:result) { filter.
|
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,7 @@ 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
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
@@ -62,10 +70,31 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
62
70
|
let(:block) { proc { array } }
|
63
71
|
|
64
72
|
context 'with an Array' do
|
65
|
-
let(:
|
73
|
+
let(:child_value) { [] }
|
74
|
+
let(:value) { [child_value, child_value] }
|
66
75
|
|
67
76
|
it 'returns the Array' do
|
68
|
-
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
|
69
98
|
end
|
70
99
|
end
|
71
100
|
|
@@ -73,17 +102,71 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
73
102
|
let(:value) { [[]] }
|
74
103
|
|
75
104
|
it 'returns the Array' do
|
76
|
-
expect(result).to eql value
|
105
|
+
expect(result.value).to eql value
|
77
106
|
end
|
78
107
|
end
|
79
108
|
|
80
109
|
context 'with a heterogenous Array' do
|
81
|
-
let(:value) { [[], false, 0.0
|
110
|
+
let(:value) { [[], false, 0.0] }
|
111
|
+
|
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
|
82
120
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
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
|
87
170
|
end
|
88
171
|
end
|
89
172
|
end
|
@@ -136,9 +219,9 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
136
219
|
|
137
220
|
it 'has a filter with the right options' do
|
138
221
|
expect(filter.filters[:'0'].options).to have_key(:class)
|
139
|
-
expect(filter.filters[:'0'].options[:class]).to
|
222
|
+
expect(filter.filters[:'0'].options[:class]).to be :Object
|
140
223
|
expect(filter.filters[:'0'].options).to have_key(:converter)
|
141
|
-
expect(filter.filters[:'0'].options[:converter]).to
|
224
|
+
expect(filter.filters[:'0'].options[:converter]).to be :new
|
142
225
|
end
|
143
226
|
end
|
144
227
|
end
|
@@ -146,7 +229,7 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
146
229
|
|
147
230
|
describe '#database_column_type' do
|
148
231
|
it 'returns :string' do
|
149
|
-
expect(filter.database_column_type).to
|
232
|
+
expect(filter.database_column_type).to be :string
|
150
233
|
end
|
151
234
|
end
|
152
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
|