aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorJosh Kalderimis <josh.kalderimis@gmail.com>2010-05-11 12:28:42 +0200
committerCarl Lerche <carllerche@mac.com>2010-05-13 13:57:37 -0700
commit9131a88bb8e82f139ec49b4057fb6065ba0a2c6a (patch)
tree5586a5c35711866acdbc2408cc70e50197229fae /activemodel/test
parent2203c781a7dfa8b0c8b6c97cd318d941f9fbb26c (diff)
downloadrails-9131a88bb8e82f139ec49b4057fb6065ba0a2c6a.tar.gz
rails-9131a88bb8e82f139ec49b4057fb6065ba0a2c6a.tar.bz2
rails-9131a88bb8e82f139ec49b4057fb6065ba0a2c6a.zip
validation macros can now be used within an instance
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/validations_test.rb13
-rw-r--r--activemodel/test/models/automobile.rb12
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