diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-22 14:48:28 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-25 13:46:54 +0200 |
commit | 5706d290b0a2501a713fadfb76d9e45c24d26e6a (patch) | |
tree | 34123891c234cf54329f11d0e5a2e57626b801d8 /activerecord/test | |
parent | 48933542ab4b83bab9ae5422bd95fd78abee79fa (diff) | |
download | rails-5706d290b0a2501a713fadfb76d9e45c24d26e6a.tar.gz rails-5706d290b0a2501a713fadfb76d9e45c24d26e6a.tar.bz2 rails-5706d290b0a2501a713fadfb76d9e45c24d26e6a.zip |
`preload` preserves readonly flag on associations. #15853
This is a partial fix for #15853. It only works when a `preload`
is issued and not an `eager_load`. I've added a skipped failing
test-case to keep in mind that we need to deal with `eager_load`.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 910067666a..21912fdf0f 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1261,4 +1261,33 @@ class EagerAssociationTest < ActiveRecord::TestCase Author.eager_load(:posts_with_signature).to_a end end + + test "preloading readonly association" do + # has-one + firm = Firm.where(id: "1").preload(:readonly_account).first! + assert firm.readonly_account.readonly? + + # has_and_belongs_to_many + project = Project.where(id: "2").preload(:readonly_developers).first! + assert project.readonly_developers.first.readonly? + + # has-many :through + david = Author.where(id: "1").preload(:readonly_comments).first! + assert david.readonly_comments.first.readonly? + end + + test "eager-loading readonly association" do + skip "eager_load does not yet preserve readonly associations" + # has-one + firm = Firm.where(id: "1").eager_load(:readonly_account).first! + assert firm.readonly_account.readonly? + + # has_and_belongs_to_many + project = Project.where(id: "2").eager_load(:readonly_developers).first! + assert project.readonly_developers.first.readonly? + + # has-many :through + david = Author.where(id: "1").eager_load(:readonly_comments).first! + assert david.readonly_comments.first.readonly? + end end |