aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/query_cache_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-07-25 03:48:30 +0000
committerRick Olson <technoweenie@gmail.com>2007-07-25 03:48:30 +0000
commitf5ea6f880f365c5383d029bddc917baa82e56d55 (patch)
treeb14e2d0a722dedff18f85918c3e70b73ab6a406c /activerecord/test/query_cache_test.rb
parentd51e7f8252269492a511a9eb41f2832646a44248 (diff)
downloadrails-f5ea6f880f365c5383d029bddc917baa82e56d55.tar.gz
rails-f5ea6f880f365c5383d029bddc917baa82e56d55.tar.bz2
rails-f5ea6f880f365c5383d029bddc917baa82e56d55.zip
Perform a deep #dup on query cache results so that modifying activerecord attributes does not modify the cached attributes. [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7238 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/query_cache_test.rb')
-rw-r--r--activerecord/test/query_cache_test.rb37
1 files changed, 19 insertions, 18 deletions
diff --git a/activerecord/test/query_cache_test.rb b/activerecord/test/query_cache_test.rb
index 4cadc32316..b09ceea746 100644
--- a/activerecord/test/query_cache_test.rb
+++ b/activerecord/test/query_cache_test.rb
@@ -8,39 +8,43 @@ class QueryCacheTest < Test::Unit::TestCase
fixtures :tasks
def test_find_queries
- assert_queries(2) { Task.find(1); Task.find(1) }
+ assert_queries(2) { Task.find(1); Task.find(1) }
end
def test_find_queries_with_cache
Task.cache do
- assert_queries(1) { Task.find(1); Task.find(1) }
+ assert_queries(1) { Task.find(1); Task.find(1) }
end
end
- def test_find_queries_with_cache
- Task.cache do
- assert_queries(1) { Task.find(1); Task.find(1) }
- end
- end
-
- def test_query_cache_returned
+ def test_query_cache_returned
assert_not_equal ActiveRecord::QueryCache, Task.connection.class
- Task.cache do
- assert_equal ActiveRecord::QueryCache, Task.connection.class
+ Task.cache do
+ assert_equal ActiveRecord::QueryCache, Task.connection.class
end
end
-
+
+ def test_query_cache_dups_results_correctly
+ Task.cache do
+ now = Time.now.utc
+ task = Task.find 1
+ assert_not_equal now, task.starting
+ task.starting = now
+ task.reload
+ assert_not_equal now, task.starting
+ end
+ end
def test_cache_is_scoped_on_actual_class_only
Task.cache do
- assert_queries(2) { Topic.find(1); Topic.find(1) }
+ Topic.columns # don't count this query
+ assert_queries(2) { Topic.find(1); Topic.find(1); }
end
end
-
def test_cache_is_scoped_on_all_descending_classes
ActiveRecord::Base.cache do
- assert_queries(1) { Task.find(1); Task.find(1) }
+ assert_queries(1) { Task.find(1); Task.find(1) }
end
end
@@ -53,11 +57,8 @@ class QueryCacheTest < Test::Unit::TestCase
"Connections should be different, Course connects to a different database"
end
end
-
-
end
-
uses_mocha('QueryCacheExpiryTest') do
class QueryCacheExpiryTest < Test::Unit::TestCase