Project

General

Profile

Refactor #19085

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

Added by Dominic Cleal over 1 year ago. Updated 4 months ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
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

Blocks Foreman - Feature #19050: Add support for running under Ruby on Rails 5.0Closed2017-03-28

Associated revisions

Revision 9a785fce (diff)
Added by Dominic Cleal over 1 year ago

fixes #19085 - remove test for Token#expires

Token expiry is fully tested in HostTest, as the expiry is actually a
concern on the Host::Managed model. This test fails due to datetime
field precision on MySQL databases with Rails 5, and doesn't appear to
have any value - it only tests a default constructor.

History

#1 Updated by The Foreman Bot over 1 year ago

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

#2 Updated by Dominic Cleal over 1 year ago

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

#3 Updated by The Foreman Bot over 1 year ago

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

#4 Updated by Dominic Cleal over 1 year ago

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

#5 Updated by Dominic Cleal over 1 year ago

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

#6 Updated by Marek Hulán about 1 year ago

  • Legacy Backlogs Release (now unused) set to 240

Also available in: Atom PDF