Sha256: 8dbf0f56b89499660428ff1ab922632d82b59e50ab635efc7c93a6f6844ede27

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

require "database_cleaner/truncation_base"

module ActiveRecord
  module ConnectionAdapters

    class MysqlAdapter
      def truncate_table(table_name)
        execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
      end
    end

    class SQLite3Adapter
      def truncate_table(table_name)
        execute("DELETE FROM #{quote_table_name(table_name)};")
      end
    end

    class JdbcAdapter
      def truncate_table(table_name)
        execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
      end
    end

    class PostgreSQLAdapter
      def truncate_table(table_name)
        execute("TRUNCATE TABLE #{quote_table_name(table_name)} CASCADE;")
      end
    end

    class SQLServerAdapter
      def truncate_table(table_name)
        execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
      end
    end

  end
end


module DatabaseCleaner::ActiveRecord
  class Truncation < ::DatabaseCleaner::TruncationBase

    def clean
      connection.disable_referential_integrity do
        tables_to_truncate.each do |table_name|
          connection.truncate_table table_name
        end
      end
    end

    private

    def tables_to_truncate
      (@only || connection.tables) - @tables_to_exclude
    end

    def connection
      ::ActiveRecord::Base.connection
    end

    # overwritten
    def migration_storage_name
      'schema_migrations'
    end

  end
end


Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
yozhyk-database_cleaner-0.2.4 lib/database_cleaner/active_record/truncation.rb
database_cleaner-0.4.2 lib/database_cleaner/active_record/truncation.rb
tooky-database_cleaner-0.4.1 lib/database_cleaner/active_record/truncation.rb
database_cleaner-0.4.1 lib/database_cleaner/active_record/truncation.rb
database_cleaner-0.4.0 lib/database_cleaner/active_record/truncation.rb
database_cleaner-0.3.0 lib/database_cleaner/active_record/truncation.rb