Improve test coverage and refactor User.find_by_username_or_email