veto 0.1.3 → 1.0.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 +7 -94
- data/lib/veto/blocks/block.rb +25 -0
- data/lib/veto/blocks/checker.rb +28 -0
- data/lib/veto/blocks/conditional_block.rb +26 -0
- data/lib/veto/blocks/validate_block.rb +18 -0
- data/lib/veto/blocks/validates_block.rb +51 -0
- data/lib/veto/blocks/with_options_block.rb +7 -0
- data/lib/veto/check_context_object.rb +10 -0
- data/lib/veto/checks/attribute_check.rb +19 -0
- data/lib/veto/checks/check.rb +7 -0
- data/lib/veto/checks/check_factory.rb +18 -0
- data/lib/veto/{validators/exact_length_validator.rb → checks/exact_length_check.rb} +5 -4
- data/lib/veto/{validators/format_validator.rb → checks/format_check.rb} +5 -4
- data/lib/veto/{validators/greater_than_validator.rb → checks/greater_than_check.rb} +2 -4
- data/lib/veto/{validators/greater_than_or_equal_to_validator.rb → checks/greater_than_or_equal_to_check.rb} +2 -4
- data/lib/veto/{validators/inclusion_validator.rb → checks/inclusion_check.rb} +2 -4
- data/lib/veto/{validators/integer_validator.rb → checks/integer_check.rb} +2 -4
- data/lib/veto/{validators/length_range_validator.rb → checks/length_range_check.rb} +2 -4
- data/lib/veto/{validators/less_than_validator.rb → checks/less_than_check.rb} +2 -4
- data/lib/veto/{validators/less_than_or_equal_to_validator.rb → checks/less_than_or_equal_to_check.rb} +2 -4
- data/lib/veto/{validators/max_length_validator.rb → checks/max_length_check.rb} +2 -4
- data/lib/veto/checks/method_check.rb +17 -0
- data/lib/veto/{validators/min_length_validator.rb → checks/min_length_check.rb} +2 -4
- data/lib/veto/{validators/not_null_validator.rb → checks/not_null_check.rb} +2 -4
- data/lib/veto/{validators/numeric_validator.rb → checks/numeric_check.rb} +2 -4
- data/lib/veto/{validators/presence_validator.rb → checks/presence_check.rb} +2 -4
- data/lib/veto/conditions/condition.rb +7 -0
- data/lib/veto/conditions/condition_factory.rb +18 -0
- data/lib/veto/conditions/conditions.rb +21 -0
- data/lib/veto/conditions/context_method_condition.rb +11 -0
- data/lib/veto/conditions/entity_eval_condition.rb +11 -0
- data/lib/veto/conditions/if_conditions.rb +8 -0
- data/lib/veto/conditions/if_unless_conditions.rb +21 -0
- data/lib/veto/conditions/passing_condition.rb +7 -0
- data/lib/veto/conditions/primative_condition.rb +11 -0
- data/lib/veto/conditions/proc_condition.rb +11 -0
- data/lib/veto/conditions/unless_conditions.rb +8 -0
- data/lib/veto/configuration.rb +38 -37
- data/lib/veto/errors.rb +27 -27
- data/lib/veto/exceptions.rb +13 -3
- data/lib/veto/model.rb +33 -35
- data/lib/veto/validator.rb +68 -169
- data/lib/veto/version.rb +1 -1
- data/lib/veto.rb +90 -49
- data/spec/blocks/block_spec.rb +31 -0
- data/spec/blocks/check_block_spec.rb +46 -0
- data/spec/blocks/conditional_block_spec.rb +36 -0
- data/spec/blocks/validate_block_spec.rb +18 -0
- data/spec/blocks/validates_block_spec.rb +22 -0
- data/spec/checks/exact_length_check_spec.rb +37 -0
- data/spec/checks/format_validator_spec.rb +37 -0
- data/spec/checks/greater_than_check_spec.rb +48 -0
- data/spec/checks/greater_than_or_equal_to_check_spec.rb +48 -0
- data/spec/checks/inclusion_check_spec.rb +37 -0
- data/spec/checks/integer_check_spec.rb +37 -0
- data/spec/checks/length_range_check_spec.rb +37 -0
- data/spec/checks/less_than_check_spec.rb +48 -0
- data/spec/checks/less_than_or_equal_to_check_spec.rb +48 -0
- data/spec/checks/max_length_check_spec.rb +48 -0
- data/spec/checks/method_check_spec.rb +13 -0
- data/spec/checks/min_length_check_spec.rb +48 -0
- data/spec/checks/not_null_check_spec.rb +37 -0
- data/spec/checks/numeric_check_spec.rb +37 -0
- data/spec/checks/presence_check_spec.rb +48 -0
- data/spec/conditions/condition_factory_spec.rb +31 -0
- data/spec/conditions/conditions_spec.rb +25 -0
- data/spec/conditions/context_method_condition_spec.rb +25 -0
- data/spec/conditions/entity_eval_condition_spec.rb +21 -0
- data/spec/conditions/if_conditions_spec.rb +65 -0
- data/spec/conditions/if_unless_conditions_spec.rb +33 -0
- data/spec/conditions/primative_condition_spec.rb +22 -0
- data/spec/conditions/proc_condition_spec.rb +25 -0
- data/spec/conditions/unless_conditions_spec.rb +65 -0
- data/spec/configuration/message_spec.rb +18 -23
- data/spec/spec_helper.rb +2 -1
- data/spec/validator_spec.rb +224 -115
- metadata +96 -61
- data/lib/veto/attribute_validator_factory.rb +0 -36
- data/lib/veto/builder.rb +0 -65
- data/lib/veto/conditions.rb +0 -23
- data/lib/veto/conditions_evaluator.rb +0 -30
- data/lib/veto/validators/abstract_validator.rb +0 -15
- data/lib/veto/validators/attribute_validator.rb +0 -22
- data/lib/veto/validators/custom_method_validator.rb +0 -19
- data/spec/attribute_validator_factory_spec.rb +0 -72
- data/spec/builder_spec.rb +0 -38
- data/spec/conditions_evaluator_spec.rb +0 -90
- data/spec/conditions_spec.rb +0 -16
- data/spec/configuration_spec.rb +0 -6
- data/spec/errors_spec.rb +0 -22
- data/spec/model_spec.rb +0 -67
- data/spec/system/validator_spec.rb +0 -530
- data/spec/validators/exact_length_validator_spec.rb +0 -37
- data/spec/validators/format_validator_spec.rb +0 -32
- data/spec/validators/inclusion_validator_spec.rb +0 -45
- data/spec/validators/integer_validator_spec.rb +0 -42
- data/spec/validators/length_range_validator_spec.rb +0 -55
- data/spec/validators/max_length_validator_spec.rb +0 -32
- data/spec/validators/min_length_validator_spec.rb +0 -32
- data/spec/validators/not_null_validator_spec.rb +0 -27
- data/spec/validators/numeric_validator_spec.rb +0 -42
- data/spec/validators/presence_validator_spec.rb +0 -47
- data/spec/veto_spec.rb +0 -24
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto/validators/length_range_validator'
|
3
|
-
require 'veto/errors'
|
4
|
-
|
5
|
-
describe Veto::LengthRangeValidator do
|
6
|
-
let(:errors){ Veto::Errors.new }
|
7
|
-
let(:entity) { Object.new }
|
8
|
-
let(:attribute) { :title }
|
9
|
-
let(:value) { 'blahblah' }
|
10
|
-
let(:options) {{:in => (1..10)}}
|
11
|
-
let(:validator){ Veto::LengthRangeValidator.new(attribute, options) }
|
12
|
-
let(:result){ validator.validate(entity, attribute, value, errors, options) }
|
13
|
-
|
14
|
-
describe '#validate' do
|
15
|
-
before { result }
|
16
|
-
|
17
|
-
context 'when range is array' do
|
18
|
-
let(:options) {{:in => [5, 8, 15]}}
|
19
|
-
|
20
|
-
context 'when value length is in array' do
|
21
|
-
let(:value) { 'abcde' }
|
22
|
-
it { errors[:title].must_be_nil }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when value length is not in array' do
|
26
|
-
let(:value) { 'abc' }
|
27
|
-
it { errors[:title].must_equal ["is too short or too long"] }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when value length is nil' do
|
31
|
-
let(:value) { nil }
|
32
|
-
it { errors[:title].must_equal ["is too short or too long"] }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when range is range' do
|
37
|
-
let(:options) {{:in => (5..10)}}
|
38
|
-
|
39
|
-
context 'when value length is in range' do
|
40
|
-
let(:value) { 'abcdef' }
|
41
|
-
it { errors[:title].must_be_nil }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when value length is not in range' do
|
45
|
-
let(:value) { 'abc' }
|
46
|
-
it { errors[:title].must_equal ["is too short or too long"] }
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when value length is nil' do
|
50
|
-
let(:value) { nil }
|
51
|
-
it { errors[:title].must_equal ["is too short or too long"] }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto/validators/max_length_validator'
|
3
|
-
require 'veto/errors'
|
4
|
-
|
5
|
-
describe Veto::MaxLengthValidator do
|
6
|
-
let(:errors){ Veto::Errors.new }
|
7
|
-
let(:entity) { Object.new }
|
8
|
-
let(:attribute) { :title }
|
9
|
-
let(:value) { 'blahblah' }
|
10
|
-
let(:options) {{:with => 10}}
|
11
|
-
let(:validator){ Veto::MaxLengthValidator.new(stub, stub) }
|
12
|
-
let(:result){ validator.validate(entity, attribute, value, errors, options) }
|
13
|
-
|
14
|
-
describe '#validate' do
|
15
|
-
before { result }
|
16
|
-
|
17
|
-
context 'when value length is less than max' do
|
18
|
-
let(:value) { 'abc' }
|
19
|
-
it { errors[:title].must_be_nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when value is too long' do
|
23
|
-
let(:value) { 'abcdefghijklmnop' }
|
24
|
-
it { errors[:title].must_equal ["is longer than 10 characters"] }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when value is nil' do
|
28
|
-
let(:value) { nil }
|
29
|
-
it { errors[:title].must_equal ["is longer than 10 characters"] }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto/validators/min_length_validator'
|
3
|
-
require 'veto/errors'
|
4
|
-
|
5
|
-
describe Veto::MinLengthValidator do
|
6
|
-
let(:errors){ Veto::Errors.new }
|
7
|
-
let(:entity) { Object.new }
|
8
|
-
let(:attribute) { :title }
|
9
|
-
let(:value) { 'blahblah' }
|
10
|
-
let(:options) {{:with => 5}}
|
11
|
-
let(:validator){ Veto::MinLengthValidator.new(stub, stub) }
|
12
|
-
let(:result){ validator.validate(entity, attribute, value, errors, options) }
|
13
|
-
|
14
|
-
describe '#validate' do
|
15
|
-
before { result }
|
16
|
-
|
17
|
-
context 'when value length is greater than min' do
|
18
|
-
let(:value) { 'abcdefg' }
|
19
|
-
it { errors[:title].must_be_nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when value is too short' do
|
23
|
-
let(:value) { 'abcd' }
|
24
|
-
it { errors[:title].must_equal ["is shorter than 5 characters"] }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when value is nil' do
|
28
|
-
let(:value) { nil }
|
29
|
-
it { errors[:title].must_equal ["is shorter than 5 characters"] }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto/validators/not_null_validator'
|
3
|
-
require 'veto/errors'
|
4
|
-
|
5
|
-
describe Veto::NotNullValidator do
|
6
|
-
let(:errors){ Veto::Errors.new }
|
7
|
-
let(:entity) { Object.new }
|
8
|
-
let(:attribute) { :title }
|
9
|
-
let(:value) { 'blahblah' }
|
10
|
-
let(:options) {{:with => {}}}
|
11
|
-
let(:validator){ Veto::NotNullValidator.new(stub, stub) }
|
12
|
-
let(:result){ validator.validate(entity, attribute, value, errors, options) }
|
13
|
-
|
14
|
-
describe '#validate' do
|
15
|
-
before { result }
|
16
|
-
|
17
|
-
context 'when value is not null' do
|
18
|
-
let(:value) { 123 }
|
19
|
-
it { errors[:title].must_be_nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when value is nil' do
|
23
|
-
let(:value) { nil }
|
24
|
-
it { errors[:title].must_equal ["is not present"]}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto/validators/numeric_validator'
|
3
|
-
require 'veto/errors'
|
4
|
-
|
5
|
-
describe Veto::NumericValidator do
|
6
|
-
let(:errors){ Veto::Errors.new }
|
7
|
-
let(:entity) { Object.new }
|
8
|
-
let(:attribute) { :title }
|
9
|
-
let(:value) { 'blahblah' }
|
10
|
-
let(:options) {{:with => {}}}
|
11
|
-
let(:validator){ Veto::NumericValidator.new(stub, stub) }
|
12
|
-
let(:result){ validator.validate(entity, attribute, value, errors, options) }
|
13
|
-
|
14
|
-
describe '#validate' do
|
15
|
-
before { result }
|
16
|
-
|
17
|
-
context 'when value is integer' do
|
18
|
-
let(:value) { 123 }
|
19
|
-
it { errors[:title].must_be_nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when value is float' do
|
23
|
-
let(:value) { 123.4 }
|
24
|
-
it { errors[:title].must_be_nil }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when value is string' do
|
28
|
-
let(:value) { 'abc' }
|
29
|
-
it { errors[:title].must_equal ["is not a number"]}
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when value is nil' do
|
33
|
-
let(:value) { nil }
|
34
|
-
it { errors[:title].must_equal ["is not a number"]}
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when value is everything else' do
|
38
|
-
let(:value) { ['array'] }
|
39
|
-
it { errors[:title].must_equal ["is not a number"]}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto/validators/presence_validator'
|
3
|
-
require 'veto/errors'
|
4
|
-
|
5
|
-
describe Veto::PresenceValidator do
|
6
|
-
let(:errors) { Veto::Errors.new }
|
7
|
-
let(:entity) { Object.new }
|
8
|
-
let(:attribute) { :title }
|
9
|
-
let(:value) { 'blahblah' }
|
10
|
-
let(:options) {{:with => {}}}
|
11
|
-
let(:validator) { Veto::PresenceValidator.new(stub, stub) }
|
12
|
-
let(:result) { validator.validate(entity, attribute, value, errors, options) }
|
13
|
-
|
14
|
-
describe '#validate' do
|
15
|
-
before { result }
|
16
|
-
|
17
|
-
context 'when value is not null' do
|
18
|
-
let(:value) { 123 }
|
19
|
-
it { errors[:title].must_be_nil }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when value is nil' do
|
23
|
-
let(:value) { nil }
|
24
|
-
it { errors[:title].must_equal ["is not present"]}
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when value is empty string' do
|
28
|
-
let(:value) { '' }
|
29
|
-
it { errors[:title].must_equal ["is not present"]}
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when value is string of whitespace' do
|
33
|
-
let(:value) { ' ' }
|
34
|
-
it { errors[:title].must_equal ["is not present"]}
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when value is empty array' do
|
38
|
-
let(:value) { [] }
|
39
|
-
it { errors[:title].must_equal ["is not present"]}
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when value is empty hash' do
|
43
|
-
let(:value) { {} }
|
44
|
-
it { errors[:title].must_equal ["is not present"]}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/spec/veto_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'veto'
|
3
|
-
|
4
|
-
describe Veto do
|
5
|
-
describe '::model' do
|
6
|
-
let(:klass){ Class.new{ include Veto.model('validator class') } }
|
7
|
-
|
8
|
-
it 'includes model module to class' do
|
9
|
-
klass.included_modules.must_include Veto::Model
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets model validator' do
|
13
|
-
klass.validator.must_equal 'validator class'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '::validator' do
|
18
|
-
let(:klass){ Class.new{ include Veto.validator } }
|
19
|
-
|
20
|
-
it 'includes validator module to class' do
|
21
|
-
klass.included_modules.must_include Veto::Validator
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|