circleci
32 of 34 new or added lines in 3 files covered. (94.12%)
115 existing lines in 19 files now uncovered.1009 of 1014 relevant lines covered (99.51%)
96.7 hits per line
| 1 |
# frozen_string_literal: true
|
|
| 2 |
|
|
| 3 |
# This class is responsible for persisting
|
|
| 4 |
# OAuth tokens to the database
|
|
| 5 |
class OAuthToken < ApplicationRecord |
3✔ |
| 6 |
def token |
3✔ |
|
UNCOV
7
|
if expiration_time && not_yet_expired?
|
29✔ |
|
UNCOV
8
|
self[:token] |
6✔ |
| 9 |
else
|
|
|
UNCOV
10
|
fetch_new_token |
23✔ |
|
UNCOV
11
|
reload[:token]
|
21✔ |
| 12 |
end
|
|
| 13 |
end
|
|
| 14 |
|
|
| 15 |
private |
3✔ |
| 16 |
|
|
| 17 |
def fetch_new_token |
3✔ |
|
UNCOV
18
|
service = OAuthService.new(service: self.service, endpoint:) |
23✔ |
|
UNCOV
19
|
self.token = service.new_token
|
23✔ |
|
UNCOV
20
|
self.expiration_time = service.expiration_time
|
21✔ |
|
UNCOV
21
|
save |
21✔ |
| 22 |
end
|
|
| 23 |
|
|
| 24 |
def not_yet_expired? |
3✔ |
|
UNCOV
25
|
(Time.zone.now < expiration_time)
|
7✔ |
| 26 |
end
|
|
| 27 |
end
|