Skip to content
This repository
Browse code

use method with_active_record_default_timezone

  • Loading branch information...
commit a0f0943d3a8c7f277d1266fce898b128b136bf6a 1 parent b67a80d
Neeraj Singh neerajdotname authored

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

  1. +20 30 activerecord/test/cases/quoting_test.rb
50 activerecord/test/cases/quoting_test.rb
@@ -53,50 +53,40 @@ def test_quoted_date
53 53 end
54 54
55 55 def test_quoted_time_utc
56   - before = ActiveRecord::Base.default_timezone
57   - ActiveRecord::Base.default_timezone = :utc
58   - t = Time.now
59   - assert_equal t.getutc.to_s(:db), @quoter.quoted_date(t)
60   - ensure
61   - ActiveRecord::Base.default_timezone = before
  56 + with_active_record_default_timezone :utc do
  57 + t = Time.now
  58 + assert_equal t.getutc.to_s(:db), @quoter.quoted_date(t)
  59 + end
62 60 end
63 61
64 62 def test_quoted_time_local
65   - before = ActiveRecord::Base.default_timezone
66   - ActiveRecord::Base.default_timezone = :local
67   - t = Time.now
68   - assert_equal t.getlocal.to_s(:db), @quoter.quoted_date(t)
69   - ensure
70   - ActiveRecord::Base.default_timezone = before
  63 + with_active_record_default_timezone :local do
  64 + t = Time.now
  65 + assert_equal t.getlocal.to_s(:db), @quoter.quoted_date(t)
  66 + end
71 67 end
72 68
73 69 def test_quoted_time_crazy
74   - before = ActiveRecord::Base.default_timezone
75   - ActiveRecord::Base.default_timezone = :asdfasdf
76   - t = Time.now
77   - assert_equal t.getlocal.to_s(:db), @quoter.quoted_date(t)
78   - ensure
79   - ActiveRecord::Base.default_timezone = before
  70 + with_active_record_default_timezone :asdfasdf do
  71 + t = Time.now
  72 + assert_equal t.getlocal.to_s(:db), @quoter.quoted_date(t)
  73 + end
80 74 end
81 75
82 76 def test_quoted_datetime_utc
83   - before = ActiveRecord::Base.default_timezone
84   - ActiveRecord::Base.default_timezone = :utc
85   - t = DateTime.now
86   - assert_equal t.getutc.to_s(:db), @quoter.quoted_date(t)
87   - ensure
88   - ActiveRecord::Base.default_timezone = before
  77 + with_active_record_default_timezone :utc do
  78 + t = DateTime.now
  79 + assert_equal t.getutc.to_s(:db), @quoter.quoted_date(t)
  80 + end
89 81 end
90 82
91 83 ###
92 84 # DateTime doesn't define getlocal, so make sure it does nothing
93 85 def test_quoted_datetime_local
94   - before = ActiveRecord::Base.default_timezone
95   - ActiveRecord::Base.default_timezone = :local
96   - t = DateTime.now
97   - assert_equal t.to_s(:db), @quoter.quoted_date(t)
98   - ensure
99   - ActiveRecord::Base.default_timezone = before
  86 + with_active_record_default_timezone :local do
  87 + t = DateTime.now
  88 + assert_equal t.to_s(:db), @quoter.quoted_date(t)
  89 + end
100 90 end
101 91
102 92 def test_quote_with_quoted_id

0 comments on commit a0f0943

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