FIX: on initial token issue stop unmarking token as unseen

prev and current are the same so we need special logic to bypass
This commit is contained in:
Sam 2017-02-28 10:38:22 -05:00
parent ffd8fa7481
commit 3ac4709903
2 changed files with 15 additions and 1 deletions

View File

@ -64,7 +64,7 @@ class UserAuthToken < ActiveRecord::Base
return nil return nil
end end
if user_token.prev_auth_token == token && user_token.auth_token_seen if user_token.auth_token != token && user_token.prev_auth_token == token && user_token.auth_token_seen
changed_rows = UserAuthToken changed_rows = UserAuthToken
.where(id: user_token.id, prev_auth_token: token) .where(id: user_token.id, prev_auth_token: token)
.update_all(auth_token_seen: false) .update_all(auth_token_seen: false)

View File

@ -251,4 +251,18 @@ describe UserAuthToken do
end end
it "will not mark token unseen when prev and current are the same" do
user = Fabricate(:user)
token = UserAuthToken.generate!(user_id: user.id,
user_agent: "some user agent",
client_ip: "1.1.2.3")
lookup = UserAuthToken.lookup(token.unhashed_auth_token, seen: true)
lookup = UserAuthToken.lookup(token.unhashed_auth_token, seen: true)
lookup.reload
expect(lookup.auth_token_seen).to eq(true)
end
end end