diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-04-12 20:42:13 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-04-12 20:42:13 +0000 |
commit | bdb2a2f1cb645a5dfde2de3b03f0f22b54b8b5d0 (patch) | |
tree | 3cab5b2cd876df9de682416fe132c882aa5deeac /activerecord/test | |
parent | 7e76740d2a5ee14b308c7e40f9c95354d19f6189 (diff) | |
download | rails-bdb2a2f1cb645a5dfde2de3b03f0f22b54b8b5d0.tar.gz rails-bdb2a2f1cb645a5dfde2de3b03f0f22b54b8b5d0.tar.bz2 rails-bdb2a2f1cb645a5dfde2de3b03f0f22b54b8b5d0.zip |
Add :case_sensitive option to validates_uniqueness_of (closes #3090) [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4207 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/validations_test.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index d7ba74597c..b73058a64b 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -304,6 +304,37 @@ class ValidationsTest < Test::Unit::TestCase assert !r3.save, "Saving r3 the third time." end + def test_validate_case_insensitive_uniqueness + Topic.validates_uniqueness_of(:title, :parent_id, :case_sensitive => false, :allow_nil => true) + + t = Topic.new("title" => "I'm unique!", :parent_id => 2) + assert t.save, "Should save t as unique" + + t.content = "Remaining unique" + assert t.save, "Should still save t as unique" + + t2 = Topic.new("title" => "I'm UNIQUE!", :parent_id => 1) + assert !t2.valid?, "Shouldn't be valid" + assert !t2.save, "Shouldn't save t2 as unique" + assert t2.errors.on(:title) + assert t2.errors.on(:parent_id) + assert_equal "has already been taken", t2.errors.on(:title) + + t2.title = "I'm truly UNIQUE!" + assert !t2.valid?, "Shouldn't be valid" + assert !t2.save, "Shouldn't save t2 as unique" + assert_nil t2.errors.on(:title) + assert t2.errors.on(:parent_id) + + t2.parent_id = 3 + assert t2.save, "Should now save t2 as unique" + + t2.parent_id = nil + t2.title = nil + assert t2.valid?, "should validate with nil" + assert t2.save, "should save with nil" + end + def test_validate_format Topic.validates_format_of(:title, :content, :with => /^Validation\smacros \w+!$/, :message => "is bad data") |