aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/validations_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-22 23:40:44 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-22 23:40:44 +0000
commitab4c640b96f1bf1882f78847d0357e7492b621b1 (patch)
tree4b13433c1c00f73c6a51afc0dfc32f861b65a3da /activerecord/test/validations_test.rb
parentd834b65b540665db81cca51fdc828d0c91e314a6 (diff)
downloadrails-ab4c640b96f1bf1882f78847d0357e7492b621b1.tar.gz
rails-ab4c640b96f1bf1882f78847d0357e7492b621b1.tar.bz2
rails-ab4c640b96f1bf1882f78847d0357e7492b621b1.zip
Added scope option to validation_uniqueness #349 [Kent Sibilev]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@259 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/validations_test.rb')
-rwxr-xr-xactiverecord/test/validations_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index f5735de59d..db6aab653b 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -204,6 +204,25 @@ class ValidationsTest < Test::Unit::TestCase
assert t2.save, "Should now save t2 as unique"
end
+ def test_validate_uniqueness_with_scope
+ Reply.validates_uniqueness_of(:content, :scope => "parent_id")
+
+ t = Topic.create("title" => "I'm unique!")
+
+ r1 = t.replies.create "title" => "r1", "content" => "hello world"
+ assert r1.valid?, "Saving r1"
+
+ r2 = t.replies.create "title" => "r2", "content" => "hello world"
+ assert !r2.valid?, "Saving r2 first time"
+
+ r2.content = "something else"
+ assert r2.save, "Saving r2 second time"
+
+ t2 = Topic.create("title" => "I'm unique too!")
+ r3 = t2.replies.create "title" => "r3", "content" => "hello world"
+ assert r3.valid?, "Saving r3"
+ end
+
def test_validate_format
Topic.validates_format_of(:title, :content, :with => /^Validation macros rule!$/, :message => "is bad data")