From 5214f8284126a9bbd448dd0186481c0421228f2a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 30 Dec 2019 10:14:29 -0500 Subject: [PATCH] API endpoints should return a response, not nil --- app/controllers/admin/users_controller.rb | 2 +- spec/requests/admin/users_controller_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 72ad4a1f5c4..fdc0815a01f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -301,7 +301,7 @@ class Admin::UsersController < Admin::AdminController @user.deactivate(current_user) StaffActionLogger.new(current_user).log_user_deactivate(@user, I18n.t('user.deactivated_by_staff'), params.slice(:context)) refresh_browser @user - render body: nil + render json: success_json end def silence diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb index e39ddde0554..2e787bb4ad6 100644 --- a/spec/requests/admin/users_controller_spec.rb +++ b/spec/requests/admin/users_controller_spec.rb @@ -593,6 +593,19 @@ RSpec.describe Admin::UsersController do end end + describe '#deactivate' do + fab!(:reg_user) { Fabricate(:active_user) } + + it "returns success" do + put "/admin/users/#{reg_user.id}/deactivate.json" + expect(response.status).to eq(200) + json = ::JSON.parse(response.body) + expect(json['success']).to eq("OK") + reg_user.reload + expect(reg_user.active).to eq(false) + end + end + describe '#log_out' do fab!(:reg_user) { Fabricate(:user) }