aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-12-02 04:30:46 +0000
committerMarcel Molina <marcel@vernix.org>2005-12-02 04:30:46 +0000
commit2e42167058fa6e528237f4d78a4cb0bd6c2e099d (patch)
treea68d8db71f2be0104a795aa98bfca7d3fdca7d3a /activerecord/test
parent3d0e3c92900ff3dd1ddef7c94c201698e71ca9d5 (diff)
downloadrails-2e42167058fa6e528237f4d78a4cb0bd6c2e099d.tar.gz
rails-2e42167058fa6e528237f4d78a4cb0bd6c2e099d.tar.bz2
rails-2e42167058fa6e528237f4d78a4cb0bd6c2e099d.zip
Allow validate_uniqueness_of to be scoped by more than just one column. Closes #1559.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3206 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/validations_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index f0d75c96cf..811585b203 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -280,6 +280,30 @@ class ValidationsTest < Test::Unit::TestCase
assert r3.valid?, "Saving r3"
end
+ def test_validate_uniqueness_with_scope_array
+ Reply.validates_uniqueness_of(:author_name, :scope => [:author_email_address, :parent_id])
+
+ t = Topic.create("title" => "The earth is actually flat!")
+
+ r1 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're crazy!", "content" => "Crazy reply"
+ assert r1.valid?, "Saving r1"
+
+ r2 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're crazy!", "content" => "Crazy reply again..."
+ assert !r2.valid?, "Saving r2. Double reply by same author."
+
+ r2.author_email_address = "jeremy_alt_email@rubyonrails.com"
+ assert r2.save, "Saving r2 the second time."
+
+ r3 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy_alt_email@rubyonrails.com", "title" => "You're wrong", "content" => "It's cubic"
+ assert !r3.valid?, "Saving r3"
+
+ r3.author_name = "jj"
+ assert r3.save, "Saving r3 the second time."
+
+ r3.author_name = "jeremy"
+ assert !r3.save, "Saving r3 the third time."
+ end
+
def test_validate_format
Topic.validates_format_of(:title, :content, :with => /^Validation\smacros \w+!$/, :message => "is bad data")