Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #125 from kamui/sequel_transaction

Sequel also uses schema_migrations as a migration table
  • Loading branch information...
commit 4350e3274d299ce1987594efee53c4a95473e969 2 parents dfb3f50 + edf2c42
@bmabey bmabey authored
View
20 lib/database_cleaner/active_record/truncation.rb
@@ -12,7 +12,7 @@
module DatabaseCleaner
module ActiveRecord
-
+
module AbstractAdapter
# used to be called views but that can clash with gems like schema_plus
# this gem is not meant to be exposing such an extra interface any way
@@ -37,7 +37,7 @@ def truncate_tables(tables)
end
module MysqlAdapter
-
+
def truncate_table(table_name)
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
end
@@ -53,7 +53,7 @@ def pre_count_truncate_tables(tables, options = {:reset_ids => true})
private
-
+
def row_count(table)
select_value("SELECT EXISTS (SELECT 1 FROM #{quote_table_name(table)} LIMIT 1)")
end
@@ -67,8 +67,8 @@ def has_been_used?(table)
true
else
select_value(<<-SQL) > 1 # returns nil if not present
- SELECT Auto_increment
- FROM information_schema.tables
+ SELECT Auto_increment
+ FROM information_schema.tables
WHERE table_name='#{table}';
SQL
end
@@ -79,14 +79,14 @@ def has_rows?(table)
end
end
-
+
module IBM_DBAdapter
def truncate_table(table_name)
execute("TRUNCATE #{quote_table_name(table_name)} IMMEDIATE")
end
end
-
+
module SQLiteAdapter
def delete_table(table_name)
execute("DELETE FROM #{quote_table_name(table_name)};")
@@ -181,7 +181,7 @@ class SQLiteAdapter < AbstractAdapter
MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
MYSQL2_ADAPTER_PARENT = AbstractAdapter
end
-
+
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : SQLiteAdapter
POSTGRE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
@@ -244,8 +244,8 @@ def tables_to_truncate(connection)
end
# overwritten
- def migration_storage_name
- 'schema_migrations'
+ def migration_storage_names
+ %w[schema_migrations]
end
def pre_count?
View
2  lib/database_cleaner/data_mapper/truncation.rb
@@ -167,7 +167,7 @@ def tables_to_truncate(repository = self.db)
# overwritten
def migration_storage_name
- 'migration_info'
+ %w[migration_info]
end
end
View
4 lib/database_cleaner/generic/truncation.rb
@@ -31,8 +31,8 @@ def tables_to_truncate
# overwrite in subclasses
# default implementation given because migration storage need not be present
- def migration_storage_name
- nil
+ def migration_storage_names
+ %w[]
end
end
end
View
10 lib/database_cleaner/sequel/truncation.rb
@@ -6,7 +6,7 @@ module Sequel
class Truncation
include ::DatabaseCleaner::Sequel::Base
include ::DatabaseCleaner::Generic::Truncation
-
+
def clean
case db.database_type
when :postgres
@@ -25,7 +25,7 @@ def clean
end
end
end
-
+
def each_table
tables_to_truncate(db).each do |table|
yield db, table
@@ -33,14 +33,14 @@ def each_table
end
private
-
+
def tables_to_truncate(db)
(@only || db.tables) - @tables_to_exclude
end
# overwritten
- def migration_storage_name
- :schema_info
+ def migration_storage_names
+ %w[schema_info schema_migrations]
end
end
View
12 spec/database_cleaner/generic/truncation_spec.rb
@@ -24,8 +24,8 @@ def pre_count?
end
class MigrationExample < TruncationExample
- def migration_storage_name
- "migration_storage_name"
+ def migration_storage_names
+ %w[migration_storage_name]
end
end
@@ -37,8 +37,8 @@ def migration_storage_name
it { should_not respond_to(:tables_to_truncate) }
its(:tables_to_truncate) { expect{ subject }.to raise_error(NotImplementedError) }
- it { should_not respond_to(:migration_storage_name) }
- its(:migration_storage_name) { should be_nil }
+ it { should_not respond_to(:migration_storage_names) }
+ its(:migration_storage_names) { should be_empty }
end
describe "initialize" do
@@ -86,11 +86,11 @@ def migration_storage_name
subject { TruncationExample.new( { :pre_count => nil } ) }
its(:pre_count?) { should == false }
end
-
+
context "" do
subject { MigrationExample.new }
its(:only) { should == nil }
- its(:except) { should == ["migration_storage_name"] }
+ its(:except) { should == %w[migration_storage_name] }
end
context "" do
Please sign in to comment.
Something went wrong with that request. Please try again.