aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-06-19 15:18:35 -0400
committerGitHub <noreply@github.com>2018-06-19 15:18:35 -0400
commit897946f2141662a072a8917946737218df82e204 (patch)
tree55f7b2e46f33072a36aec2fe432cdc2a52632b27 /activerecord/test/cases
parentee21e058424b2cb55bf74981c28b1ac0fb98b576 (diff)
parent13f0d6ebd38ad08f7550db784d64c5c6ab7f56f9 (diff)
downloadrails-897946f2141662a072a8917946737218df82e204.tar.gz
rails-897946f2141662a072a8917946737218df82e204.tar.bz2
rails-897946f2141662a072a8917946737218df82e204.zip
Merge pull request #33074 from lsylvester/optimize-pluck
Reduce Memory Allocation when using .pluck
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/calculations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 6ceac59eec..5c9ed42173 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -642,6 +642,18 @@ class CalculationsTest < ActiveRecord::TestCase
assert_equal [ topic.written_on ], relation.pluck(:written_on)
end
+ def test_pluck_with_type_cast_does_not_corrupt_the_query_cache
+ topic = topics(:first)
+ relation = Topic.where(id: topic.id)
+ assert_queries 1 do
+ Topic.cache do
+ kind = relation.select(:written_on).load.first.read_attribute_before_type_cast(:written_on).class
+ relation.pluck(:written_on)
+ assert_kind_of kind, relation.select(:written_on).load.first.read_attribute_before_type_cast(:written_on)
+ end
+ end
+ end
+
def test_pluck_and_distinct
assert_equal [50, 53, 55, 60], Account.order(:credit_limit).distinct.pluck(:credit_limit)
end