Skip to content

Commit

Permalink
Use teardown helper method.
Browse files Browse the repository at this point in the history
Follow-Up to #14348

Ensure that SQLCounter.clear_log is called after each test.

This is a step to prevent side effects when running tests. This will allow us to run them in random order.
  • Loading branch information
tgxworld committed Mar 15, 2014
1 parent 3560d7a commit 3baace6
Show file tree
Hide file tree
Showing 49 changed files with 51 additions and 61 deletions.
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapter_test.rb
Expand Up @@ -218,7 +218,7 @@ def setup
@connection = Klass.connection
end

def teardown
teardown do
Klass.remove_connection
end

Expand Down
Expand Up @@ -11,7 +11,7 @@ def execute(sql, name = nil) return sql end
end
end

def teardown
teardown do
ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection(@connection)
end
Expand Down
Expand Up @@ -37,7 +37,7 @@ def setup
'distinct_select'=>'distinct_id int, select_id int'
end

def teardown
teardown do
drop_tables_directly ['group', 'select', 'values', 'distinct', 'distinct_select', 'order']
end

Expand Down
Expand Up @@ -11,7 +11,7 @@ def execute(sql, name = nil) return sql end
end
end

def teardown
teardown do
ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection(@connection)
end
Expand Down
Expand Up @@ -37,7 +37,7 @@ def setup
'distinct_select'=>'distinct_id int, select_id int'
end

def teardown
teardown do
drop_tables_directly ['group', 'select', 'values', 'distinct', 'distinct_select', 'order']
end

Expand Down
Expand Up @@ -7,7 +7,7 @@ def execute(sql, name = nil) sql end
end
end

def teardown
teardown do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
remove_method :execute
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/array_test.rb
Expand Up @@ -19,7 +19,7 @@ def setup
@column = PgArray.columns.find { |c| c.name == 'tags' }
end

def teardown
teardown do
@connection.execute 'drop table if exists pg_arrays'
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/bytea_test.rb
Expand Up @@ -23,7 +23,7 @@ def setup
assert(@column.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLColumn))
end

def teardown
teardown do
@connection.execute 'drop table if exists bytea_data_type'
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/citext_test.rb
Expand Up @@ -25,7 +25,7 @@ def setup
@column = Citext.columns_hash['cival']
end

def teardown
teardown do
@connection.execute 'DROP TABLE IF EXISTS citexts;'
@connection.execute 'DROP EXTENSION IF EXISTS citext CASCADE;'
end
Expand Down
Expand Up @@ -8,7 +8,7 @@ class PostgresqlComposite < ActiveRecord::Base
self.table_name = "postgresql_composites"
end

def teardown
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_composites'
@connection.execute 'DROP TYPE IF EXISTS full_address'
end
Expand Down
Expand Up @@ -67,7 +67,7 @@ def setup
@connection.execute("INSERT INTO postgresql_timestamp_with_zones (id, time) VALUES (1, '2010-01-01 10:00:00-1')")
end

def teardown
teardown do
[PostgresqlArray, PostgresqlTsvector, PostgresqlMoney, PostgresqlNumber, PostgresqlTime, PostgresqlNetworkAddress,
PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone].each(&:delete_all)
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/enum_test.rb
Expand Up @@ -8,7 +8,7 @@ class PostgresqlEnum < ActiveRecord::Base
self.table_name = "postgresql_enums"
end

def teardown
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_enums'
@connection.execute 'DROP TYPE IF EXISTS mood'
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/hstore_test.rb
Expand Up @@ -31,7 +31,7 @@ def setup
@column = Hstore.columns.find { |c| c.name == 'tags' }
end

def teardown
teardown do
@connection.execute 'drop table if exists hstores'
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/json_test.rb
Expand Up @@ -26,7 +26,7 @@ def setup
@column = JsonDataType.columns.find { |c| c.name == 'payload' }
end

