Skip to content

Commit

Permalink
minor syntax tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bmabey committed Aug 5, 2012
1 parent 6d0afa7 commit 20963dd
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/database_cleaner/active_record/truncation.rb
Expand Up @@ -2,10 +2,7 @@

require 'active_record/connection_adapters/abstract_adapter'

begin
require 'active_record/connection_adapters/abstract_mysql_adapter'
rescue LoadError
end
require 'active_record/connection_adapters/abstract_mysql_adapter' rescue LoadError

require "database_cleaner/generic/truncation"
require 'database_cleaner/active_record/base'
Expand Down Expand Up @@ -60,7 +57,7 @@ def truncate_table(table_name)
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
end

def fast_truncate_tables *tables_and_opts
def fast_truncate_tables(*tables_and_opts)
opts = tables_and_opts.last.is_a?(::Hash) ? tables_and_opts.pop : {}
reset_ids = opts[:reset_ids] != false

Expand All @@ -79,12 +76,11 @@ def truncate_table_with_id_reset(table_name)
rows_exist = execute("SELECT EXISTS(SELECT 1 FROM #{quote_table_name(table_name)} LIMIT 1)").fetch_row.first.to_i

if rows_exist == 0
auto_inc = execute(<<-AUTO_INCREMENT
auto_inc = execute(<<-SQL)
SELECT Auto_increment
FROM information_schema.tables
WHERE table_name='#{table_name}';
AUTO_INCREMENT
)
SQL

truncate_table(table_name) if auto_inc.fetch_row.first.to_i > 1
else
Expand Down Expand Up @@ -119,15 +115,14 @@ def fast_truncate_tables *tables_and_opts
end

def truncate_table_with_id_reset(table_name)
rows_exist = execute("SELECT EXISTS(SELECT 1 FROM #{quote_table_name(table_name)} LIMIT 1)").first.first.to_i
rows_exist = execute("SELECT EXISTS(SELECT 1 FROM #{quote_table_name(table_name)} LIMIT 1)").first.first.to_i.zero?

if rows_exist == 0
auto_inc = execute(<<-AUTO_INCREMENT
if rows_exist
auto_inc = execute(<<-SQL)
SELECT Auto_increment
FROM information_schema.tables
WHERE table_name='#{table_name}';
AUTO_INCREMENT
)
SQL

truncate_table(table_name) if auto_inc.first.first.to_i > 1
else
Expand Down

0 comments on commit 20963dd

Please sign in to comment.