diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-26 05:09:22 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-26 05:09:22 +0900 |
commit | 8ff70cad3d634da344d741c49304a69572cbe188 (patch) | |
tree | 6423ed73fc689e6cb515df923d44a6cab82c16d1 /activerecord/test/cases/associations | |
parent | dccdcfb5a3743097d94b1c81ed106ebc398e6674 (diff) | |
download | rails-8ff70cad3d634da344d741c49304a69572cbe188.tar.gz rails-8ff70cad3d634da344d741c49304a69572cbe188.tar.bz2 rails-8ff70cad3d634da344d741c49304a69572cbe188.zip |
Association creation and finding should work consistently (#32048)
This is an alternative of #29722, and revert of #29601 and a1fcbd9.
Currently, association creation and normal association finding doesn't
respect `store_full_sti_class`. But eager loading and preloading respect
the setting. This means that if set `store_full_sti_class = false`
(`true` by default), eager loading and preloading can not find
created polymorphic records.
Association creation and finding should work consistently.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb index 8754889143..4776e11128 100644 --- a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb +++ b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb @@ -11,21 +11,33 @@ module Namespaced end end -class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase +module PolymorphicFullStiClassNamesSharedTest def setup + @old_store_full_sti_class = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = store_full_sti_class + post = Namespaced::Post.create(title: "Great stuff", body: "This is not", author_id: 1) @tagging = Tagging.create(taggable: post) - @old = ActiveRecord::Base.store_full_sti_class end def teardown - ActiveRecord::Base.store_full_sti_class = @old + ActiveRecord::Base.store_full_sti_class = @old_store_full_sti_class + end + + def test_class_names + ActiveRecord::Base.store_full_sti_class = false + post = Namespaced::Post.find_by_title("Great stuff") + assert_equal @tagging, post.tagging + + ActiveRecord::Base.store_full_sti_class = true + post = Namespaced::Post.find_by_title("Great stuff") + assert_equal @tagging, post.tagging end def test_class_names_with_includes ActiveRecord::Base.store_full_sti_class = false post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff") - assert_nil post.tagging + assert_equal @tagging, post.tagging ActiveRecord::Base.store_full_sti_class = true post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff") @@ -35,10 +47,28 @@ class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase def test_class_names_with_eager_load ActiveRecord::Base.store_full_sti_class = false post = Namespaced::Post.eager_load(:tagging).find_by_title("Great stuff") - assert_nil post.tagging + assert_equal @tagging, post.tagging ActiveRecord::Base.store_full_sti_class = true post = Namespaced::Post.eager_load(:tagging).find_by_title("Great stuff") assert_equal @tagging, post.tagging end end + +class PolymorphicFullStiClassNamesTest < ActiveRecord::TestCase + include PolymorphicFullStiClassNamesSharedTest + + private + def store_full_sti_class + true + end +end + +class PolymorphicNonFullStiClassNamesTest < ActiveRecord::TestCase + include PolymorphicFullStiClassNamesSharedTest + + private + def store_full_sti_class + false + end +end |