active_model_validators_ex 0.0.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -6
- data/active_model_validators_ex.gemspec +4 -3
- data/lib/active_model_validators_ex.rb +2 -0
- data/lib/active_model_validators_ex/array_format_validator.rb +19 -0
- data/lib/active_model_validators_ex/array_inclusion_validator.rb +6 -13
- data/lib/active_model_validators_ex/array_validator_base.rb +28 -0
- data/lib/active_model_validators_ex/version.rb +1 -1
- data/spec/active_model_validators_ex/array_format_validator_spec.rb +55 -0
- data/spec/active_model_validators_ex/array_inclusion_validator_spec.rb +8 -169
- data/spec/active_model_validators_ex/array_validator_base_spec.rb +152 -0
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb623b9155719e88023b83b4833516fa09a614a0
|
4
|
+
data.tar.gz: d0a82d484adf8b88c4c2e0f07d2d3670fb963b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0673775f33792232fd1ffc390dad636a0879f0b86821728784728b0cca87d5d8c4073e4ee66d16356a81d4ee708b7a9bd64d1096690e14e632f162fcabf32361
|
7
|
+
data.tar.gz: d0742f05524b44c5dffec0c6a951a102705a1965fa024458ced3374b6dd08241d1329eaa5cc65ebabfc670311568840463063944d507720f31fee9bfefa79491
|
data/README.md
CHANGED
@@ -29,8 +29,8 @@ validations:
|
|
29
29
|
|
30
30
|
* ArrayInclusionValidator
|
31
31
|
|
32
|
-
|
33
|
-
(
|
32
|
+
Validates if attribute value is an Array, containing values defined under key
|
33
|
+
:in (this can be defined either with an Array or Range). As an example:
|
34
34
|
|
35
35
|
class ExampleModel
|
36
36
|
include Mongoid::Document
|
@@ -38,12 +38,16 @@ validations:
|
|
38
38
|
field :array
|
39
39
|
|
40
40
|
validates :array, array_inclusion: {
|
41
|
-
# the collection of
|
42
|
-
in: [0, 1, 2], #
|
41
|
+
# the collection of values to compare with each element in array
|
42
|
+
in: [0, 1, 2], # this could also be written as a range: 0..2
|
43
43
|
|
44
44
|
# can be either true or false, indicates if nil is accepted
|
45
45
|
# defaults to false
|
46
|
-
allow_nil: true
|
46
|
+
allow_nil: true,
|
47
|
+
|
48
|
+
# can be either true or false, indicates if it accepts empty arrays
|
49
|
+
# defaults to false
|
50
|
+
allow_empty: true
|
47
51
|
}
|
48
52
|
end
|
49
53
|
|
@@ -53,9 +57,39 @@ validations:
|
|
53
57
|
# returns false
|
54
58
|
ExampleModel.new(array: [1, 2, 5]).valid?
|
55
59
|
|
60
|
+
# returns true
|
61
|
+
ExampleModel.new(array: []).valid?
|
62
|
+
|
63
|
+
* ArrayFormatValidator
|
64
|
+
|
65
|
+
class ExampleModel
|
66
|
+
include Mongoid::Document
|
67
|
+
|
68
|
+
field :array
|
69
|
+
|
70
|
+
validates :array, array_format: {
|
71
|
+
# the regexp to compare each element in array
|
72
|
+
with: /(some|match|string)/
|
73
|
+
|
74
|
+
# can be either true or false, indicates if nil is accepted
|
75
|
+
# defaults to false
|
76
|
+
allow_nil: true,
|
77
|
+
|
78
|
+
# can be either true or false, indicates if it accepts empty arrays
|
79
|
+
# defaults to false
|
80
|
+
allow_empty: true
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
# returns true
|
85
|
+
ExampleModel.new(array: ['some', 'match', 'string']).valid?
|
86
|
+
|
87
|
+
# return false
|
88
|
+
ExampleModel.new(array: ['not', 'matching']).valid?
|
89
|
+
|
56
90
|
* TimeFormatValidator
|
57
91
|
|
58
|
-
|
92
|
+
Validates if value is of type Time or a string parsable to Time, example:
|
59
93
|
|
60
94
|
class ExampleModel < ActiveRecord::Base
|
61
95
|
attr_accessible :time
|
@@ -8,9 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ActiveModelValidatorsEx::VERSION
|
9
9
|
spec.authors = ["junhanamaki"]
|
10
10
|
spec.email = ["jun.hanamaki@gmail.com"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
13
|
-
models.}
|
11
|
+
spec.summary = %q{Custom validators for ActiveModel}
|
12
|
+
spec.description = %q{Add more validators for your ActiveModel models.}
|
14
13
|
spec.homepage = "https://github.com/junhanamaki/active_model_validators_ex"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
@@ -19,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
19
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
19
|
spec.require_paths = ["lib"]
|
21
20
|
|
21
|
+
spec.required_ruby_version = '>= 1.9.3'
|
22
|
+
|
22
23
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
25
|
spec.add_development_dependency 'simplecov', '~> 0.9'
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'active_model_validators_ex/version'
|
2
|
+
require 'active_model_validators_ex/array_validator_base'
|
3
|
+
require 'active_model_validators_ex/array_format_validator'
|
2
4
|
require 'active_model_validators_ex/array_inclusion_validator'
|
3
5
|
require 'active_model_validators_ex/time_format_validator'
|
4
6
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_model_validators_ex/array_validator_base'
|
2
|
+
|
3
|
+
class ArrayFormatValidator < ArrayValidatorBase
|
4
|
+
def initialize(options)
|
5
|
+
unless options.key?(:with) && options[:with].is_a?(Regexp)
|
6
|
+
raise 'key with must be present, and value must be a Regexp'
|
7
|
+
end
|
8
|
+
|
9
|
+
super(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def custom_validations(record, attribute, value)
|
13
|
+
unless value.all? { |val| !val.match(options[:with]).nil? }
|
14
|
+
record.errors[attribute] <<
|
15
|
+
"attribute #{attribute} must be an Array with values that matches " \
|
16
|
+
"#{options[:with]}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,28 +1,21 @@
|
|
1
|
-
|
1
|
+
require 'active_model_validators_ex/array_validator_base'
|
2
|
+
|
3
|
+
class ArrayInclusionValidator < ArrayValidatorBase
|
2
4
|
def initialize(options)
|
3
5
|
unless options.key?(:in) &&
|
4
6
|
(options[:in].is_a?(Array) ||
|
5
7
|
options[:in].is_a?(Range))
|
6
|
-
raise 'key
|
8
|
+
raise 'key in must be present, and value must be either a Range or Array'
|
7
9
|
end
|
8
10
|
|
9
11
|
super(options)
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
return if value.nil? and options[:allow_nil]
|
14
|
-
|
15
|
-
unless value.is_a? Array
|
16
|
-
record.errors[attribute] <<
|
17
|
-
"expecting either Array or nil for attribute #{attribute}"
|
18
|
-
return
|
19
|
-
end
|
20
|
-
|
14
|
+
def custom_validations(record, attribute, value)
|
21
15
|
unless value.all? { |val| options[:in].include?(val) }
|
22
16
|
record.errors[attribute] <<
|
23
17
|
"attribute #{attribute} has be an array composed of values " \
|
24
|
-
"
|
25
|
-
return
|
18
|
+
"#{options[:in]}"
|
26
19
|
end
|
27
20
|
end
|
28
21
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class ArrayValidatorBase < ActiveModel::EachValidator
|
2
|
+
def initialize(options)
|
3
|
+
options[:allow_nil] ||= false
|
4
|
+
options[:allow_empty] ||= false
|
5
|
+
|
6
|
+
super(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
return if options[:allow_nil] && value.nil?
|
11
|
+
|
12
|
+
unless value.is_a? Array
|
13
|
+
record.errors[attribute] << "attribute #{attribute} must be an Array"
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
if !options[:allow_empty] and value.empty?
|
18
|
+
record.errors[attribute] << "attribute #{attribute} can't be empty"
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
custom_validations(record, attribute, value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def custom_validations(record, attribute, value)
|
26
|
+
raise 'override this method to perform custom validations'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArrayFormatValidator do
|
4
|
+
describe '.new' do
|
5
|
+
context 'when key with is not present in argument hash' do
|
6
|
+
let(:options) { { attributes: :something } }
|
7
|
+
|
8
|
+
it 'raises error' do
|
9
|
+
expect do
|
10
|
+
ArrayFormatValidator.new(options)
|
11
|
+
end.to raise_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when key with is a non Regexp value' do
|
16
|
+
let(:options) { { attributes: :something, with: 'not an regexp' } }
|
17
|
+
|
18
|
+
it 'raises error' do
|
19
|
+
expect do
|
20
|
+
ArrayFormatValidator.new(options)
|
21
|
+
end.to raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#validate_each' do
|
27
|
+
let(:record) { MockRecord.new(attribute) }
|
28
|
+
let(:attribute) { :array }
|
29
|
+
let(:validator) { ArrayFormatValidator.new(options) }
|
30
|
+
before { validator.validate_each(record, attribute, value) }
|
31
|
+
|
32
|
+
context 'for instance initialized with regexp value in key :with' do
|
33
|
+
let(:regexp) { /(testing|one|two)/ }
|
34
|
+
let(:options) do
|
35
|
+
{ attributes: attribute, with: regexp }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when value is an Array with values that match regexp' do
|
39
|
+
let(:value) { ['testing', 'one', 'two'] }
|
40
|
+
|
41
|
+
it 'does not set error messages in record' do
|
42
|
+
expect(record.errors[attribute].count).to eq(0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when value is an array with values that do not match regexp' do
|
47
|
+
let(:value) { ['i do not match'] }
|
48
|
+
|
49
|
+
it 'sets error message in record' do
|
50
|
+
expect(record.errors[attribute].count).to eq(1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -19,147 +19,10 @@ describe ArrayInclusionValidator do
|
|
19
19
|
let(:validator) { ArrayInclusionValidator.new(options) }
|
20
20
|
before { validator.validate_each(record, attribute, value) }
|
21
21
|
|
22
|
-
context 'for instance initialized with
|
23
|
-
'key :in with empty array as value' do
|
24
|
-
let(:options) { { attributes: attribute, in: [] } }
|
25
|
-
|
26
|
-
context 'when passed value is nil' do
|
27
|
-
let(:value) { nil }
|
28
|
-
|
29
|
-
it 'sets error message in record, under passed attribute key' do
|
30
|
-
expect(record.errors[attribute].count).to eq(1)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when passed value is a non nil, non array value' do
|
35
|
-
let(:value) { :symbol }
|
36
|
-
|
37
|
-
it 'sets error message in record' do
|
38
|
-
expect(record.errors[attribute].count).to eq(1)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when passed value is an empty array' do
|
43
|
-
let(:value) { [] }
|
44
|
-
|
45
|
-
it 'does not set error messages in record' do
|
46
|
-
expect(record.errors[attribute].count).to eq(0)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when passed value is an array with values' do
|
51
|
-
let(:value) { [1, 2, 3] }
|
52
|
-
|
53
|
-
it 'sets error message in record, under passed attribute key' do
|
54
|
-
expect(record.errors[attribute].count).to eq(1)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'for instance initialized with options hash ' \
|
60
|
-
'key :in with empty array as value, ' \
|
61
|
-
'allow_nil as false' do
|
62
|
-
let(:options) { { attributes: attribute, in: [], allow_nil: false } }
|
63
|
-
|
64
|
-
context 'when passed value is nil' do
|
65
|
-
let(:value) { nil }
|
66
|
-
|
67
|
-
it 'sets error message in record, under passed attribute key' do
|
68
|
-
expect(record.errors[attribute].count).to eq(1)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'when passed value is a non nil, non array value' do
|
73
|
-
let(:value) { :symbol }
|
74
|
-
|
75
|
-
it 'sets error message in record' do
|
76
|
-
expect(record.errors[attribute].count).to eq(1)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when passed value is an empty array' do
|
81
|
-
let(:value) { [] }
|
82
|
-
|
83
|
-
it 'does not set error messages in record' do
|
84
|
-
expect(record.errors[attribute].count).to eq(0)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'when passed value is an array with values' do
|
89
|
-
let(:value) { [1, 2, 3] }
|
90
|
-
|
91
|
-
it 'sets error message in record, under passed attribute key' do
|
92
|
-
expect(record.errors[attribute].count).to eq(1)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'for instance initialized with options hash ' \
|
98
|
-
'key :in with empty array as value, ' \
|
99
|
-
'allow_nil as true' do
|
100
|
-
let(:options) { { attributes: attribute, in: [], allow_nil: true } }
|
101
|
-
|
102
|
-
context 'when passed value is nil' do
|
103
|
-
let(:value) { nil }
|
104
|
-
|
105
|
-
it 'does not set error messages in record' do
|
106
|
-
expect(record.errors[attribute].count).to eq(0)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'when passed value is a non nil, non array value' do
|
111
|
-
let(:value) { :symbol }
|
112
|
-
|
113
|
-
it 'sets error message in record' do
|
114
|
-
expect(record.errors[attribute].count).to eq(1)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when passed value is an empty array' do
|
119
|
-
let(:value) { [] }
|
120
|
-
|
121
|
-
it 'does not set error messages in record' do
|
122
|
-
expect(record.errors[attribute].count).to eq(0)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'when passed value is an array with values' do
|
127
|
-
let(:value) { [1, 2, 3] }
|
128
|
-
|
129
|
-
it 'sets error message in record, under passed attribute key' do
|
130
|
-
expect(record.errors[attribute].count).to eq(1)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'for instance initialized with options hash ' \
|
136
|
-
'key :in with array with values as value, ' \
|
137
|
-
'allow_nil as true' do
|
22
|
+
context 'for instance initialized with key in with an Array of values' do
|
138
23
|
let(:in_array) { [1, 2, 3] }
|
139
|
-
let(:options)
|
140
|
-
|
141
|
-
context 'when passed value is nil' do
|
142
|
-
let(:value) { nil }
|
143
|
-
|
144
|
-
it 'does not set error messages in record' do
|
145
|
-
expect(record.errors[attribute].count).to eq(0)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'when passed value is a non nil, non array value' do
|
150
|
-
let(:value) { :symbol }
|
151
|
-
|
152
|
-
it 'sets error message in record' do
|
153
|
-
expect(record.errors[attribute].count).to eq(1)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'when passed value is an empty array' do
|
158
|
-
let(:value) { [] }
|
159
|
-
|
160
|
-
it 'does not set error messages in record' do
|
161
|
-
expect(record.errors[attribute].count).to eq(0)
|
162
|
-
end
|
24
|
+
let(:options) do
|
25
|
+
{ attributes: attribute, in: in_array }
|
163
26
|
end
|
164
27
|
|
165
28
|
context 'when passed value is an array with values that are in options array' do
|
@@ -179,37 +42,13 @@ describe ArrayInclusionValidator do
|
|
179
42
|
end
|
180
43
|
end
|
181
44
|
|
182
|
-
context 'for instance initialized with
|
183
|
-
'key :in with range with values as value, ' \
|
184
|
-
'allow_nil as false' do
|
45
|
+
context 'for instance initialized with key in with a Range of values' do
|
185
46
|
let(:in_range) { 1..3 }
|
186
|
-
let(:options)
|
187
|
-
|
188
|
-
context 'when passed value is nil' do
|
189
|
-
let(:value) { nil }
|
190
|
-
|
191
|
-
it 'sets error message in record' do
|
192
|
-
expect(record.errors[attribute].count).to eq(1)
|
193
|
-
end
|
47
|
+
let(:options) do
|
48
|
+
{ attributes: attribute, in: in_range }
|
194
49
|
end
|
195
50
|
|
196
|
-
context 'when passed value is
|
197
|
-
let(:value) { :symbol }
|
198
|
-
|
199
|
-
it 'sets error message in record' do
|
200
|
-
expect(record.errors[attribute].count).to eq(1)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'when passed value is an empty array' do
|
205
|
-
let(:value) { [] }
|
206
|
-
|
207
|
-
it 'does not set error messages in record' do
|
208
|
-
expect(record.errors[attribute].count).to eq(0)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context 'when passed value is an array with values that are in options range' do
|
51
|
+
context 'when passed value is an array with values that are in options array' do
|
213
52
|
let(:value) { [1, 2, 3] }
|
214
53
|
|
215
54
|
it 'does not set error messages in record' do
|
@@ -217,7 +56,7 @@ describe ArrayInclusionValidator do
|
|
217
56
|
end
|
218
57
|
end
|
219
58
|
|
220
|
-
context 'when passed value is an array with values not in options
|
59
|
+
context 'when passed value is an array with values not in options array' do
|
221
60
|
let(:value) { [4, 5, 6] }
|
222
61
|
|
223
62
|
it 'sets error message in record' do
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArrayValidatorBase do
|
4
|
+
describe '.custom_validations' do
|
5
|
+
context 'if method is not overridden' do
|
6
|
+
it 'raises error' do
|
7
|
+
expect do
|
8
|
+
validator.custom_validations(nil, nil, nil)
|
9
|
+
end.to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.validate_each' do
|
15
|
+
let(:record) { MockRecord.new(attribute) }
|
16
|
+
let(:attribute) { :a }
|
17
|
+
let(:validator) { ArrayValidatorBase.new(options) }
|
18
|
+
before do
|
19
|
+
validator.validate_each(record, attribute, value) rescue nil
|
20
|
+
end
|
21
|
+
|
22
|
+
shared_examples_for :common_behavior do
|
23
|
+
context 'and value is a non nil, non array value' do
|
24
|
+
let(:value) { :symbol }
|
25
|
+
|
26
|
+
it 'sets error message in record' do
|
27
|
+
expect(record.errors[attribute].count).to eq(1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
shared_examples_for :allow_nil_true do
|
33
|
+
context 'and value is nil' do
|
34
|
+
let(:value) { nil }
|
35
|
+
|
36
|
+
it 'does not set error messages in record' do
|
37
|
+
expect(record.errors[attribute].count).to eq(0)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
shared_examples_for :allow_nil_false do
|
43
|
+
context 'and value is nil' do
|
44
|
+
let(:value) { nil }
|
45
|
+
|
46
|
+
it 'sets error message in record' do
|
47
|
+
expect(record.errors[attribute].count).to eq(1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
shared_examples_for :allow_empty_true do
|
53
|
+
context 'and value is an empty Array' do
|
54
|
+
let(:value) { [] }
|
55
|
+
|
56
|
+
it 'does not set error messages in record' do
|
57
|
+
expect(record.errors[attribute].count).to eq(0)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
shared_examples_for :allow_empty_false do
|
63
|
+
context 'and value is an empty Array' do
|
64
|
+
let(:value) { [] }
|
65
|
+
|
66
|
+
it 'set error messager in record' do
|
67
|
+
expect(record.errors[attribute].count).to eq(1)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'for instance initialized with no options (defaults test)' do
|
73
|
+
let(:options) { { attributes: attribute } }
|
74
|
+
|
75
|
+
it_behaves_like :common_behavior
|
76
|
+
it_behaves_like :allow_nil_false
|
77
|
+
it_behaves_like :allow_empty_false
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'for instance initialized with allow_empty true' do
|
81
|
+
let(:options) { { attributes: attribute, allow_empty: true } }
|
82
|
+
|
83
|
+
it_behaves_like :common_behavior
|
84
|
+
it_behaves_like :allow_nil_false
|
85
|
+
it_behaves_like :allow_empty_true
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'for instance initialized with allow_empty false' do
|
89
|
+
let(:options) { { attributes: attribute, allow_empty: false } }
|
90
|
+
|
91
|
+
it_behaves_like :common_behavior
|
92
|
+
it_behaves_like :allow_nil_false
|
93
|
+
it_behaves_like :allow_empty_false
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'for instance initialized with allow_nil true' do
|
97
|
+
let(:options) { { attributes: attribute, allow_nil: true } }
|
98
|
+
|
99
|
+
it_behaves_like :common_behavior
|
100
|
+
it_behaves_like :allow_nil_true
|
101
|
+
it_behaves_like :allow_empty_false
|
102
|
+
|
103
|
+
context 'and allow_empty true' do
|
104
|
+
let(:options) do
|
105
|
+
{ attributes: attribute, allow_nil: true, allow_empty: true }
|
106
|
+
end
|
107
|
+
|
108
|
+
it_behaves_like :common_behavior
|
109
|
+
it_behaves_like :allow_nil_true
|
110
|
+
it_behaves_like :allow_empty_true
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'and allow_empty false' do
|
114
|
+
let(:options) do
|
115
|
+
{ attributes: attribute, allow_nil: true, allow_empty: false }
|
116
|
+
end
|
117
|
+
|
118
|
+
it_behaves_like :common_behavior
|
119
|
+
it_behaves_like :allow_nil_true
|
120
|
+
it_behaves_like :allow_empty_false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'for instance initialized with allow_nil false' do
|
125
|
+
let(:options) { { attributes: attribute, allow_nil: false } }
|
126
|
+
|
127
|
+
it_behaves_like :common_behavior
|
128
|
+
it_behaves_like :allow_nil_false
|
129
|
+
it_behaves_like :allow_empty_false
|
130
|
+
|
131
|
+
context 'and allow_empty true' do
|
132
|
+
let(:options) do
|
133
|
+
{ attributes: attribute, allow_nil: false, allow_empty: true }
|
134
|
+
end
|
135
|
+
|
136
|
+
it_behaves_like :common_behavior
|
137
|
+
it_behaves_like :allow_nil_false
|
138
|
+
it_behaves_like :allow_empty_true
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'and allow_empty false' do
|
142
|
+
let(:options) do
|
143
|
+
{ attributes: attribute, allow_nil: false, allow_empty: false }
|
144
|
+
end
|
145
|
+
|
146
|
+
it_behaves_like :common_behavior
|
147
|
+
it_behaves_like :allow_nil_false
|
148
|
+
it_behaves_like :allow_empty_false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_validators_ex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- junhanamaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,9 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '4.1'
|
97
|
-
description:
|
98
|
-
Extend ActiveModel with more validators for your
|
99
|
-
models.
|
97
|
+
description: Add more validators for your ActiveModel models.
|
100
98
|
email:
|
101
99
|
- jun.hanamaki@gmail.com
|
102
100
|
executables: []
|
@@ -114,10 +112,14 @@ files:
|
|
114
112
|
- Rakefile
|
115
113
|
- active_model_validators_ex.gemspec
|
116
114
|
- lib/active_model_validators_ex.rb
|
115
|
+
- lib/active_model_validators_ex/array_format_validator.rb
|
117
116
|
- lib/active_model_validators_ex/array_inclusion_validator.rb
|
117
|
+
- lib/active_model_validators_ex/array_validator_base.rb
|
118
118
|
- lib/active_model_validators_ex/time_format_validator.rb
|
119
119
|
- lib/active_model_validators_ex/version.rb
|
120
|
+
- spec/active_model_validators_ex/array_format_validator_spec.rb
|
120
121
|
- spec/active_model_validators_ex/array_inclusion_validator_spec.rb
|
122
|
+
- spec/active_model_validators_ex/array_validator_base_spec.rb
|
121
123
|
- spec/active_model_validators_ex/time_format_validator_spec.rb
|
122
124
|
- spec/mock_objects/mock_record.rb
|
123
125
|
- spec/spec_helper.rb
|
@@ -133,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
135
|
requirements:
|
134
136
|
- - ">="
|
135
137
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
138
|
+
version: 1.9.3
|
137
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
140
|
requirements:
|
139
141
|
- - ">="
|
@@ -144,9 +146,11 @@ rubyforge_project:
|
|
144
146
|
rubygems_version: 2.2.2
|
145
147
|
signing_key:
|
146
148
|
specification_version: 4
|
147
|
-
summary:
|
149
|
+
summary: Custom validators for ActiveModel
|
148
150
|
test_files:
|
151
|
+
- spec/active_model_validators_ex/array_format_validator_spec.rb
|
149
152
|
- spec/active_model_validators_ex/array_inclusion_validator_spec.rb
|
153
|
+
- spec/active_model_validators_ex/array_validator_base_spec.rb
|
150
154
|
- spec/active_model_validators_ex/time_format_validator_spec.rb
|
151
155
|
- spec/mock_objects/mock_record.rb
|
152
156
|
- spec/spec_helper.rb
|