veto 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ddb59a4bc3131694b4d01a21be9af65642a68f2
4
- data.tar.gz: 75debbd619daefd3747e8b71caf9fd16d21bd774
3
+ metadata.gz: 9e305094f3935b538af7cd8c9d0c7e7e161184c5
4
+ data.tar.gz: f7036823f2d394a118e988c74921c04c592a3014
5
5
  SHA512:
6
- metadata.gz: 490141f645014fdec44afc7a1e06d6c142c7ddd221aedd50b4e5296f2f21a38e3d2681085b90c831908e089e3a038607f6aef17add13024dec468f46ff0b5fe3
7
- data.tar.gz: c14d7a45c558a00d1e772c668bed5002b2cfe97715a9cc3c81288f5dd94f6b1baabe0a95df0437b725f4774557f546679a127ebde774485b82f05dfacee7eb34
6
+ metadata.gz: 2d53f44223ba0e643bb49cb743497df739dbb636ea83c6a92c15a1d572ecaf709637a69e077cbe6458906f9d753b7b9f461d02c4e84891bf9d1708f6db375381
7
+ data.tar.gz: 6fd789da9b2c6308c6c792582bc1d49a7bba6e130ad810b9d485234aeb5688076f768a707c240bcd66c36978c0e7417ae6ddee7d4959b0f43b0865249ef0a9e1
@@ -8,6 +8,8 @@ module Veto
8
8
  base.extend ClassMethods
9
9
  end
10
10
 
11
+
12
+
11
13
  module ClassMethods
12
14
  def with_options *args, &block
13
15
  builder.with_options(*args, &block)
@@ -75,6 +77,27 @@ module Veto
75
77
  def builder
76
78
  @builder ||= ::Veto::Builder.new(self)
77
79
  end
80
+
81
+ # Ensures that when a Validator class is subclassed, the
82
+ # validation rules will be carried into the subclass as well,
83
+ # where they may be added upon.
84
+ #
85
+ # @example
86
+ # class PersonValidator
87
+ # include Veto.validator
88
+ # validates :name, :presence => true
89
+ # end
90
+ #
91
+ # class EmployeeValidator < PersonValidator
92
+ # validates :employee_id, :presence => true
93
+ # end
94
+ #
95
+ # employee = Employee.new
96
+ # EmployeeValidator.validate!(employee) # => ["name is not present", "employee_id is not present"]
97
+
98
+ def inherited(descendant)
99
+ descendant.validate_with validators
100
+ end
78
101
  end
79
102
 
80
103
  # Initializes validator
data/lib/veto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Veto
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -493,4 +493,38 @@ describe Veto do
493
493
  validator.errors.full_messages.must_equal ["email_address is not a valid email address"]
494
494
  end
495
495
  end
496
+
497
+ describe 'validator descendents/inheritence' do
498
+ let(:validator_class) do
499
+ Class.new{
500
+ include Veto.validator
501
+
502
+ validate :create_superclass_error
503
+
504
+ def create_superclass_error
505
+ errors.add(:base, "superclass error")
506
+ end
507
+ }
508
+ end
509
+
510
+ context 'when validator is subclassed' do
511
+ let(:validator_subclass) do
512
+ Class.new(validator_class){
513
+
514
+ validate :create_subclass_error
515
+
516
+ def create_subclass_error
517
+ errors.add(:base, "subclass error")
518
+ end
519
+ }
520
+ end
521
+
522
+ it 'inherits superclass validation rules' do
523
+ validator = validator_subclass.new(entity)
524
+
525
+ validator.valid?
526
+ validator.errors.must_equal({:base=>["superclass error", "subclass error"]})
527
+ end
528
+ end
529
+ end
496
530
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Lott