FIX: change title when primary group changes (#6602)
This commit is contained in:
parent
fc9aafaa6a
commit
38a9bc740d
|
@ -24,14 +24,7 @@ class GroupUser < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_primary_group
|
def set_primary_group
|
||||||
if group.primary_group
|
user.update!(primary_group: 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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_primary_group
|
def remove_primary_group
|
||||||
|
|
|
@ -710,11 +710,16 @@ describe Group do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "always sets user's primary group" do
|
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)
|
expect { group.add(user) }.to change { user.reload.primary_group }.from(nil).to(group)
|
||||||
|
|
||||||
new_group = Fabricate(:group, primary_group: true)
|
new_group = Fabricate(:group, primary_group: true, title: 'BBBB')
|
||||||
expect { new_group.add(user) }.to change { user.reload.primary_group }.from(group).to(new_group)
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
context 'when adding a user into a public group' do
|
context 'when adding a user into a public group' do
|
||||||
|
|
Loading…
Reference in New Issue