Permalink
Browse files

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
  • Loading branch information...
1 parent 6b9b511 commit b18d9568a64b9b3605db90f93e6fcbf77344d010 @NZKoz NZKoz committed Sep 2, 2007
Showing with 13 additions and 6 deletions.
  1. +6 −5 activerecord/lib/active_record/query_cache.rb
  2. +7 −1 activerecord/test/query_cache_test.rb
@@ -59,12 +59,13 @@ def cache(sql)
@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
@@ -16,7 +16,13 @@ def test_find_queries_with_cache
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

0 comments on commit b18d956

Please sign in to comment.