diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-17 00:27:39 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-17 00:27:39 -0800 |
commit | 5f8274efe128ffeec8fa3179460f5167a078f007 (patch) | |
tree | 8a53a4bdb2749ae10c1145fcd9fe0a23e9ecce88 /activerecord/test | |
parent | 81e837e810460d066a2e5fc5a795366ec8ab2313 (diff) | |
parent | 9b15e01c219013825275e7e10140d9883d148c8c (diff) | |
download | rails-5f8274efe128ffeec8fa3179460f5167a078f007.tar.gz rails-5f8274efe128ffeec8fa3179460f5167a078f007.tar.bz2 rails-5f8274efe128ffeec8fa3179460f5167a078f007.zip |
Merge pull request #4490 from EmmanuelOga/master
when validating a record, if a validation context is used, use the same context when validating related records
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/validations/association_validation_test.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb index f155b9bc40..c72b7b35cd 100644 --- a/activerecord/test/cases/validations/association_validation_test.rb +++ b/activerecord/test/cases/validations/association_validation_test.rb @@ -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 |