mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
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
This commit is contained in:
@@ -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 @@ module ActiveRecord
|
||||
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 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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,7 +902,7 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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
|
||||
@@ -910,7 +910,7 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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
|
||||
@@ -918,7 +918,7 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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
|
||||
@@ -926,7 +926,7 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user