DEV: trigger :username_changed when a user is renamed (#9301)

This commit is contained in:
Joffrey JAFFEUX 2020-03-30 18:02:34 +02:00 committed by GitHub
parent 6c2717eda0
commit 96e841a635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -34,6 +34,8 @@ module Jobs
update_revisions
update_notifications
update_post_custom_fields
DiscourseEvent.trigger(:username_changed, @old_username, @new_username)
end
def update_posts

View File

@ -11,13 +11,20 @@ describe UsernameChanger do
let(:user) { Fabricate(:user) }
context 'success' do
let!(:old_username) { user.username }
let(:new_username) { "#{user.username}1234" }
it 'should change the username' do
@result = UsernameChanger.change(user, new_username)
event = DiscourseEvent.track_events {
@result = UsernameChanger.change(user, new_username)
}.last
expect(@result).to eq(true)
expect(event[:event_name]).to eq(:username_changed)
expect(event[:params].first).to eq(old_username)
expect(event[:params].second).to eq(new_username)
user.reload
expect(user.username).to eq(new_username)
expect(user.username_lower).to eq(new_username.downcase)