Skip to content

Commit

Permalink
Ensure QueryCache doesn't try to dup numeric results (does not affect…
Browse files Browse the repository at this point in the history
… 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
NZKoz committed Sep 2, 2007
1 parent 6b9b511 commit b18d956
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 6 additions & 5 deletions activerecord/lib/active_record/query_cache.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ def cache(sql)
@query_cache[sql] = yield @query_cache[sql] = yield
end end


if result case result
# perform a deep #dup in case result is an array when Array
result = result.collect { |row| row.dup } if result.is_a?(Array) result.collect { |row| row.dup }
result.dup when Numeric, NilClass, FalseClass
result
else else
nil result.dup
end end
end end


Expand Down
8 changes: 7 additions & 1 deletion activerecord/test/query_cache_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ def test_find_queries_with_cache
assert_queries(1) { Task.find(1); Task.find(1) } assert_queries(1) { Task.find(1); Task.find(1) }
end end
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 def test_query_cache_returned
assert_not_equal ActiveRecord::QueryCache, Task.connection.class assert_not_equal ActiveRecord::QueryCache, Task.connection.class
Task.cache do Task.cache do
Expand Down

0 comments on commit b18d956

Please sign in to comment.