From ea07212d9780841fbfb3368247ccc0b4bdee5bf5 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 25 Jul 2007 13:05:58 +0000 Subject: dont call #collect on a string when returning query cache results. Closes #9099 [norbert] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7239 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/query_cache.rb | 2 +- activerecord/test/query_cache_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index 191e5a3d97..e25335ecea 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -61,7 +61,7 @@ module ActiveRecord if result # perform a deep #dup in case result is an array - result = result.collect { |row| row.dup } if result.respond_to?(:collect) + result = result.collect { |row| row.dup } if result.is_a?(Array) result.dup else nil diff --git a/activerecord/test/query_cache_test.rb b/activerecord/test/query_cache_test.rb index b09ceea746..53dc581641 100644 --- a/activerecord/test/query_cache_test.rb +++ b/activerecord/test/query_cache_test.rb @@ -57,6 +57,12 @@ class QueryCacheTest < Test::Unit::TestCase "Connections should be different, Course connects to a different database" end end + + def test_cache_does_not_wrap_string_results_in_arrays + Task.cache do + assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") + end + end end uses_mocha('QueryCacheExpiryTest') do -- cgit v1.2.3