diff options
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 13 | ||||
-rw-r--r-- | activemodel/test/models/automobile.rb | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 578ffc27dd..aa75b8b0d2 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -4,6 +4,7 @@ require 'cases/helper' require 'models/topic' require 'models/reply' require 'models/custom_reader' +require 'models/automobile' class ValidationsTest < ActiveModel::TestCase @@ -252,4 +253,16 @@ class ValidationsTest < ActiveModel::TestCase Topic.validates_length_of :title, :minimum => 10 assert_equal 10, Topic.validators_on(:title).first.options[:minimum] end + + def test_validations_on_the_instance_level + auto = Automobile.new + + assert auto.invalid? + assert_equal 2, auto.errors.size + + auto.make = 'Toyota' + auto.model = 'Corolla' + + assert auto.valid? + end end diff --git a/activemodel/test/models/automobile.rb b/activemodel/test/models/automobile.rb new file mode 100644 index 0000000000..021ea61c80 --- /dev/null +++ b/activemodel/test/models/automobile.rb @@ -0,0 +1,12 @@ +class Automobile + include ActiveModel::Validations + + validate :validations + + attr_accessor :make, :model + + def validations + validates_presence_of :make + validates_length_of :model, :within => 2..10 + end +end
\ No newline at end of file |