aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapter_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-04-04 05:04:25 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-04-04 05:04:25 +0900
commit8113c8e1238939c8c68c2598b0a78a5b2171943d (patch)
tree8442114adf52f171df20bae91a18e8e07941ae46 /activerecord/test/cases/adapter_test.rb
parent8be22161edd7608acd5cae436e4278bfe9f05abf (diff)
downloadrails-8113c8e1238939c8c68c2598b0a78a5b2171943d.tar.gz
rails-8113c8e1238939c8c68c2598b0a78a5b2171943d.tar.bz2
rails-8113c8e1238939c8c68c2598b0a78a5b2171943d.zip
Clear query cache when truncate table(s)
Diffstat (limited to 'activerecord/test/cases/adapter_test.rb')
-rw-r--r--activerecord/test/cases/adapter_test.rb44
1 files changed, 36 insertions, 8 deletions
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb
index 2b20d842e8..ba04859bf0 100644
--- a/activerecord/test/cases/adapter_test.rb
+++ b/activerecord/test/cases/adapter_test.rb
@@ -485,23 +485,51 @@ module ActiveRecord
end
def test_truncate
- assert_operator @connection.query_value("SELECT COUNT(*) FROM posts"), :>, 0
+ assert_operator Post.count, :>, 0
@connection.truncate("posts")
- assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM posts")
+ assert_equal 0, Post.count
+ end
+
+ def test_truncate_with_query_cache
+ @connection.enable_query_cache!
+
+ assert_operator Post.count, :>, 0
+
+ @connection.truncate("posts")
+
+ assert_equal 0, Post.count
+ ensure
+ @connection.disable_query_cache!
end
def test_truncate_tables
- assert_operator @connection.query_value("SELECT COUNT(*) FROM posts"), :>, 0
- assert_operator @connection.query_value("SELECT COUNT(*) FROM authors"), :>, 0
- assert_operator @connection.query_value("SELECT COUNT(*) FROM author_addresses"), :>, 0
+ assert_operator Post.count, :>, 0
+ assert_operator Author.count, :>, 0
+ assert_operator AuthorAddress.count, :>, 0
@connection.truncate_tables("author_addresses", "authors", "posts")
- assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM posts")
- assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM authors")
- assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM author_addresses")
+ assert_equal 0, Post.count
+ assert_equal 0, Author.count
+ assert_equal 0, AuthorAddress.count
+ end
+
+ def test_truncate_tables_with_query_cache
+ @connection.enable_query_cache!
+
+ assert_operator Post.count, :>, 0
+ assert_operator Author.count, :>, 0
+ assert_operator AuthorAddress.count, :>, 0
+
+ @connection.truncate_tables("author_addresses", "authors", "posts")
+
+ assert_equal 0, Post.count
+ assert_equal 0, Author.count
+ assert_equal 0, AuthorAddress.count
+ ensure
+ @connection.disable_query_cache!
end
# test resetting sequences in odd tables in PostgreSQL