Skip to content
This repository
Browse code

Merge pull request #6870 from erichmenge/patch/base_test_oracle

Setup each test with default ActiveRecord timezone settings to ensure ea...
  • Loading branch information...
commit 5847f59b2506d40e45edc2db671b897b9bffe640 2 parents 99e10eb + 600f027
Rafael Mendonça França authored June 26, 2012

Showing 1 changed file with 8 additions and 20 deletions. Show diff stats Hide diff stats

  1. 28  activerecord/test/cases/base_test.rb
28  activerecord/test/cases/base_test.rb
@@ -81,6 +81,12 @@ def setup
81 81
 class BasicsTest < ActiveRecord::TestCase
82 82
   fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories, :posts
83 83
 
  84
+  def setup
  85
+    ActiveRecord::Base.time_zone_aware_attributes = false
  86
+    ActiveRecord::Base.default_timezone = :local
  87
+    Time.zone = nil
  88
+  end
  89
+
84 90
   def test_generated_methods_modules
85 91
     modules = Computer.ancestors
86 92
     assert modules.include?(Computer::GeneratedFeatureMethods)
@@ -686,7 +692,7 @@ def test_multiparameter_attributes_on_time
686 692
     }
687 693
     topic = Topic.find(1)
688 694
     topic.attributes = attributes
689  
-    assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on
  695
+    assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
690 696
   end
691 697
 
692 698
   def test_multiparameter_attributes_on_time_with_no_date
@@ -793,8 +799,6 @@ def test_multiparameter_attributes_on_time_with_utc
793 799
     topic = Topic.find(1)
794 800
     topic.attributes = attributes
795 801
     assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on
796  
-  ensure
797  
-    ActiveRecord::Base.default_timezone = :local
798 802
   end
799 803
 
800 804
   def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
@@ -810,14 +814,9 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
810 814
     assert_equal Time.utc(2004, 6, 24, 23, 24, 0), topic.written_on
811 815
     assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on.time
812 816
     assert_equal Time.zone, topic.written_on.time_zone
813  
-  ensure
814  
-    ActiveRecord::Base.time_zone_aware_attributes = false
815  
-    ActiveRecord::Base.default_timezone = :local
816  
-    Time.zone = nil
817 817
   end
818 818
 
819 819
   def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
820  
-    ActiveRecord::Base.time_zone_aware_attributes = false
821 820
     Time.zone = ActiveSupport::TimeZone[-28800]
822 821
     attributes = {
823 822
       "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
@@ -827,8 +826,6 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
827 826
     topic.attributes = attributes
828 827
     assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
829 828
     assert_equal false, topic.written_on.respond_to?(:time_zone)
830  
-  ensure
831  
-    Time.zone = nil
832 829
   end
833 830
 
834 831
   def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_attributes
@@ -845,9 +842,6 @@ def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_at
845 842
     assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on
846 843
     assert_equal false, topic.written_on.respond_to?(:time_zone)
847 844
   ensure
848  
-    ActiveRecord::Base.time_zone_aware_attributes = false
849  
-    ActiveRecord::Base.default_timezone = :local
850  
-    Time.zone = nil
851 845
     Topic.skip_time_zone_conversion_for_attributes = []
852 846
   end
853 847
 
@@ -865,10 +859,6 @@ def test_multiparameter_attributes_on_time_only_column_with_time_zone_aware_attr
865 859
       topic.attributes = attributes
866 860
       assert_equal Time.utc(2000, 1, 1, 16, 24, 0), topic.bonus_time
867 861
       assert topic.bonus_time.utc?
868  
-    ensure
869  
-      ActiveRecord::Base.time_zone_aware_attributes = false
870  
-      ActiveRecord::Base.default_timezone = :local
871  
-      Time.zone = nil
872 862
     end
873 863
   end
874 864
 
@@ -911,7 +901,7 @@ def test_attributes_on_dummy_time
911 901
     }
912 902
     topic = Topic.find(1)
913 903
     topic.attributes = attributes
914  
-    assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
  904
+    assert_equal Time.local(2000, 1, 1, 5, 42, 0), topic.bonus_time
915 905
   end
916 906
 
917 907
   def test_boolean
@@ -1876,8 +1866,6 @@ def test_cache_key_for_existing_record_is_not_timezone_dependent
1876 1866
     est_key = Developer.first.cache_key
1877 1867
 
1878 1868
     assert_equal utc_key, est_key
1879  
-  ensure
1880  
-    ActiveRecord::Base.time_zone_aware_attributes = false
1881 1869
   end
1882 1870
 
1883 1871
   def test_cache_key_format_for_existing_record_with_updated_at

0 notes on commit 5847f59

Please sign in to comment.
Something went wrong with that request. Please try again.