mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user