Skip to content

Commit fff2b4f

Browse files
committed
use TimeWithZone instead of just Time
1 parent 014ef37 commit fff2b4f

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

app/controllers/kracken/sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def create
1111
current_user = @user
1212
session[:user_id] = @user.id
1313
session[:user_cache_key] = cookies[:_radius_user_cache_key]
14-
session[:token_expires_at] = Time.at(auth_hash[:credentials][:expires_at])
14+
session[:token_expires_at] = Time.zone.at(auth_hash[:credentials][:expires_at])
1515
redirect_to return_to_path
1616
end
1717

lib/kracken/controllers/authenticatable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def authenticate_user!
4545
end
4646

4747
def check_token_expiry!
48-
if session[:token_expires_at].nil? || session[:token_expires_at] < Time.now
48+
if session[:token_expires_at].nil? || session[:token_expires_at] < Time.zone.now
4949
session.delete :user_id
5050
end
5151
end

spec/kracken/controllers/authenticatable_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ class ControllerDouble < BaseControllerDouble
9595
it "redirects to sign-in when token has expired" do
9696
allow(controller).to receive(:request).and_return(double(format: nil, fullpath: nil))
9797
allow(controller).to receive(:redirect_to)
98-
controller.session[:token_expires_at] = 5.minutes.ago
98+
controller.session[:token_expires_at] = Time.zone.now - 5.minutes
9999
controller.authenticate_user!
100100
expect(controller).to have_received(:redirect_to)
101101
end
102102

103103
it "authenticates user when token has not expired" do
104104
allow(controller).to receive(:request).and_return(double(format: nil, fullpath: nil))
105105
allow(controller).to receive(:redirect_to)
106-
controller.session[:token_expires_at] = Time.now + 5.minutes
106+
controller.session[:token_expires_at] = Time.zone.now + 5.minutes
107107
controller.authenticate_user!
108108
expect(controller).to_not have_received(:redirect_to)
109109
end

spec/requests/authentication_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def headers_with_token(token)
3131
it "sets :token_expires_at in the session" do
3232
OmniAuth.config.mock_auth[:radius] = OmniAuth::AuthHash.new(auth_hash)
3333
get "/auth/radius/callback"
34-
expect(request.session[:token_expires_at]).to eq(Time.at(token_expiry))
34+
expect(request.session[:token_expires_at]).to eq(Time.zone.at(token_expiry))
3535
end
3636
end
3737
end

0 commit comments

Comments
 (0)