diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-09-02 23:52:58 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-09-02 23:52:58 +0000 |
commit | b18d9568a64b9b3605db90f93e6fcbf77344d010 (patch) | |
tree | ee36d93a5d4e614cd9a8faea80a084d7e99a6c3f /activerecord | |
parent | 6b9b511de10ed7870d831259e18c38af627f92c9 (diff) | |
download | rails-b18d9568a64b9b3605db90f93e6fcbf77344d010.tar.gz rails-b18d9568a64b9b3605db90f93e6fcbf77344d010.tar.bz2 rails-b18d9568a64b9b3605db90f93e6fcbf77344d010.zip |
Ensure QueryCache doesn't try to dup numeric results (does not affect the major OS database). Closes #7661 [tomafro, nzkoz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7399 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 11 | ||||
-rw-r--r-- | activerecord/test/query_cache_test.rb | 8 |
2 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index e25335ecea..e598de07e2 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -59,12 +59,13 @@ module ActiveRecord @query_cache[sql] = yield end - if result - # perform a deep #dup in case result is an array - result = result.collect { |row| row.dup } if result.is_a?(Array) - result.dup + case result + when Array + result.collect { |row| row.dup } + when Numeric, NilClass, FalseClass + result else - nil + result.dup end end diff --git a/activerecord/test/query_cache_test.rb b/activerecord/test/query_cache_test.rb index 53dc581641..8c8ae69776 100644 --- a/activerecord/test/query_cache_test.rb +++ b/activerecord/test/query_cache_test.rb @@ -16,7 +16,13 @@ class QueryCacheTest < Test::Unit::TestCase assert_queries(1) { Task.find(1); Task.find(1) } end end - + + def test_count_queries_with_cache + Task.cache do + assert_queries(1) { Task.count; Task.count } + end + end + def test_query_cache_returned assert_not_equal ActiveRecord::QueryCache, Task.connection.class Task.cache do |