From 02ade72ceba8aab3e6e2ad5936e928eb0b8b3a50 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Wed, 10 Dec 2014 09:43:16 -0700 Subject: [PATCH] Update username should return a json response - Have update username return json response that contains the updated username and id. I figured this would be better than just return "OK". - Add test to verify that the new username is returned. --- app/controllers/users_controller.rb | 5 ++++- spec/controllers/users_controller_spec.rb | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 64b7fc8ac..15fd6de00 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -91,7 +91,10 @@ class UsersController < ApplicationController result = user.change_username(params[:new_username]) raise Discourse::InvalidParameters.new(:new_username) unless result - render nothing: true + render json: { + id: user.id, + username: user.username + } end def check_emails diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index f682ab631..b6f7cb15c 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -636,6 +636,11 @@ describe UsersController do response.should be_success end + it 'should return a JSON response with the updated username' do + xhr :put, :username, username: user.username, new_username: new_username + ::JSON.parse(response.body)['username'].should == new_username + end + end end