diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 311a11b2f91..b4024a280ad 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -128,6 +128,8 @@ class GroupsController < ApplicationController user = User.find(params[:user_id]) elsif params[:username].present? user = User.find_by_username(params[:username]) + elsif params[:user_email].present? + user = User.find_by_email(params[:user_email]) else raise Discourse::InvalidParameters.new('user_id or username must be present') end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index fded427a080..b926e4d6c62 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -200,19 +200,22 @@ describe GroupsController do end it "removes by id" do - xhr :delete, :remove_member, id: group.id, user_id: user.id + expect do + xhr :delete, :remove_member, id: group.id, user_id: user.id - expect(response).to be_success - group.reload - expect(group.users.count).to eq(0) + expect(response).to be_success + group.reload + end.to change{group.users.count}.from(1).to(0) end it "removes by username" do - xhr :delete, :remove_member, id: group.id, username: user.username + expect do + xhr :delete, :remove_member, id: group.id, username: user.username - expect(response).to be_success - group.reload - expect(group.users.count).to eq(0) + expect(response).to be_success + group.reload + + end.to change{group.users.count}.from(1).to(0) end it "removes user.primary_group_id when user is removed from group" do @@ -224,6 +227,14 @@ describe GroupsController do user.reload expect(user.primary_group_id).to eq(nil) end + + it "removes by user_email" do + expect do + xhr :delete, :remove_member, id: group.id, user_email: user.email + expect(response).to be_success + group.reload + end.to change{group.users.count}.from(1).to(0) + end end end