Project

General

Profile

Actions

Refactor #19085

closed

TokenTest expiry fails on MySQL with Rails 5.0, it should be removed

Added by Dominic Cleal about 7 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Under Rails 5.0, the following test fails when using a MySQL database:

  1) Failure:
TokenTest#test_0001_a token expires when set to expire [/home/dcleal/code/foreman/foreman/test/models/token_test.rb:12]:
--- expected
+++ actual
@@ -1 +1 @@
-Thu, 30 Mar 2017 08:35:18 UTC +00:00
+2017-03-30 08:35:18 UTC

On MySQL, the default precision of datetime fields is to the second, not nanoseconds (on PostgreSQL and SQlite). The test compares the value of Time.now.utc to the value of Token#expires, which if the model attribute has been rounded to the second, will not be equal.

This is reproducible on 4.2 by changing the test to persist and reload the Token. It differs on 5.0 as the attribute getter on the unpersisted model immediately returns the rounded value, so the comparison fails.

This can be fixed trivially (using #to_i to compare times), but I think the test should be removed as it's quite worthless - it only tests persistence of the expires attribute through Token.new. Real testing of token expiry occurs in test/models/host_test.rb.


Related issues 1 (0 open1 closed)

Blocks Foreman - Feature #19050: Add support for running under Ruby on Rails 5.0ClosedDominic Cleal03/28/2017Actions
Actions

Also available in: Atom PDF