diff options
Diffstat (limited to 'activerecord/test/cases/helper.rb')
-rw-r--r-- | activerecord/test/cases/helper.rb | 71 |
1 files changed, 26 insertions, 45 deletions
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 95f8706d73..f1d69a215a 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -1,19 +1,15 @@ -require File.expand_path('../../../../load_paths', __FILE__) +require "config" -require 'config' +require "stringio" -require 'active_support/testing/autorun' -require 'active_support/testing/method_call_assertions' -require 'stringio' +require "active_record" +require "cases/test_case" +require "active_support/dependencies" +require "active_support/logger" +require "active_support/core_ext/string/strip" -require 'active_record' -require 'cases/test_case' -require 'active_support/dependencies' -require 'active_support/logger' -require 'active_support/core_ext/string/strip' - -require 'support/config' -require 'support/connection' +require "support/config" +require "support/connection" # TODO: Move all these random hacks into the ARTest namespace and into the support/ dir @@ -29,7 +25,7 @@ I18n.enforce_available_locales = false ARTest.connect # Quote "type" if it's a reserved word for the current connection. -QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') +QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name("type") # FIXME: Remove this when the deprecation cycle on TZ aware types by default ends. ActiveRecord::Base.time_zone_aware_types << :time @@ -51,18 +47,18 @@ def subsecond_precision_supported? end def mysql_enforcing_gtid_consistency? - current_adapter?(:Mysql2Adapter) && 'ON' == ActiveRecord::Base.connection.show_variable('enforce_gtid_consistency') + current_adapter?(:Mysql2Adapter) && "ON" == ActiveRecord::Base.connection.show_variable("enforce_gtid_consistency") end def supports_savepoints? ActiveRecord::Base.connection.supports_savepoints? end -def with_env_tz(new_tz = 'US/Eastern') - old_tz, ENV['TZ'] = ENV['TZ'], new_tz +def with_env_tz(new_tz = "US/Eastern") + old_tz, ENV["TZ"] = ENV["TZ"], new_tz yield ensure - old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') + old_tz ? ENV["TZ"] = old_tz : ENV.delete("TZ") end def with_timezone_config(cfg) @@ -136,21 +132,6 @@ def disable_extension!(extension, connection) connection.reconnect! end -require "cases/validations_repair_helper" -class ActiveSupport::TestCase - include ActiveRecord::TestFixtures - include ActiveRecord::ValidationsRepairHelper - include ActiveSupport::Testing::MethodCallAssertions - - self.fixture_path = FIXTURES_ROOT - self.use_instantiated_fixtures = false - self.use_transactional_tests = true - - def create_fixtures(*fixture_set_names, &block) - ActiveRecord::FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, fixture_class_names, &block) - end -end - def load_schema # silence verbose schema loading original_stdout = $stdout @@ -190,17 +171,17 @@ end module InTimeZone private - def in_time_zone(zone) - old_zone = Time.zone - old_tz = ActiveRecord::Base.time_zone_aware_attributes - - Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil - ActiveRecord::Base.time_zone_aware_attributes = !zone.nil? - yield - ensure - Time.zone = old_zone - ActiveRecord::Base.time_zone_aware_attributes = old_tz - end + def in_time_zone(zone) + old_zone = Time.zone + old_tz = ActiveRecord::Base.time_zone_aware_attributes + + Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil + ActiveRecord::Base.time_zone_aware_attributes = !zone.nil? + yield + ensure + Time.zone = old_zone + ActiveRecord::Base.time_zone_aware_attributes = old_tz + end end -require 'mocha/setup' # FIXME: stop using mocha +require "mocha/setup" # FIXME: stop using mocha |