FIX: always trigger the ':user_updated' event

We don't always use the UserUpdated class to update a user's record
This commit is contained in:
Régis Hanol 2017-08-04 18:12:10 +02:00
parent ecbeaed0bc
commit 519b70ea46
3 changed files with 13 additions and 5 deletions

View File

@ -103,6 +103,7 @@ class User < ActiveRecord::Base
after_save :expire_old_email_tokens
after_save :index_search
after_commit :trigger_user_created_event, on: :create
after_commit :trigger_user_updated_event, on: :update
before_destroy do
# These tables don't have primary keys, so destroying them with activerecord is tricky:
@ -1092,6 +1093,11 @@ class User < ActiveRecord::Base
true
end
def trigger_user_updated_event
DiscourseEvent.trigger(:user_updated, self)
true
end
end
# == Schema Information

View File

@ -121,7 +121,6 @@ class UserUpdater
end
end
DiscourseEvent.trigger(:user_updated, user) if saved
saved
end

View File

@ -90,12 +90,15 @@ describe User do
user.approve(admin)
end
it 'triggers a extensibility event' do
it 'triggers extensibility events' do
user && admin # bypass the user_created event
event = DiscourseEvent.track_events { user.approve(admin) }.first
user_updated_event, user_approved_event = DiscourseEvent.track_events { user.approve(admin) }
expect(event[:event_name]).to eq(:user_approved)
expect(event[:params].first).to eq(user)
expect(user_updated_event[:event_name]).to eq(:user_updated)
expect(user_updated_event[:params].first).to eq(user)
expect(user_approved_event[:event_name]).to eq(:user_approved)
expect(user_approved_event[:params].first).to eq(user)
end
context 'after approval' do