Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def devices?

def second_last_signed_in_at
user.events.where(event_type: 'sign_in_after_2fa').
order(created_at: :desc).pluck(:created_at).second
order(created_at: :desc).limit(2).pluck(:created_at).second
end

def connected_apps
Expand Down
11 changes: 11 additions & 0 deletions spec/decorators/user_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,15 @@
expect(user_decorator.connected_apps).to eq([app])
end
end

describe '#second_last_signed_in_at' do
it 'returns second most recent full authentication event' do
user = create(:user)
_event1 = create(:event, user: user, event_type: 'sign_in_after_2fa')
event2 = create(:event, user: user, event_type: 'sign_in_after_2fa')
_event3 = create(:event, user: user, event_type: 'sign_in_after_2fa')

expect(user.decorate.second_last_signed_in_at).to eq(event2.reload.created_at)
end
end
end