TokenTest expiry fails on MySQL with Rails 5.0, it should be removed
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.
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.