diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-28 03:07:56 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-04 02:34:00 +0900 |
commit | d35875b7a3f559155a9378cbe9203b0b8ea580f9 (patch) | |
tree | e8d8c225cf2309976327a94370f09f901023a9b1 /activerecord/test | |
parent | 75a24602edacd3e66b5c38c2b5efe885dfdd14ab (diff) | |
download | rails-d35875b7a3f559155a9378cbe9203b0b8ea580f9.tar.gz rails-d35875b7a3f559155a9378cbe9203b0b8ea580f9.tar.bz2 rails-d35875b7a3f559155a9378cbe9203b0b8ea580f9.zip |
Extract all `base_class.name` as `polymorphic_name`
This is an alternative of #29722, and follow up of #32048.
This does not change the current behavior, but makes it easier to modify
all polymorphic names consistently.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb | 32 |
1 files changed, 23 insertions, 9 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 4776e11128..5fca972aee 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 @@ -8,6 +8,10 @@ module Namespaced class Post < ActiveRecord::Base self.table_name = "posts" has_one :tagging, as: :taggable, class_name: "Tagging" + + def self.polymorphic_name + sti_name + end end end @@ -25,34 +29,44 @@ module PolymorphicFullStiClassNamesSharedTest end def test_class_names - ActiveRecord::Base.store_full_sti_class = false + ActiveRecord::Base.store_full_sti_class = !store_full_sti_class post = Namespaced::Post.find_by_title("Great stuff") - assert_equal @tagging, post.tagging + assert_nil post.tagging - ActiveRecord::Base.store_full_sti_class = true + ActiveRecord::Base.store_full_sti_class = store_full_sti_class 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 + ActiveRecord::Base.store_full_sti_class = !store_full_sti_class post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff") - assert_equal @tagging, post.tagging + assert_nil post.tagging - ActiveRecord::Base.store_full_sti_class = true + ActiveRecord::Base.store_full_sti_class = store_full_sti_class post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff") assert_equal @tagging, post.tagging end def test_class_names_with_eager_load - ActiveRecord::Base.store_full_sti_class = false + ActiveRecord::Base.store_full_sti_class = !store_full_sti_class post = Namespaced::Post.eager_load(:tagging).find_by_title("Great stuff") - assert_equal @tagging, post.tagging + assert_nil post.tagging - ActiveRecord::Base.store_full_sti_class = true + ActiveRecord::Base.store_full_sti_class = store_full_sti_class post = Namespaced::Post.eager_load(:tagging).find_by_title("Great stuff") assert_equal @tagging, post.tagging end + + def test_class_names_with_find_by + post = Namespaced::Post.find_by_title("Great stuff") + + ActiveRecord::Base.store_full_sti_class = !store_full_sti_class + assert_nil Tagging.find_by(taggable: post) + + ActiveRecord::Base.store_full_sti_class = store_full_sti_class + assert_equal @tagging, Tagging.find_by(taggable: post) + end end class PolymorphicFullStiClassNamesTest < ActiveRecord::TestCase |