diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2016-03-08 11:46:11 +0900 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2016-07-30 15:28:33 +0900 |
commit | 411e4597d552aa091cfe3dc76a83bdaffe02da1a (patch) | |
tree | a7c06d6df27915249734789f7f995b55f17e79e6 /activerecord/test/cases/associations | |
parent | 815b730b1b79158511f9f4c8465c476b9fe9b7e0 (diff) | |
download | rails-411e4597d552aa091cfe3dc76a83bdaffe02da1a.tar.gz rails-411e4597d552aa091cfe3dc76a83bdaffe02da1a.tar.bz2 rails-411e4597d552aa091cfe3dc76a83bdaffe02da1a.zip |
Preserve readonly flag only for readonly association
Fixes #24093
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 80d9a6083b..477bc9d1c2 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1424,6 +1424,24 @@ class EagerAssociationTest < ActiveRecord::TestCase assert david.readonly_comments.first.readonly? end + test "eager-loading non-readonly association" do + # has_one + firm = Firm.where(id: "1").eager_load(:account).first! + assert_not firm.account.readonly? + + # has_and_belongs_to_many + project = Project.where(id: "2").eager_load(:developers).first! + assert_not project.developers.first.readonly? + + # has_many :through + david = Author.where(id: "1").eager_load(:comments).first! + assert_not david.comments.first.readonly? + + # belongs_to + post = Post.where(id: "1").eager_load(:author).first! + assert_not post.author.readonly? + end + test "eager-loading readonly association" do # has-one firm = Firm.where(id: "1").eager_load(:readonly_account).first! @@ -1438,8 +1456,8 @@ class EagerAssociationTest < ActiveRecord::TestCase assert david.readonly_comments.first.readonly? # belongs_to - post = Post.where(id: "1").eager_load(:author).first! - assert post.author.readonly? + post = Post.where(id: "1").eager_load(:readonly_author).first! + assert post.readonly_author.readonly? end test "preloading a polymorphic association with references to the associated table" do |