aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/mysql2/connection_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-09-22 14:57:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-09-22 14:57:19 -0700
commit9a4e183fe9f81365f7815c391512b3d46622d8c8 (patch)
tree4a6bc21833c73d5d098dc398560a43bd1d854f07 /activerecord/test/cases/adapters/mysql2/connection_test.rb
parent53a8a7f9cb7ee93513c445302f25643423fea8e7 (diff)
downloadrails-9a4e183fe9f81365f7815c391512b3d46622d8c8.tar.gz
rails-9a4e183fe9f81365f7815c391512b3d46622d8c8.tar.bz2
rails-9a4e183fe9f81365f7815c391512b3d46622d8c8.zip
add a truncate method to the connection
it doesn't work on SQLite3 since it doesn't support truncate, but that's OK. If you call truncate on the connection, you're now bound to that database (same as if you use hstore or any other db specific feature).
Diffstat (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb')
-rw-r--r--activerecord/test/cases/adapters/mysql2/connection_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb
index 0b2f59b0eb..62c5abbf41 100644
--- a/activerecord/test/cases/adapters/mysql2/connection_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb
@@ -4,6 +4,8 @@ require 'support/connection_helper'
class MysqlConnectionTest < ActiveRecord::TestCase
include ConnectionHelper
+ fixtures :comments
+
def setup
super
@subscriber = SQLSubscriber.new
@@ -24,6 +26,17 @@ class MysqlConnectionTest < ActiveRecord::TestCase
end
end
+ def test_truncate
+ rows = ActiveRecord::Base.connection.exec_query("select count(*) from comments")
+ count = rows.first.values.first
+ assert_operator count, :>, 0
+
+ ActiveRecord::Base.connection.truncate("comments")
+ rows = ActiveRecord::Base.connection.exec_query("select count(*) from comments")
+ count = rows.first.values.first
+ assert_equal 0, count
+ end
+
def test_no_automatic_reconnection_after_timeout
assert @connection.active?
@connection.update('set @@wait_timeout=1')