def teardown
teardown do
@connection.execute 'drop table if exists json_data_type'
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/ltree_test.rb
Expand Up @@ -19,7 +19,7 @@ def setup
skip "do not test on PG without ltree"
end

def teardown
teardown do
@connection.execute 'drop table if exists ltrees'
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/range_test.rb
Expand Up @@ -8,7 +8,7 @@ class PostgresqlRange < ActiveRecord::Base
end

class PostgresqlRangeTest < ActiveRecord::TestCase
def teardown
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_ranges'
@connection.execute 'DROP TYPE IF EXISTS floatrange'
end
Expand Down
Expand Up @@ -27,7 +27,7 @@ def setup
end
end

def teardown
teardown do
set_session_auth
@connection.execute "RESET search_path"
USERS.each do |u|
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/schema_test.rb
Expand Up @@ -71,7 +71,7 @@ def setup
@connection.execute "CREATE TABLE #{SCHEMA_NAME}.#{UNMATCHED_PK_TABLE_NAME} (id integer NOT NULL DEFAULT nextval('#{SCHEMA_NAME}.#{UNMATCHED_SEQUENCE_NAME}'::regclass), CONSTRAINT unmatched_pkey PRIMARY KEY (id))"
end

def teardown
teardown do
@connection.execute "DROP SCHEMA #{SCHEMA2_NAME} CASCADE"
@connection.execute "DROP SCHEMA #{SCHEMA_NAME} CASCADE"
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/view_test.rb
Expand Up @@ -24,7 +24,7 @@ def setup
@connection.execute "CREATE VIEW #{SCHEMA_NAME}.#{VIEW_NAME} AS SELECT id,name,email,moment FROM #{SCHEMA_NAME}.#{TABLE_NAME}"
end

def teardown
teardown do
@connection.execute "DROP SCHEMA #{SCHEMA_NAME} CASCADE"
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/adapters/postgresql/xml_test.rb
Expand Up @@ -23,7 +23,7 @@ def setup
@column = XmlDataType.columns.find { |c| c.name == 'payload' }
end

def teardown
teardown do
@connection.execute 'drop table if exists xml_data_type'
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/ar_schema_test.rb
Expand Up @@ -10,7 +10,7 @@ def setup
ActiveRecord::SchemaMigration.drop_table
end

def teardown
teardown do
@connection.drop_table :fruits rescue nil
@connection.drop_table :nep_fruits rescue nil
@connection.drop_table :nep_schema_migrations rescue nil
Expand Down
Expand Up @@ -68,7 +68,7 @@ def setup
generate_test_object_graphs
end

def teardown
teardown do
[Circle, Square, Triangle, PaintColor, PaintTexture,
ShapeExpression, NonPolyOne, NonPolyTwo].each do |c|
c.delete_all
Expand Down Expand Up @@ -111,7 +111,7 @@ def setup
@first_categorization = @davey_mcdave.categorizations.create(:category => Category.first, :post => @first_post)
end

def teardown
teardown do
@davey_mcdave.destroy
@first_post.destroy
@first_comment.destroy
Expand Down
Expand Up @@ -90,7 +90,7 @@ def setup
end
end

def teardown
teardown do
connection.drop_table :viri
connection.drop_table :octopi
connection.drop_table :passes
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/attribute_methods_test.rb
Expand Up @@ -22,7 +22,7 @@ def setup
@target.table_name = 'topics'
end

def teardown
teardown do
ActiveRecord::Base.send(:attribute_method_matchers).clear
ActiveRecord::Base.send(:attribute_method_matchers).concat(@old_matchers)
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/bind_parameter_test.rb
Expand Up @@ -25,7 +25,7 @@ def setup
ActiveSupport::Notifications.subscribe('sql.active_record', @listener)
end

def teardown
teardown do
ActiveSupport::Notifications.unsubscribe(@listener)
end

Expand Down
Expand Up @@ -13,7 +13,7 @@ def setup
@previous_database_url = ENV.delete("DATABASE_URL")
end

