FEATURE: trigger user_updated event if username is changed.

This commit is contained in:
Vinoth Kannan 2020-07-03 00:14:19 +05:30
parent de243426c4
commit 9426d12c1d
2 changed files with 8 additions and 2 deletions

View File

@ -36,6 +36,7 @@ module Jobs
update_post_custom_fields
DiscourseEvent.trigger(:username_changed, @old_username, @new_username)
DiscourseEvent.trigger(:user_updated, User.find_by(id: @user_id))
end
def update_posts

View File

@ -15,16 +15,21 @@ describe UsernameChanger do
let(:new_username) { "#{user.username}1234" }
it 'should change the username' do
event = DiscourseEvent.track_events {
events = DiscourseEvent.track_events {
@result = UsernameChanger.change(user, new_username)
}.last
}.last(2)
expect(@result).to eq(true)
event = events.first
expect(event[:event_name]).to eq(:username_changed)
expect(event[:params].first).to eq(old_username)
expect(event[:params].second).to eq(new_username)
event = events.last
expect(event[:event_name]).to eq(:user_updated)
expect(event[:params].first).to eq(user)
user.reload
expect(user.username).to eq(new_username)
expect(user.username_lower).to eq(new_username.downcase)