Project

General

Profile

Actions

Refactor #19085

closed

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

Added by Dominic Cleal over 7 years ago. Updated about 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 #1

Updated by The Foreman Bot over 7 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4423 added
Actions #2

Updated by Dominic Cleal over 7 years ago

  • Blocks Feature #19050: Add support for running under Ruby on Rails 5.0 added
Actions #3

Updated by The Foreman Bot over 7 years ago

  • Pull request https://github.com/theforeman/foreman/pull/4422 added
Actions #4

Updated by Dominic Cleal over 7 years ago

  • Pull request deleted (https://github.com/theforeman/foreman/pull/4422)
Actions #5

Updated by Dominic Cleal over 7 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #6

Updated by Marek Hulán almost 7 years ago

  • Translation missing: en.field_release set to 240
Actions

Also available in: Atom PDF