diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-16 13:43:44 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-16 14:28:19 -0800 |
commit | c801f233df9d20c59d9756a5279365603dc5cbbd (patch) | |
tree | f6a530c622aa41f5003595898a8abf2e5e9614c8 /activerecord/test/cases/associations | |
parent | 1395545404eb0b28af08108b50d7cfe3fa9a5357 (diff) | |
download | rails-c801f233df9d20c59d9756a5279365603dc5cbbd.tar.gz rails-c801f233df9d20c59d9756a5279365603dc5cbbd.tar.bz2 rails-c801f233df9d20c59d9756a5279365603dc5cbbd.zip |
reloading an association will properly set attributes of instantiated objects. Thanks Brian Palmer [#5802 state:resolved]
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ecfc769f3a..33c53e695b 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1282,4 +1282,25 @@ class HasManyAssociationsTest < ActiveRecord::TestCase comment = post.comments.build assert post.comments.include?(comment) end + + def test_load_target_respects_protected_attributes + topic = Topic.create! + reply = topic.replies.create(:title => "reply 1") + reply.approved = false + reply.save! + + # Save with a different object instance, so the instance that's still held + # in topic.relies doesn't know about the changed attribute. + reply2 = Reply.find(reply.id) + reply2.approved = true + reply2.save! + + # Force loading the collection from the db. This will merge the existing + # object (reply) with what gets loaded from the db (which includes the + # changed approved attribute). approved is a protected attribute, so if mass + # assignment is used, it won't get updated and will still be false. + first = topic.replies.to_a.first + assert_equal reply.id, first.id + assert_equal true, first.approved? + end end |