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:
parent
ecbeaed0bc
commit
519b70ea46
|
@ -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
|
||||
|
|
|
@ -121,7 +121,6 @@ class UserUpdater
|
|||
end
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:user_updated, user) if saved
|
||||
saved
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue