FEATURE: match user title when primary group changes

When primary group changes and the user's title is the previous primary
group's title, change the title to the new primary group's title
This commit is contained in:
Kyle Zhao
2018-09-17 13:08:39 +08:00
committed by Sam
parent 53d34c69fc
commit 6659417807
3 changed files with 57 additions and 0 deletions

View File

@ -1814,4 +1814,16 @@ describe User do
end
describe '#match_title_to_primary_group_changes' do
let(:primary_group_a) { Fabricate(:group, title: 'A', users: [user]) }
let(:primary_group_b) { Fabricate(:group, title: 'B', users: [user]) }
it "updates user's title only when it is blank or matches the previous primary group" do
expect { user.update(primary_group: primary_group_a) }.to change { user.reload.title }.from(nil).to('A')
expect { user.update(primary_group: primary_group_b) }.to change { user.reload.title }.from('A').to('B')
user.update(title: 'Different')
expect { user.update(primary_group: primary_group_a) }.to_not change { user.reload.title }
end
end
end