diff options
-rw-r--r-- | activemodel/lib/active_model/validations/with.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 3 | ||||
-rw-r--r-- | activemodel/test/models/automobile.rb | 3 |
3 files changed, 6 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 16bd6670d1..7022f9bee5 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -139,6 +139,8 @@ module ActiveModel # class version of this method for more information. def validates_with(*args, &block) options = args.extract_options! + options[:class] = self.class + args.each do |klass| validator = klass.new(options, &block) validator.validate(self) diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index bee8ece992..cfce8fb8e6 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -284,10 +284,11 @@ class ValidationsTest < ActiveModel::TestCase auto = Automobile.new assert auto.invalid? - assert_equal 2, auto.errors.size + assert_equal 3, auto.errors.size auto.make = 'Toyota' auto.model = 'Corolla' + auto.approved = '1' assert auto.valid? end diff --git a/activemodel/test/models/automobile.rb b/activemodel/test/models/automobile.rb index ece644c40c..4df2fe8b3a 100644 --- a/activemodel/test/models/automobile.rb +++ b/activemodel/test/models/automobile.rb @@ -3,10 +3,11 @@ class Automobile validate :validations - attr_accessor :make, :model + attr_accessor :make, :model, :approved def validations validates_presence_of :make validates_length_of :model, within: 2..10 + validates_acceptance_of :approved, allow_nil: false end end |