Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Validators should at model level and not at AR:Base level [Closes #4804]

[#4804 state:resolved]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
commit e11bb95d56ed77b10d54d9dfe5a3cc4aa48b3a61 1 parent 9838156
@neerajdotname neerajdotname authored dhh committed
View
2  activemodel/lib/active_model/validations.rb
@@ -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
View
10 activerecord/test/cases/validations_test.rb
@@ -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'
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.