mirror of
https://github.com/github/rails.git
synced 2026-01-29 08:18:03 -05:00
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6138 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
80 lines
1.5 KiB
Ruby
80 lines
1.5 KiB
Ruby
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 |