1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #14380 from tgxworld/use_teardown_helper_method_in_activerecord

Use teardown helper method.
This commit is contained in:
Yves Senn 2014-03-15 11:59:25 +01:00
commit 6869884b46
49 changed files with 51 additions and 61 deletions

View file

@ -218,7 +218,7 @@ module ActiveRecord
@connection = Klass.connection
end
def teardown
teardown do
Klass.remove_connection
end

View file

@ -11,7 +11,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase
end
end
def teardown
teardown do
ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection(@connection)
end

View file

@ -37,7 +37,7 @@ class MysqlReservedWordTest < ActiveRecord::TestCase
'distinct_select'=>'distinct_id int, select_id int'
end
def teardown
teardown do
drop_tables_directly ['group', 'select', 'values', 'distinct', 'distinct_select', 'order']
end

View file

@ -11,7 +11,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase
end
end
def teardown
teardown do
ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection(@connection)
end

View file

@ -37,7 +37,7 @@ class MysqlReservedWordTest < ActiveRecord::TestCase
'distinct_select'=>'distinct_id int, select_id int'
end
def teardown
teardown do
drop_tables_directly ['group', 'select', 'values', 'distinct', 'distinct_select', 'order']
end

View file

@ -7,7 +7,7 @@ class PostgresqlActiveSchemaTest < ActiveRecord::TestCase
end
end
def teardown
teardown do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
remove_method :execute
end

View file

@ -19,7 +19,7 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
@column = PgArray.columns.find { |c| c.name == 'tags' }
end
def teardown
teardown do
@connection.execute 'drop table if exists pg_arrays'
end

View file

@ -23,7 +23,7 @@ class PostgresqlByteaTest < ActiveRecord::TestCase
assert(@column.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLColumn))
end
def teardown
teardown do
@connection.execute 'drop table if exists bytea_data_type'
end

View file

@ -25,7 +25,7 @@ class PostgresqlCitextTest < ActiveRecord::TestCase
@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

View file

@ -8,7 +8,7 @@ class PostgresqlCompositeTest < ActiveRecord::TestCase
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

View file

@ -67,7 +67,7 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
@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

View file

@ -8,7 +8,7 @@ class PostgresqlEnumTest < ActiveRecord::TestCase
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

View file

@ -31,7 +31,7 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
@column = Hstore.columns.find { |c| c.name == 'tags' }
end
def teardown
teardown do
@connection.execute 'drop table if exists hstores'
end

View file

@ -26,7 +26,7 @@ class PostgresqlJSONTest < ActiveRecord::TestCase
@column = JsonDataType.columns.find { |c| c.name == 'payload' }
end
def teardown
teardown do
@connection.execute 'drop table if exists json_data_type'
end

View file

@ -19,7 +19,7 @@ class PostgresqlLtreeTest < ActiveRecord::TestCase
skip "do not test on PG without ltree"
end
def teardown
teardown do
@connection.execute 'drop table if exists ltrees'
end

View file

@ -8,7 +8,7 @@ if ActiveRecord::Base.connection.supports_ranges?
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

View file

@ -27,7 +27,7 @@ class SchemaAuthorizationTest < ActiveRecord::TestCase
end
end
def teardown
teardown do
set_session_auth
@connection.execute "RESET search_path"
USERS.each do |u|

View file

@ -71,7 +71,7 @@ class SchemaTest < ActiveRecord::TestCase
@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

View file

@ -24,7 +24,7 @@ class ViewTest < ActiveRecord::TestCase
@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

View file

@ -23,7 +23,7 @@ class PostgresqlXMLTest < ActiveRecord::TestCase
@column = XmlDataType.columns.find { |c| c.name == 'payload' }
end
def teardown
teardown do
@connection.execute 'drop table if exists xml_data_type'
end

View file

@ -10,7 +10,7 @@ if ActiveRecord::Base.connection.supports_migrations?
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

View file

@ -68,7 +68,7 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
generate_test_object_graphs
end
def teardown
teardown do
[Circle, Square, Triangle, PaintColor, PaintTexture,
ShapeExpression, NonPolyOne, NonPolyTwo].each do |c|
c.delete_all
@ -111,7 +111,7 @@ class EagerLoadNestedIncludeWithMissingDataTest < ActiveRecord::TestCase
@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

View file

@ -90,7 +90,7 @@ class EagerSingularizationTest < ActiveRecord::TestCase
end
end
def teardown
teardown do
connection.drop_table :viri
connection.drop_table :octopi
connection.drop_table :passes

View file

@ -22,7 +22,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
@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

View file

@ -25,7 +25,7 @@ module ActiveRecord
ActiveSupport::Notifications.subscribe('sql.active_record', @listener)
end
def teardown
teardown do
ActiveSupport::Notifications.unsubscribe(@listener)
end

View file

