diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-31 01:50:07 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-31 01:50:07 +0000 |
commit | c52771e7a022a45f2b70bfc8f29b02d008fb9b15 (patch) | |
tree | 247e874a15fbf20d6e0c13d35cc11f4f7e73f3c6 /activerecord/test | |
parent | 97019f9f5a94fa102debe13f5a957726e7d4783e (diff) | |
download | rails-c52771e7a022a45f2b70bfc8f29b02d008fb9b15.tar.gz rails-c52771e7a022a45f2b70bfc8f29b02d008fb9b15.tar.bz2 rails-c52771e7a022a45f2b70bfc8f29b02d008fb9b15.zip |
Fix case-sensitive validates_uniqueness_of. Closes #11366 [miloops]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/cases/validations_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index d5b8b4d88b..d0b4902bce 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -437,6 +437,30 @@ class ValidationsTest < ActiveRecord::TestCase assert t2.save, "should save with nil" end + def test_validate_case_sensitive_uniqueness + Topic.validates_uniqueness_of(:title, :case_sensitive => true, :allow_nil => true) + + t = Topic.new("title" => "I'm unique!") + 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!") + assert t2.valid?, "Should be valid" + assert t2.save, "Should save t2 as unique" + assert !t2.errors.on(:title) + assert !t2.errors.on(:parent_id) + assert_not_equal "has already been taken", t2.errors.on(:title) + + t3 = Topic.new("title" => "I'M uNiQUe!") + assert t3.valid?, "Should be valid" + assert t3.save, "Should save t2 as unique" + assert !t3.errors.on(:title) + assert !t3.errors.on(:parent_id) + assert_not_equal "has already been taken", t3.errors.on(:title) + end + def test_validate_uniqueness_with_non_standard_table_names i1 = WarehouseThing.create(:value => 1000) assert !i1.valid?, "i1 should not be valid" |