aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/validations/association_validation_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/validations/association_validation_test.rb')
-rw-r--r--activerecord/test/cases/validations/association_validation_test.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb
index f155b9bc40..7ac34bc71e 100644
--- a/activerecord/test/cases/validations/association_validation_test.rb
+++ b/activerecord/test/cases/validations/association_validation_test.rb
@@ -86,7 +86,7 @@ class AssociationValidationTest < ActiveRecord::TestCase
assert !r.valid?
assert r.errors[:topic].any?
- r.topic = Topic.find :first
+ r.topic = Topic.first
assert r.valid?
end
@@ -118,4 +118,21 @@ class AssociationValidationTest < ActiveRecord::TestCase
end
end
+ def test_validates_associated_models_in_the_same_context
+ Topic.validates_presence_of :title, :on => :custom_context
+ Topic.validates_associated :replies
+ Reply.validates_presence_of :title, :on => :custom_context
+
+ t = Topic.new('title' => '')
+ r = t.replies.new('title' => '')
+
+ assert t.valid?
+ assert !t.valid?(:custom_context)
+
+ t.title = "Longer"
+ assert !t.valid?(:custom_context), "Should NOT be valid if the associated object is not valid in the same context."
+
+ r.title = "Longer"
+ assert t.valid?(:custom_context), "Should be valid if the associated object is not valid in the same context."
+ end
end