Skip to content

Commit

Permalink
Ensure drop_table even if tests failure or interrupted
Browse files Browse the repository at this point in the history
I was encountered remaining `:binary_testings` table by tests failure.
When remaining `:binary_testings` table, never reach `drop_table` due to
`create_table` in the test always fails.
  • Loading branch information
kamipo committed Feb 24, 2016
1 parent 5a064be commit 95441c7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions activerecord/test/cases/migration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,34 +516,32 @@ def test_create_table_with_binary_column
data_column = columns.detect { |c| c.name == "data" }

assert_nil data_column.default

ensure
Person.connection.drop_table :binary_testings, if_exists: true
end

unless mysql_enforcing_gtid_consistency?
def test_create_table_with_query
Person.connection.drop_table :table_from_query_testings rescue nil
Person.connection.create_table(:person, force: true)

Person.connection.create_table :table_from_query_testings, as: "SELECT id FROM person"

columns = Person.connection.columns(:table_from_query_testings)
assert_equal 1, columns.length
assert_equal "id", columns.first.name

ensure
Person.connection.drop_table :table_from_query_testings rescue nil
end

def test_create_table_with_query_from_relation
Person.connection.drop_table :table_from_query_testings rescue nil
Person.connection.create_table(:person, force: true)

Person.connection.create_table :table_from_query_testings, as: Person.select(:id)

columns = Person.connection.columns(:table_from_query_testings)
assert_equal 1, columns.length
assert_equal "id", columns.first.name

ensure
Person.connection.drop_table :table_from_query_testings rescue nil
end
end
Expand Down Expand Up @@ -731,7 +729,7 @@ def test_drop_index_from_table_named_values
connection.add_index :values, :value
connection.remove_index :values, :column => :value
end

ensure
connection.drop_table :values rescue nil
end
end
Expand All @@ -747,7 +745,7 @@ def test_drop_index_by_name
connection.add_index :values, :value, name: 'a_different_name'
connection.remove_index :values, column: :value, name: 'a_different_name'
end

ensure
connection.drop_table :values rescue nil
end
end
Expand Down

0 comments on commit 95441c7

Please sign in to comment.