FEATURE: trigger `user_updated` event if email changed.
It will trigger `user_updated` Discourse event if a user_email record is created or updated or destroyed.
This commit is contained in:
parent
906a84d66f
commit
1460d7957c
|
@ -19,6 +19,10 @@ class UserEmail < ActiveRecord::Base
|
|||
|
||||
scope :secondary, -> { where(primary: false) }
|
||||
|
||||
after_commit(on: [:create, :update, :destroy]) do
|
||||
DiscourseEvent.trigger(:user_updated, user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def strip_downcase_email
|
||||
|
|
|
@ -13,9 +13,17 @@ describe UserEmail do
|
|||
end
|
||||
|
||||
it "allows multiple secondary emails" do
|
||||
Fabricate(:secondary_email, user: user, primary: false)
|
||||
Fabricate(:secondary_email, user: user, primary: false)
|
||||
events = DiscourseEvent.track_events {
|
||||
Fabricate(:secondary_email, user: user, primary: false)
|
||||
Fabricate(:secondary_email, user: user, primary: false)
|
||||
}
|
||||
|
||||
expect(user.user_emails.count).to eq 3
|
||||
expect(events.count).to eq 2
|
||||
|
||||
event = events.first
|
||||
expect(event[:event_name]).to eq(:user_updated)
|
||||
expect(event[:params].first).to eq(user)
|
||||
end
|
||||
|
||||
it "does not allow an invalid email" do
|
||||
|
|
|
@ -63,9 +63,14 @@ describe UsersEmailController do
|
|||
it 'confirms with a correct token' do
|
||||
user.user_stat.update_columns(bounce_score: 42, reset_bounce_score_after: 1.week.from_now)
|
||||
|
||||
put "/u/confirm-new-email", params: {
|
||||
token: "#{user.email_tokens.last.token}"
|
||||
}
|
||||
event = DiscourseEvent.track_events {
|
||||
put "/u/confirm-new-email", params: {
|
||||
token: "#{user.email_tokens.last.token}"
|
||||
}
|
||||
}.last
|
||||
|
||||
expect(event[:event_name]).to eq(:user_updated)
|
||||
expect(event[:params].first).to eq(user)
|
||||
|
||||
expect(response.status).to eq(302)
|
||||
expect(response.redirect_url).to include("done")
|
||||
|
|
Loading…
Reference in New Issue