diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 1ae379769f..059dc8cff3 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -12,6 +12,8 @@ require 'models/contact' require 'models/keyboard' class AttributeMethodsTest < ActiveRecord::TestCase + include InTimeZome + fixtures :topics, :developers, :companies, :computers def setup @@ -800,18 +802,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase Topic.columns.select { |c| [:time, :date, :datetime, :timestamp].include?(c.type) } 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 - def privatize(method_signature) @target.class_eval(<<-private_method, __FILE__, __LINE__ + 1) private diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index a6a7b2d528..ac1ab801da 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -27,6 +27,8 @@ class NumericData < ActiveRecord::Base end class DirtyTest < ActiveRecord::TestCase + include InTimeZome + # Dummy to force column loads so query counts are clean. def setup Person.create :first_name => 'foo' @@ -603,16 +605,4 @@ class DirtyTest < ActiveRecord::TestCase assert_equal %w(parrot_id), pirate.changed assert_nil pirate.parrot_id_was 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 diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index cff6689c15..cb1edc4627 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -135,3 +135,16 @@ module LogIntercepter end end +module InTimeZome + 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