aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/validations_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-10 16:02:11 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-10 16:02:11 +0000
commitaaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69 (patch)
treec2c443eae085e4fe528cd1223ed15147706dc7c7 /activerecord/test/validations_test.rb
parent0b92b7de2f752bee6c4c950ac9090e5bce3b63bf (diff)
downloadrails-aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69.tar.gz
rails-aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69.tar.bz2
rails-aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69.zip
Added Base.validate_uniqueness thatv alidates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named "davidhh".
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@108 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/validations_test.rb')
-rwxr-xr-xactiverecord/test/validations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index 2d6c795d92..1abdfa062d 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -172,4 +172,22 @@ class ValidationsTest < Test::Unit::TestCase
assert t.save
end
+
+ def test_validate_uniqueness
+ Topic.validate_uniqueness(:title)
+
+ 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?, "Shouldn't be valid"
+ assert !t2.save, "Shouldn't save t2 as unique"
+ assert_equal "has already been taken", t2.errors.on(:title)
+
+ t2.title = "Now Im really also unique"
+ assert t2.save, "Should now save t2 as unique"
+ end
end \ No newline at end of file