FIX: change title when primary group changes (#6602)

This commit is contained in:
Kyle Zhao 2018-11-13 19:28:41 -05:00 committed by Guo Xiang Tan
parent fc9aafaa6a
commit 38a9bc740d
2 changed files with 9 additions and 11 deletions

View File

@ -24,14 +24,7 @@ class GroupUser < ActiveRecord::Base
end
def set_primary_group
if group.primary_group
DB.exec("
UPDATE users
SET primary_group_id = :id
WHERE id = :user_id",
id: group.id, user_id: user_id
)
end
user.update!(primary_group: group) if group.primary_group
end
def remove_primary_group

View File

@ -710,11 +710,16 @@ describe Group do
end
it "always sets user's primary group" do
group.update(primary_group: true)
group.update(primary_group: true, title: 'AAAA')
expect { group.add(user) }.to change { user.reload.primary_group }.from(nil).to(group)
new_group = Fabricate(:group, primary_group: true)
expect { new_group.add(user) }.to change { user.reload.primary_group }.from(group).to(new_group)
new_group = Fabricate(:group, primary_group: true, title: 'BBBB')
expect {
new_group.add(user)
user.reload
}.to change { user.primary_group }.from(group).to(new_group)
.and change { user.title }.from('AAAA').to('BBBB')
end
context 'when adding a user into a public group' do