diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2007-02-06 21:16:07 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2007-02-06 21:16:07 +0000 |
commit | f458b376c545d8eae5189d1ecc16245cafe7e796 (patch) | |
tree | 57862a2d590cbaf90db2f15e8035ad8bbea7a361 /activerecord/test/query_cache_test.rb | |
parent | 23b2abe3135e255dc10fb7ca8d6213700d0a2f28 (diff) | |
download | rails-f458b376c545d8eae5189d1ecc16245cafe7e796.tar.gz rails-f458b376c545d8eae5189d1ecc16245cafe7e796.tar.bz2 rails-f458b376c545d8eae5189d1ecc16245cafe7e796.zip |
Introducing Model.cache { ... } for the occasional query caching needs. ( fantastic to reduce the 200 SELECT * from accounts WHERE id=1 queries in your views )
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6138 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/query_cache_test.rb')
-rw-r--r-- | activerecord/test/query_cache_test.rb | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/activerecord/test/query_cache_test.rb b/activerecord/test/query_cache_test.rb new file mode 100644 index 0000000000..5326351483 --- /dev/null +++ b/activerecord/test/query_cache_test.rb @@ -0,0 +1,80 @@ +require 'abstract_unit' +require 'fixtures/topic' +require 'fixtures/reply' +require 'fixtures/task' + + +class QueryCacheTest < Test::Unit::TestCase + fixtures :tasks + + + def test_find_queries + 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) } + end + end + + def test_find_queries_with_cache + Task.cache do + assert_queries(1) { Task.find(1); Task.find(1) } + end + end + + def test_cache_is_scoped_on_actual_class_only + Task.cache do + assert_queries(2) { Topic.find(1); Topic.find(1) } + end + end +end + +uses_mocha('QueryCacheExpiryTest') do + +class QueryCacheExpiryTest < Test::Unit::TestCase + fixtures :tasks + + def test_find + ActiveRecord::QueryCache.any_instance.expects(:clear_query_cache).times(0) + + Task.cache do + Task.find(1) + end + end + + def test_save + ActiveRecord::QueryCache.any_instance.expects(:clear_query_cache).times(1) + + Task.cache do + Task.find(1).save + end + end + + def test_destroy + ActiveRecord::QueryCache.any_instance.expects(:clear_query_cache).at_least_once + + Task.cache do + Task.find(1).destroy + end + end + + def test_create + ActiveRecord::QueryCache.any_instance.expects(:clear_query_cache).times(1) + + Task.cache do + Task.create! + end + end + + def test_new_save + ActiveRecord::QueryCache.any_instance.expects(:clear_query_cache).times(1) + + Task.cache do + Task.new.save + end + end +end + +end
\ No newline at end of file |