プロジェクト

全般

プロフィール

Vote #81427

完了

Use `Time.use_zone` instead of `Time.zone=`

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Code cleanup/refactoring_30
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
30
version_id:
155
issue_org_id:
35208
author_id:
332
assigned_to_id:
332
comments:
2
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

When temporarily overriding a time zone, it is safer to use @Time.use_zone@ than to update Time.zone directly because Time.use_zone will reset the time zone to its original value after the execution of the given block is done.

And RuboCop Rails 2.10.0 will display Rails/TimeZoneAssignment warning when it detects code that directly updates Time.zone.


Index: test/unit/mailer_test.rb
===================================================================
--- test/unit/mailer_test.rb    (リビジョン 20961)
+++ test/unit/mailer_test.rb    (作業コピー)
@@ -386,11 +386,10 @@
     issue = Issue.find(3)
     user = User.find(1)
     %w(UTC Paris Tokyo).each do |zone|
-      Time.zone = zone
-      assert_match /^redmine\.issue-3\.20060719190727\.1@example\.net/, Mailer.token_for(issue, user)
+      Time.use_zone(zone) do
+        assert_match /^redmine\.issue-3\.20060719190727\.1@example\.net/, Mailer.token_for(issue, user)
+      end
     end
-  ensure
-    Time.zone = zone_was
   end
 
   test "#issue_add should notify project members" do

journals

--------------------------------------------------------------------------------
Committed the patch.
--------------------------------------------------------------------------------


related_issues

relates,Closed,35207,Update RuboCop Rails to 2.14

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0