@ -13,7 +13,7 @@ module ActiveRecord
@previous_database_url = ENV.delete("DATABASE_URL")
end
def teardown
teardown do
ENV["DATABASE_URL"] = @previous_database_url
end

View file

@ -22,8 +22,7 @@ module ActiveRecord
end
end
def teardown
super
teardown do
@pool.disconnect!
end

View file

@ -206,7 +206,7 @@ if current_adapter?(:PostgreSQLAdapter)
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

View file

@ -10,7 +10,7 @@ class TestDisconnectedAdapter < ActiveRecord::TestCase
@connection = ActiveRecord::Base.connection
end
def teardown
teardown do
return if in_memory_db?
spec = ActiveRecord::Base.connection_config
ActiveRecord::Base.establish_connection(spec)

View file

@ -48,7 +48,7 @@ if ActiveRecord::Base.connection.supports_explain?
assert queries.empty?
end
def teardown
teardown do
ActiveRecord::ExplainRegistry.reset
end

View file

@ -339,7 +339,7 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase
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

View file

@ -12,7 +12,7 @@ class TestAdapterWithInvalidConnection < ActiveRecord::TestCase
Bird.establish_connection adapter: 'mysql', database: 'i_do_not_exist'
end
def teardown
teardown do
Bird.remove_connection
end

View file

@ -122,7 +122,7 @@ module ActiveRecord
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)

View file

@ -11,8 +11,7 @@ module ActiveRecord
@table_name = :testings
end
def teardown
super
teardown do
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end

View file

@ -8,7 +8,7 @@ module ActiveRecord
@connection = Minitest::Mock.new
end
def teardown
teardown do
assert @connection.verify
end

View file

@ -18,8 +18,7 @@ module ActiveRecord
end
end
def teardown
super
teardown do
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end

View file

@ -10,8 +10,7 @@ module ActiveRecord
@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

View file

@ -21,8 +21,7 @@ module ActiveRecord
end
end
def teardown
super
teardown do
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end

View file

@ -19,8 +19,7 @@ module ActiveRecord
ActiveRecord::SchemaMigration.delete_all
end
def teardown
super
teardown do
ActiveRecord::SchemaMigration.drop_table
end

View file

@ -11,8 +11,7 @@ module ActiveRecord
@table_name = :testings
end
def teardown
super
teardown do
connection.drop_table :testings rescue nil
end

View file

@ -33,7 +33,7 @@ class MigrationTest < ActiveRecord::TestCase
ActiveRecord::Base.connection.schema_cache.clear!
end
def teardown
teardown do
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
@ -585,7 +585,7 @@ if ActiveRecord::Base.connection.supports_bulk_alter?
Person.reset_sequence_name
end
def teardown
teardown do
Person.connection.drop_table(:delete_me) rescue nil
end

View file

@ -26,8 +26,7 @@ module ActiveRecord
ActiveRecord::SchemaMigration.delete_all rescue nil
end
def teardown
super
teardown do
ActiveRecord::SchemaMigration.delete_all rescue nil
ActiveRecord::Migration.verbose = true
end

View file

@ -18,7 +18,7 @@ class ModulesTest < ActiveRecord::TestCase
ActiveRecord::Base.store_full_sti_class = false
end
def teardown
teardown do
# reinstate the constants that we undefined in the setup
@undefined_consts.each do |constant, value|
Object.send :const_set, constant, value unless value.nil?

View file

@ -28,7 +28,7 @@ end
class TestNestedAttributesInGeneral < ActiveRecord::TestCase
include AssertRaiseWithMessage
def teardown
teardown do
Pirate.accepts_nested_attributes_for :ship, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
end

View file

@ -10,7 +10,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
@connection = ActiveRecord::Base.remove_connection
end
def teardown
teardown do
ActiveRecord::Base.clear_all_connections!
ActiveRecord::Base.establish_connection(@connection)
@per_test_teardown.each {|td| td.call }

View file

@ -10,8 +10,7 @@ module ActiveRecord
@pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec
end
def teardown
super
teardown do
@pool.connections.each(&:close)
end

View file

@ -10,8 +10,7 @@ class SerializedAttributeTest < ActiveRecord::TestCase
MyObject = Struct.new :attribute1, :attribute2
def teardown
super
teardown do
Topic.serialize("content")
end

View file

@ -11,7 +11,7 @@ class TestUnconnectedAdapter < ActiveRecord::TestCase
@specification = ActiveRecord::Base.remove_connection
end
def teardown
teardown do
@underlying = nil
ActiveRecord::Base.establish_connection(@specification)
load_schema if in_memory_db?

View file

@ -14,7 +14,7 @@ class I18nValidationTest < ActiveRecord::TestCase
I18n.backend.store_translations('en', :errors => {:messages => {:custom => nil}})
end
def teardown
teardown do
I18n.load_path.replace @old_load_path
I18n.backend = @old_backend
end