プロジェクト

全般

プロフィール

Vote #81045

未完了

Do not use timezone unaware methods

Admin Redmine さんが約2年前に追加. 約2年前に更新.

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

0%

予定工数:
category_id:
44
version_id:
0
issue_org_id:
33941
author_id:
362529
assigned_to_id:
0
comments:
6
status_id:
1
tracker_id:
1
plus1:
1
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

説明

If you set the timezone in @config/additional_environment.rb@ and test it, any tests may fail.


config.time_zone = 'International Date Line West'   # UTC-12:00
The test will always fail if the date of today on @UTC@ and the date of today on @config.time_zone@ are different.
$ RAILS_ENV=test bundle exec rake db:migrate:reset

$ RAILS_ENV=test bundle exec rake test
Run options: --seed 21968

# Running:

....................F

Failure:
MailerTest#test_reminders [./test/unit/mailer_test.rb:694]:
"Bug #3: Error 281 when updating a recipe (5 days late)" not found in "1 issue(s) that are assigned to you are due in the next 42 days::

* eCookbook - Bug #3: Error 281 when updating a recipe (6 days late)

View all issues (2 open)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
"


bin/rails test test/unit/mailer_test.rb:687

................F

Failure:
MailerTest#test_reminders_should_sort_issues_by_due_date [./test/unit/mailer_test.rb:823]:
<(?-mix:foo \(1 day late\))> expected but was
..
Expected 0 to be >= 1.


bin/rails test test/unit/mailer_test.rb:811

........F

Failure:
MailerTest#test_reminders_language_auto [./test/unit/mailer_test.rb:717]:
"Bug #3: Error 281 when updating a recipe (En retard de 5 jours)" not found in "1 demande(s) qui vous sont assignées arrivent à échéance dans les 42 prochains jours ::

* eCookbook - Bug #3: Error 281 when updating a recipe (En retard de 6 jours)

Voir toutes les demandes (2 ouvertes)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
"


bin/rails test test/unit/mailer_test.rb:708

....F

Failure:
MailerTest#test_reminder_should_include_issues_assigned_to_groups [./test/unit/mailer_test.rb:773]:
"Assigned to group (Due in 5 days)" not found in "1 issue(s) that are assigned to you are due in the next 7 days::

* eCookbook - Bug #15: Assigned to group (Due in 4 days)

View all issues (2 open)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
"


bin/rails test test/unit/mailer_test.rb:749

.......F

Failure:
MailerTest#test_reminders_for_users [./test/unit/mailer_test.rb:746]:
"Bug #3: Error 281 when updating a recipe (5 days late)" not found in "1 issue(s) that are assigned to you are due in the next 42 days::

* eCookbook - Bug #3: Error 281 when updating a recipe (6 days late)

View all issues (2 open)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
"


bin/rails test test/unit/mailer_test.rb:738

...........

Finished in 411.745744s, 12.2090 runs/s, 56.3649 assertions/s.
5027 runs, 23208 assertions, 5 failures, 0 errors, 7 skips

You have skipped tests. Run with --verbose for details.
$

journals

There are two possible causes for the test to fail.

* When using @Date.today, Time.now, DateTime.now@, the timezone in config.time_zone is ignored. You should use @Date.current, Time.current, DateTime.current@.
* Times of the day are not stored in table columns of type of date. However, in @Query#date_clause@(source:/trunk/app/models/query.rb#L1465), because the where condition considering the time difference is created for this Date type table column, the SQL execution result is strange.
--------------------------------------------------------------------------------
Yuichi HARADA wrote:
> There are two possible causes for the test to fail.
>
> * When using @Date.today, Time.now, DateTime.now@, the timezone in config.time_zone is ignored. You should use @Date.current, Time.current, DateTime.current@.
> * Times of the day are not stored in table columns of type of date. However, in @Query#date_clause@(source:/trunk/app/models/query.rb#L1465), because the where condition considering the time difference is created for this Date type table column, the SQL execution result is strange.

I will attach a patch to resolve these.

I've tested in the following time zones to make sure the tests don't fail.

<pre><code class="ruby">
config.time_zone = 'UTC' # UTC+-00:00

config.time_zone = 'Tokyo' # UTC+09:00
config.time_zone = 'Samoa' # UTC+13:00

config.time_zone = 'Alaska' # UTC-09:00
config.time_zone = 'International Date Line West' # UTC-12:00
</code></pre>

--------------------------------------------------------------------------------
+1

After applying this patch, you should be able to enable Rails/Date for Rubocop, which is currently disabled.
https://www.rubydoc.info/gems/rubocop/0.41.2/RuboCop/Cop/Rails/Date
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Here is the result of the following command:

<pre>
bundle exec rubocop --ignore-disable-comments --only Rails/TimeZone,Rails/Date
</pre>
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,New,23189,Spent time by filter, offset by one day

Admin Redmine さんが約2年前に更新

  • カテゴリRails support_44 にセット

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

いいね!0
いいね!0