Commit e54cc7a
authored
Previously, if `User#expires_at` was defined, but it was set to `nil`,
the `expires_in` calculation was returning a large negative integer.
This was because `nil.to_i` is 0 and thus `user.expires_at.to_i -
Time.zone.now.to_i` was a value like `-1744820986` (for 2025-04-16
17:30) which meant the credentials were effectively immediately expired
some time ago.
This isn't a problem in e.g. `code-club-frontend`, because [the user
factory sets `User#expires_at` to a time a random number of seconds in
the future, i.e. `rand(60..300).seconds.from_now][1].
We've had to do [something similar in `experience-cs`][2], but I think a
better solution is to default to using the 3600 fallback value if
`User#expires_at` is `nil` just like we do if `User#expires_at` is not
defined.
[1]:
https://github.com/RaspberryPiFoundation/code-club-frontend/blob/f7e965798d910584fed0d1eb7867f32a899f9ce8/spec/factories/user.rb#L21
[2]:
https://github.com/RaspberryPiFoundation/experience-cs/blob/47d11bd60da7b7bd93968534542f84edca4054aa/spec/factories/user.rb#L5
2 files changed
+3
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
0 commit comments