aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters
diff options
context:
space:
mode:
authorBogdan <bogdanvlviv@gmail.com>2019-03-05 00:57:38 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2019-03-04 14:57:38 -0800
commita8c0ebccbdbf4e2ccbacbf94cba6cf24699af190 (patch)
tree0767c1a1138c4a670384fc8bc6a1e3ac7b23e879 /activerecord/test/cases/adapters
parent076e8eddf4766a27a62fd0ae087c6c08501ddc42 (diff)
downloadrails-a8c0ebccbdbf4e2ccbacbf94cba6cf24699af190.tar.gz
rails-a8c0ebccbdbf4e2ccbacbf94cba6cf24699af190.tar.bz2
rails-a8c0ebccbdbf4e2ccbacbf94cba6cf24699af190.zip
Allow `truncate` for SQLite3 adapter and add `rails db:seed:replant` (#34779)
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter. SQLite doesn't support `TRUNCATE TABLE`, but SQLite3 adapter can support `ActiveRecord::Base.connection.truncate` by using `DELETE FROM`. `DELETE` without `WHERE` uses "The Truncate Optimization", see https://www.sqlite.org/lang_delete.html. * Add `rails db:seed:replant` that truncates database tables and loads the seeds Closes #34765
Diffstat (limited to 'activerecord/test/cases/adapters')
-rw-r--r--activerecord/test/cases/adapters/sqlite3/connection_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/sqlite3/connection_test.rb b/activerecord/test/cases/adapters/sqlite3/connection_test.rb
new file mode 100644
index 0000000000..3dabc8766a
--- /dev/null
+++ b/activerecord/test/cases/adapters/sqlite3/connection_test.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require "cases/helper"
+
+class SQLite3ConnectionTest < ActiveRecord::SQLite3TestCase
+ fixtures :comments
+
+ 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
+end