From ff1061272cd79ff9208e7c03d762e5eced3ac511 Mon Sep 17 00:00:00 2001 From: Prommah Date: Thu, 24 Sep 2015 03:16:35 +0100 Subject: [PATCH] Return null steam data for previously invalid SteamIDs --- app/controllers/api/v1/users_controller.rb | 2 +- spec/controllers/api/v1/users_controller_spec.rb | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) mode change 100644 => 100755 app/controllers/api/v1/users_controller.rb mode change 100644 => 100755 spec/controllers/api/v1/users_controller_spec.rb diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb old mode 100644 new mode 100755 index 161772b..7c992d2 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -14,7 +14,7 @@ class Api::V1::UsersController < Api::V1::BaseController time_zone: @user.time_zone, avatar: @user.profile.avatar.url, admin: @user.admin?, - steam: { + steam: @user.steamid.nil? ? nil : { id: @user.steamid, url: @steam.nil? ? nil : @steam.base_url, nickname: @steam.nil? ? nil : @steam.nickname diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb old mode 100644 new mode 100755 index f9e362b..c2a7059 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -29,16 +29,14 @@ describe Api::V1::UsersController do expect(json["team"]).to be_nil end - it "returns data for users with invalid steam ids" do - @user.steamid = "0:0:000" + it "returns nulled steam data for users who had invalid steam ids" do + @user.steamid = nil @user.save! get :show, id: @user.id expect(response).to be_success - expect(json["steam"]["id"]).to_not be_nil - expect(json["steam"]["url"]).to be_nil - expect(json["steam"]["nickname"]).to be_nil + expect(json["steam"]).to be_nil end it "returns 404 if user does not exist" do