aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-06-28 14:42:55 -0400
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-06-28 14:42:55 -0400
commit316e3c2ff1ff6efb2d1cf43cae1cbd4bf93cf16e (patch)
treeee1623906b8e0fbe1015784715354ea868b02d34 /activerecord/test/cases/associations
parent33de72667a026f8a9c188189bcc191976a7c397a (diff)
parentb084fe9054759263329cfe36f2d4de13567d67f6 (diff)
downloadrails-316e3c2ff1ff6efb2d1cf43cae1cbd4bf93cf16e.tar.gz
rails-316e3c2ff1ff6efb2d1cf43cae1cbd4bf93cf16e.tar.bz2
rails-316e3c2ff1ff6efb2d1cf43cae1cbd4bf93cf16e.zip
Merge pull request #29601 from kamipo/fix_eager_loading_to_respect_store_full_sti_class
Fix eager loading to respect `store_full_sti_class` setting
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb27
1 files changed, 17 insertions, 10 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 4f0fe3236e..61f39b4136 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,25 +11,32 @@ end
class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase
def setup
- generate_test_objects
- end
-
- def generate_test_objects
post = Namespaced::Post.create(title: "Great stuff", body: "This is not", author_id: 1)
- Tagging.create(taggable: post)
+ @tagging = Tagging.create(taggable: post)
+ @old = ActiveRecord::Base.store_full_sti_class
end
- def test_class_names
- old = ActiveRecord::Base.store_full_sti_class
+ def teardown
+ ActiveRecord::Base.store_full_sti_class = @old
+ 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
ActiveRecord::Base.store_full_sti_class = true
post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff")
- assert_instance_of Tagging, post.tagging
- ensure
- ActiveRecord::Base.store_full_sti_class = old
+ assert_equal @tagging, post.tagging
+ end
+
+ 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
+
+ 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