Skip to content

Commit

Permalink
Validators should at model level and not at AR:Base level [Closes #4804]
Browse files Browse the repository at this point in the history
[#4804 state:resolved]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information
Neeraj Singh authored and dhh committed Jun 10, 2010
1 parent 9838156 commit e11bb95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/validations.rb
Expand Up @@ -54,7 +54,7 @@ module Validations

attr_accessor :validation_context

class_attribute :_validators
class_inheritable_accessor :_validators
self._validators = Hash.new { |h,k| h[k] = [] }
end

Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/validations_test.rb
Expand Up @@ -9,6 +9,8 @@
require 'models/owner'
require 'models/pet'
require 'models/event'
require 'models/parrot'
require 'models/company'

class ProtectedPerson < ActiveRecord::Base
set_table_name 'people'
Expand Down Expand Up @@ -189,4 +191,12 @@ def test_validate_is_deprecated_on_update
end
assert_equal ["always invalid", "invalid on update"], p.errors[:name]
end

def test_validators
assert_equal 1, Parrot.validators.size
assert_equal 1, Company.validators.size
assert_equal 1, Parrot.validators_on(:name).size
assert_equal 1, Company.validators_on(:name).size
end

end

0 comments on commit e11bb95

Please sign in to comment.