aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-02-26 03:36:06 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-02-26 03:36:06 -0800
commit06eb872035a115852d92121c037e3c54a7a10f58 (patch)
treea6b8de1e96448eb6959b166090e6647b12b448a1 /activerecord/test/cases
parent0761bb029886bb6920a404ecf409013f83a44f58 (diff)
parent905b7df1fac8332547b9eb7fc4d5b083c6fc1031 (diff)
downloadrails-06eb872035a115852d92121c037e3c54a7a10f58.tar.gz
rails-06eb872035a115852d92121c037e3c54a7a10f58.tar.bz2
rails-06eb872035a115852d92121c037e3c54a7a10f58.zip
Merge pull request #9430 from authorNari/backport-7072-to-3-2-stable
Backported #7072 to 3-2-stable. Use database value for uniqueness validation scope
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/validations/uniqueness_validation_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb
index 8708117129..0f9cb10f0f 100644
--- a/activerecord/test/cases/validations/uniqueness_validation_test.rb
+++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb
@@ -22,6 +22,14 @@ end
class Thaumaturgist < IneptWizard
end
+class ReplyTitle; end
+
+class ReplyWithTitleObject < Reply
+ validates_uniqueness_of :content, :scope => :title
+
+ def title; ReplyTitle.new; end
+end
+
class UniquenessValidationTest < ActiveRecord::TestCase
fixtures :topics, 'warehouse-things', :developers
@@ -80,6 +88,14 @@ class UniquenessValidationTest < ActiveRecord::TestCase
assert r3.valid?, "Saving r3"
end
+ def test_validate_uniqueness_with_composed_attribute_scope
+ r1 = ReplyWithTitleObject.create "title" => "r1", "content" => "hello world"
+ assert r1.valid?, "Saving r1"
+
+ r2 = ReplyWithTitleObject.create "title" => "r1", "content" => "hello world"
+ assert !r2.valid?, "Saving r2 first time"
+ end
+
def test_validate_uniqueness_scoped_to_defining_class
t = Topic.create("title" => "What, me worry?")