I have a simple test
test "should store activation time when activated" do
profile = create(:raw_profile)
get profile_activate_path(profile)
assert_equal profile.updated_at, profile.activated_at
end
And a simple Profile method without any after_action
or anything it's straightforward
def activate
@profile.update_columns(active: true)
@profile.touch(:activated_at)
redirect_to @profile, notice: "Profile activated."
end
But the test fails with always a 2s or 3s difference
--- expected
+++ actual
@@ -1 +1 @@
-Sun, 23 Aug 2020 19:33:51 CEST +02:00
+Sun, 23 Aug 2020 19:33:49 CEST +02:00
test/controllers/profiles_controller_test.rb:73:in `block in <class:ProfilesControllerTest>'
An actual record in the console (or in the app itself) behaves correctly
>> p.touch(:activated_at)
(18.1ms) BEGIN
Profile Update (2.2ms) UPDATE "profiles" SET "updated_at" = $1, "activated_at" = $2 WHERE "profiles"."id" = $3 [["updated_at", "2020-08-23 17:32:46.239317"], ["activated_at", "2020-08-23 17:32:46.239317"], ["id", 11]]
(5.8ms) COMMIT
=> true
>> p.activated_at == p.updated_at
=> true
What's going on?
Aucun commentaire:
Enregistrer un commentaire