2017年5月22日月曜日

rails4.1.6からrails5.0.3にアップデートでActiveSupport::TimeWithZoneにはまった

rails4.1.6からrails5.0.3にアップデートをした際にrspecのテストが落ちて、
それを解決するのに調べました。

環境
ruby2.3.1
rails4.1.6からrails5.0.3

rspecはこんな感じ
test_time = Time.now

user.test_at = test_time
user.save!

ごにょごにょ処理

test_atが変わらないよねっていうテスト
expect(user.test_at).to eq(test_time)

4.1.6では通っていたけど5.0.3で落ちたテスト結果
expected: 2017-05-16 16:26:54.647989000 +0900
          got: 2017-05-16 16:26:54.000000000 +0900

test_timeはTimeクラス、user.test_atはActiveSupport::TimeWithZone。
rails4.1.6のときはsave!のタイミングではTimeWithZoneのミリ秒はまるめられてなかったみたい。
4.1.6でもexpectの前にreloadすると、ミリ秒はまるめられたものに変わった。
rails5ではsave!のタイミングでミリ秒をまるめたものを保持するように変わったげ。

1 件のコメント:

  1. Play casino games for real money with no deposit required
    In this 포항 출장마사지 article, we will try to explain 파주 출장안마 the casino's games and how to 충청남도 출장안마 play them, how to deposit, and the 당진 출장마사지 best gambling 대전광역 출장마사지 experiences to

    返信削除