DEV: Replace User.unstage and User#unstage API with User#unstage! (#8906)

* DEV: Replace User.unstage and User#unstage API with User#unstage!

Quoting @SamSaffron:

> User.unstage mixes concerns of both unstaging users and updating params which is fragile/surprising.
> u.unstage destroys notifications and raises a user_unstaged event prior to the user becoming unstaged and the user object being saved.

User#unstage! no longer updates user attributes and saves the object before triggering the `user_unstaged` event.

* Update one more spec

* Assign attributes after unstaging
This commit is contained in:
Jarek Radosz
2020-03-17 16:48:24 +01:00
committed by GitHub
parent 43b38dbbc2
commit e950471c0f
9 changed files with 41 additions and 62 deletions

View File

@ -113,8 +113,7 @@ class Users::OmniauthCallbacksController < ApplicationController
# automatically activate/unstage any account if a provider marked the email valid
if @auth_result.email_valid && @auth_result.email == user.email
user.unstage
user.save
user.unstage!
if !user.active || !user.email_confirmed?
user.update!(password: SecureRandom.hex)