diff --git a/app/models/user.rb b/app/models/user.rb index c52b456ce45..2895c212321 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -108,7 +108,6 @@ 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: @@ -1098,11 +1097,6 @@ class User < ActiveRecord::Base true end - def trigger_user_updated_event - DiscourseEvent.trigger(:user_updated, self) - true - end - def set_should_validate_email if self.primary_email self.primary_email.should_validate_email = should_validate_email_address? diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index e2d3c703a7a..591a50a966f 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -122,6 +122,7 @@ class UserUpdater end end + DiscourseEvent.trigger(:user_updated, user) if saved saved end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cd075118343..ee0b4405a2f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -91,15 +91,12 @@ describe User do user.approve(admin) end - it 'triggers extensibility events' do + it 'triggers a extensibility event' do user && admin # bypass the user_created event - user_updated_event, user_approved_event = DiscourseEvent.track_events { user.approve(admin) } + event = DiscourseEvent.track_events { user.approve(admin) }.first - 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) + expect(event[:event_name]).to eq(:user_approved) + expect(event[:params].first).to eq(user) end context 'after approval' do