Permalink
Browse files

Run validations in the order they were declared. Closes #6657.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5588 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent d41f380 commit 88bd86e8bc165322cea4dfd6fecf092d7bb3d49e @jeremy jeremy committed Nov 20, 2006
Showing with 19 additions and 8 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +1 −1 activerecord/lib/active_record/validations.rb
  3. +16 −7 activerecord/test/validations_test.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Run validations in the order they were declared. #6657 [obrie]
+
* MySQL: detect when a NOT NULL column without a default value is misreported as default ''. Can't detect for string, text, and binary columns since '' is a legitimate default. #6156 [simon@redhillconsulting.com.au, obrie, Jeremy Kemper]
* Simplify association proxy implementation by factoring construct_scope out of method_missing. #6643 [martin]
@@ -730,7 +730,7 @@ def create!(attributes = nil)
private
def write_inheritable_set(key, methods)
existing_methods = read_inheritable_attribute(key) || []
- write_inheritable_attribute(key, methods | existing_methods)
+ write_inheritable_attribute(key, existing_methods | methods)
end
def validation_method(on)
@@ -877,7 +877,7 @@ def test_validates_acceptance_of_with_custom_error_using_quotes
d = Developer.new
d.salary = "0"
assert !d.valid?
- assert_equal d.errors.on(:salary).first, "This string contains 'single' and \"double\" quotes"
+ assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:salary).last
end
def test_validates_confirmation_of_with_custom_error_using_quotes
@@ -902,31 +902,31 @@ def test_validates_inclusion_of_with_custom_error_using_quotes
d = Developer.new
d.salary = "90,000"
assert !d.valid?
- assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:salary).first
+ assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:salary).last
end
def test_validates_length_of_with_custom_too_long_using_quotes
Developer.validates_length_of :name, :maximum => 4, :too_long=> "This string contains 'single' and \"double\" quotes"
d = Developer.new
d.name = "Jeffrey"
assert !d.valid?
- assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first
+ assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).last
end
def test_validates_length_of_with_custom_too_short_using_quotes
Developer.validates_length_of :name, :minimum => 4, :too_short=> "This string contains 'single' and \"double\" quotes"
d = Developer.new
d.name = "Joe"
assert !d.valid?
- assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first
+ assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).last
end
def test_validates_length_of_with_custom_message_using_quotes
Developer.validates_length_of :name, :minimum => 4, :message=> "This string contains 'single' and \"double\" quotes"
d = Developer.new
d.name = "Joe"
assert !d.valid?
- assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first
+ assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).last
end
def test_validates_presence_of_with_custom_message_using_quotes
@@ -942,7 +942,7 @@ def test_validates_uniqueness_of_with_custom_message_using_quotes
d = Developer.new
d.name = "David"
assert !d.valid?
- assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first
+ assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).last
end
def test_validates_associated_with_custom_message_using_quotes
@@ -951,7 +951,7 @@ def test_validates_associated_with_custom_message_using_quotes
r = Reply.create("title" => "A reply", "content" => "with content!")
r.topic = Topic.create("title" => "uhohuhoh")
assert !r.valid?
- assert_equal "This string contains 'single' and \"double\" quotes", r.errors.on(:topic).first
+ assert_equal "This string contains 'single' and \"double\" quotes", r.errors.on(:topic).last
end
def test_conditional_validation_using_method_true
@@ -1025,6 +1025,15 @@ def test_errors_to_xml
assert xml.include?("<error>Title is Wrong Create</error>")
assert xml.include?("<error>Content Empty</error>")
end
+
+ def test_validation_order
+ Topic.validates_presence_of :title
+ Topic.validates_length_of :title, :minimum => 2
+
+ t = Topic.new("title" => "")
+ assert !t.valid?
+ assert_equal "can't be blank", t.errors.on("title").first
+ end
end

0 comments on commit 88bd86e

Please sign in to comment.