aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorbeerlington <pete@lette.us>2012-07-17 07:27:54 -0400
committerbeerlington <pete@lette.us>2012-07-17 07:27:54 -0400
commit0c3c2279e7f9b92f606356debc2efe0a93752a69 (patch)
treefc443a8c8c616869eab1056f1723a0c5ad9ffb25 /activerecord/test
parent15bfaa3d13f84c689f9182c0be658ddde019e572 (diff)
downloadrails-0c3c2279e7f9b92f606356debc2efe0a93752a69.tar.gz
rails-0c3c2279e7f9b92f606356debc2efe0a93752a69.tar.bz2
rails-0c3c2279e7f9b92f606356debc2efe0a93752a69.zip
Fixes "Cannot visit ..." with validates_uniqueness_of
Fixes issue with overrding ActiveRecord reader methods with a composed object and using that attribute as the scope of a validates_uniqueness_of validation.
Diffstat (limited to 'activerecord/test')
-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 c173ee9a15..ea5e055289 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
@@ -104,6 +112,14 @@ class UniquenessValidationTest < ActiveRecord::TestCase
assert !r2.valid?, "Saving r2 first time"
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_with_object_arg
Reply.validates_uniqueness_of(:topic)