diff options
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/validations_test.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index f472f50f9b..7520e0331d 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -54,7 +54,7 @@ module ActiveModel attr_accessor :validation_context - class_attribute :_validators + class_inheritable_accessor :_validators self._validators = Hash.new { |h,k| h[k] = [] } end diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 9527404f03..3f1b0e333f 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -9,6 +9,8 @@ require 'models/guid' 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 @@ class ValidationsTest < ActiveRecord::TestCase 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 |