aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapter_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/adapter_test.rb')
-rw-r--r--activerecord/test/cases/adapter_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb
index d90003b0ba..d25faf21d8 100644
--- a/activerecord/test/cases/adapter_test.rb
+++ b/activerecord/test/cases/adapter_test.rb
@@ -452,6 +452,8 @@ module ActiveRecord
class AdapterTestWithoutTransaction < ActiveRecord::TestCase
self.use_transactional_tests = false
+ fixtures :posts, :authors, :author_addresses
+
def setup
@connection = ActiveRecord::Base.connection
end
@@ -482,6 +484,26 @@ module ActiveRecord
end
end
+ def test_truncate
+ assert_operator @connection.query_value("SELECT COUNT(*) FROM posts"), :>, 0
+
+ @connection.truncate("posts")
+
+ assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM posts")
+ end
+
+ def test_truncate_tables
+ assert_operator @connection.query_value("SELECT COUNT(*) FROM authors"), :>, 0
+ assert_operator @connection.query_value("SELECT COUNT(*) FROM author_addresses"), :>, 0
+
+ @connection.disable_referential_integrity do
+ @connection.truncate_tables("author_addresses", "authors")
+ end
+
+ assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM authors")
+ assert_equal 0, @connection.query_value("SELECT COUNT(*) FROM author_addresses")
+ end
+
# test resetting sequences in odd tables in PostgreSQL
if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
require "models/movie"