def teardown
teardown do
ENV["DATABASE_URL"] = @previous_database_url
end

Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/connection_pool_test.rb
Expand Up @@ -22,8 +22,7 @@ def setup
end
end

def teardown
super
teardown do
@pool.disconnect!
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/defaults_test.rb
Expand Up @@ -206,7 +206,7 @@ def test_text_defaults_after_updating_column_default
assert_equal "some text", Default.new.text_col, "Default of text column was not correctly parse after updating default using '::text' since postgreSQL will add parens to the default in db"
end

def teardown
teardown do
@connection.schema_search_path = @old_search_path
Default.reset_column_information
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/disconnected_test.rb
Expand Up @@ -10,7 +10,7 @@ def setup
@connection = ActiveRecord::Base.connection
end

def teardown
teardown do
return if in_memory_db?
spec = ActiveRecord::Base.connection_config
ActiveRecord::Base.establish_connection(spec)
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/explain_subscriber_test.rb
Expand Up @@ -48,7 +48,7 @@ def test_collects_nothing_if_the_statement_is_only_partially_matched
assert queries.empty?
end

def teardown
teardown do
ActiveRecord::ExplainRegistry.reset
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/inheritance_test.rb
Expand Up @@ -339,7 +339,7 @@ def setup
ActiveSupport::Dependencies.log_activity = true
end

def teardown
teardown do
ActiveSupport::Dependencies.log_activity = false
self.class.const_remove :FirmOnTheFly rescue nil
Firm.const_remove :FirmOnTheFly rescue nil
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/invalid_connection_test.rb
Expand Up @@ -12,7 +12,7 @@ def setup
Bird.establish_connection adapter: 'mysql', database: 'i_do_not_exist'
end

def teardown
teardown do
Bird.remove_connection
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/invertible_migration_test.rb
Expand Up @@ -122,7 +122,7 @@ def change
end
end

def teardown
teardown do
%w[horses new_horses].each do |table|
if ActiveRecord::Base.connection.table_exists?(table)
ActiveRecord::Base.connection.drop_table(table)
Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/migration/change_schema_test.rb
Expand Up @@ -11,8 +11,7 @@ def setup
@table_name = :testings
end

def teardown
super
teardown do
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/migration/change_table_test.rb
Expand Up @@ -8,7 +8,7 @@ def setup
@connection = Minitest::Mock.new
end

def teardown
teardown do
assert @connection.verify
end

Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/migration/column_positioning_test.rb
Expand Up @@ -18,8 +18,7 @@ def setup
end
end

def teardown
super
teardown do
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end
Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/migration/create_join_table_test.rb
Expand Up @@ -10,8 +10,7 @@ def setup
@connection = ActiveRecord::Base.connection
end

def teardown
super
teardown do
%w(artists_musics musics_videos catalog).each do |table_name|
connection.drop_table table_name if connection.tables.include?(table_name)
end
Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/migration/index_test.rb
Expand Up @@ -21,8 +21,7 @@ def setup
end
end

def teardown
super
teardown do
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end
Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/migration/logger_test.rb
Expand Up @@ -19,8 +19,7 @@ def setup
ActiveRecord::SchemaMigration.delete_all
end

def teardown
super
teardown do
ActiveRecord::SchemaMigration.drop_table
end

Expand Down
3 changes: 1 addition & 2 deletions activerecord/test/cases/migration/references_index_test.rb
Expand Up @@ -11,8 +11,7 @@ def setup
@table_name = :testings
end

def teardown
super
teardown do
connection.drop_table :testings rescue nil
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -33,7 +33,7 @@ def setup
ActiveRecord::Base.connection.schema_cache.clear!
end

def teardown
teardown do
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""

Expand Down Expand Up @@ -585,7 +585,7 @@ def setup
Person.reset_sequence_name
end

def teardown
teardown do
Person.connection.drop_table(:delete_me) rescue nil
end

Expand Down

0 comments on commit 3baace6

Please sign in to comment.