veto 0.1.3 → 1.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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -94
  3. data/lib/veto/blocks/block.rb +25 -0
  4. data/lib/veto/blocks/checker.rb +28 -0
  5. data/lib/veto/blocks/conditional_block.rb +26 -0
  6. data/lib/veto/blocks/validate_block.rb +18 -0
  7. data/lib/veto/blocks/validates_block.rb +51 -0
  8. data/lib/veto/blocks/with_options_block.rb +7 -0
  9. data/lib/veto/check_context_object.rb +10 -0
  10. data/lib/veto/checks/attribute_check.rb +19 -0
  11. data/lib/veto/checks/check.rb +7 -0
  12. data/lib/veto/checks/check_factory.rb +18 -0
  13. data/lib/veto/{validators/exact_length_validator.rb → checks/exact_length_check.rb} +5 -4
  14. data/lib/veto/{validators/format_validator.rb → checks/format_check.rb} +5 -4
  15. data/lib/veto/{validators/greater_than_validator.rb → checks/greater_than_check.rb} +2 -4
  16. data/lib/veto/{validators/greater_than_or_equal_to_validator.rb → checks/greater_than_or_equal_to_check.rb} +2 -4
  17. data/lib/veto/{validators/inclusion_validator.rb → checks/inclusion_check.rb} +2 -4
  18. data/lib/veto/{validators/integer_validator.rb → checks/integer_check.rb} +2 -4
  19. data/lib/veto/{validators/length_range_validator.rb → checks/length_range_check.rb} +2 -4
  20. data/lib/veto/{validators/less_than_validator.rb → checks/less_than_check.rb} +2 -4
  21. data/lib/veto/{validators/less_than_or_equal_to_validator.rb → checks/less_than_or_equal_to_check.rb} +2 -4
  22. data/lib/veto/{validators/max_length_validator.rb → checks/max_length_check.rb} +2 -4
  23. data/lib/veto/checks/method_check.rb +17 -0
  24. data/lib/veto/{validators/min_length_validator.rb → checks/min_length_check.rb} +2 -4
  25. data/lib/veto/{validators/not_null_validator.rb → checks/not_null_check.rb} +2 -4
  26. data/lib/veto/{validators/numeric_validator.rb → checks/numeric_check.rb} +2 -4
  27. data/lib/veto/{validators/presence_validator.rb → checks/presence_check.rb} +2 -4
  28. data/lib/veto/conditions/condition.rb +7 -0
  29. data/lib/veto/conditions/condition_factory.rb +18 -0
  30. data/lib/veto/conditions/conditions.rb +21 -0
  31. data/lib/veto/conditions/context_method_condition.rb +11 -0
  32. data/lib/veto/conditions/entity_eval_condition.rb +11 -0
  33. data/lib/veto/conditions/if_conditions.rb +8 -0
  34. data/lib/veto/conditions/if_unless_conditions.rb +21 -0
  35. data/lib/veto/conditions/passing_condition.rb +7 -0
  36. data/lib/veto/conditions/primative_condition.rb +11 -0
  37. data/lib/veto/conditions/proc_condition.rb +11 -0
  38. data/lib/veto/conditions/unless_conditions.rb +8 -0
  39. data/lib/veto/configuration.rb +38 -37
  40. data/lib/veto/errors.rb +27 -27
  41. data/lib/veto/exceptions.rb +13 -3
  42. data/lib/veto/model.rb +33 -35
  43. data/lib/veto/validator.rb +68 -169
  44. data/lib/veto/version.rb +1 -1
  45. data/lib/veto.rb +90 -49
  46. data/spec/blocks/block_spec.rb +31 -0
  47. data/spec/blocks/check_block_spec.rb +46 -0
  48. data/spec/blocks/conditional_block_spec.rb +36 -0
  49. data/spec/blocks/validate_block_spec.rb +18 -0
  50. data/spec/blocks/validates_block_spec.rb +22 -0
  51. data/spec/checks/exact_length_check_spec.rb +37 -0
  52. data/spec/checks/format_validator_spec.rb +37 -0
  53. data/spec/checks/greater_than_check_spec.rb +48 -0
  54. data/spec/checks/greater_than_or_equal_to_check_spec.rb +48 -0
  55. data/spec/checks/inclusion_check_spec.rb +37 -0
  56. data/spec/checks/integer_check_spec.rb +37 -0
  57. data/spec/checks/length_range_check_spec.rb +37 -0
  58. data/spec/checks/less_than_check_spec.rb +48 -0
  59. data/spec/checks/less_than_or_equal_to_check_spec.rb +48 -0
  60. data/spec/checks/max_length_check_spec.rb +48 -0
  61. data/spec/checks/method_check_spec.rb +13 -0
  62. data/spec/checks/min_length_check_spec.rb +48 -0
  63. data/spec/checks/not_null_check_spec.rb +37 -0
  64. data/spec/checks/numeric_check_spec.rb +37 -0
  65. data/spec/checks/presence_check_spec.rb +48 -0
  66. data/spec/conditions/condition_factory_spec.rb +31 -0
  67. data/spec/conditions/conditions_spec.rb +25 -0
  68. data/spec/conditions/context_method_condition_spec.rb +25 -0
  69. data/spec/conditions/entity_eval_condition_spec.rb +21 -0
  70. data/spec/conditions/if_conditions_spec.rb +65 -0
  71. data/spec/conditions/if_unless_conditions_spec.rb +33 -0
  72. data/spec/conditions/primative_condition_spec.rb +22 -0
  73. data/spec/conditions/proc_condition_spec.rb +25 -0
  74. data/spec/conditions/unless_conditions_spec.rb +65 -0
  75. data/spec/configuration/message_spec.rb +18 -23
  76. data/spec/spec_helper.rb +2 -1
  77. data/spec/validator_spec.rb +224 -115
  78. metadata +96 -61
  79. data/lib/veto/attribute_validator_factory.rb +0 -36
  80. data/lib/veto/builder.rb +0 -65
  81. data/lib/veto/conditions.rb +0 -23
  82. data/lib/veto/conditions_evaluator.rb +0 -30
  83. data/lib/veto/validators/abstract_validator.rb +0 -15
  84. data/lib/veto/validators/attribute_validator.rb +0 -22
  85. data/lib/veto/validators/custom_method_validator.rb +0 -19
  86. data/spec/attribute_validator_factory_spec.rb +0 -72
  87. data/spec/builder_spec.rb +0 -38
  88. data/spec/conditions_evaluator_spec.rb +0 -90
  89. data/spec/conditions_spec.rb +0 -16
  90. data/spec/configuration_spec.rb +0 -6
  91. data/spec/errors_spec.rb +0 -22
  92. data/spec/model_spec.rb +0 -67
  93. data/spec/system/validator_spec.rb +0 -530
  94. data/spec/validators/exact_length_validator_spec.rb +0 -37
  95. data/spec/validators/format_validator_spec.rb +0 -32
  96. data/spec/validators/inclusion_validator_spec.rb +0 -45
  97. data/spec/validators/integer_validator_spec.rb +0 -42
  98. data/spec/validators/length_range_validator_spec.rb +0 -55
  99. data/spec/validators/max_length_validator_spec.rb +0 -32
  100. data/spec/validators/min_length_validator_spec.rb +0 -32
  101. data/spec/validators/not_null_validator_spec.rb +0 -27
  102. data/spec/validators/numeric_validator_spec.rb +0 -42
  103. data/spec/validators/presence_validator_spec.rb +0 -47
  104. 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