FIX: Don't raise an error if you try to assign a group that exists
This commit is contained in:
parent
6b236d3c83
commit
23371b026d
|
@ -121,7 +121,10 @@ class Admin::UsersController < Admin::AdminController
|
||||||
def add_group
|
def add_group
|
||||||
group = Group.find(params[:group_id].to_i)
|
group = Group.find(params[:group_id].to_i)
|
||||||
return render_json_error group unless group && !group.automatic
|
return render_json_error group unless group && !group.automatic
|
||||||
group.users << @user
|
|
||||||
|
# We don't care about duplicate group assignment
|
||||||
|
group.users << @user rescue ActiveRecord::RecordNotUnique
|
||||||
|
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ describe Admin::UsersController do
|
||||||
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(0)
|
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(0)
|
||||||
|
|
||||||
xhr :get, :index, show_emails: "true"
|
xhr :get, :index, show_emails: "true"
|
||||||
data = ::JSON.parse(response.body)
|
|
||||||
|
|
||||||
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(1)
|
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(1)
|
||||||
end
|
end
|
||||||
|
@ -173,6 +172,22 @@ describe Admin::UsersController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '.add_group' do
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
let(:group) { Fabricate(:group) }
|
||||||
|
|
||||||
|
it 'adds the user to the group' do
|
||||||
|
xhr :post, :add_group, group_id: group.id, user_id: user.id
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
expect(GroupUser.where(user_id: user.id, group_id: group.id).exists?).to eq(true)
|
||||||
|
|
||||||
|
# Doing it again doesn't raise an error
|
||||||
|
xhr :post, :add_group, group_id: group.id, user_id: user.id
|
||||||
|
expect(response).to be_success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '.primary_group' do
|
context '.primary_group' do
|
||||||
before do
|
before do
|
||||||
@another_user = Fabricate(:coding_horror)
|
@another_user = Fabricate(:coding_horror)
|
||||||
|
|
Loading…
Reference in New Issue