FIX: When activating a user, ensure the change is reflected immediately

When activating a user via an external provider, this would cause the "this account is not activated" message to show on the first attempt, even though the account had been activated correctly.
This commit is contained in:
David Taylor 2019-08-28 12:44:16 +01:00
parent a5e198fa30
commit 2bb08d93e4
2 changed files with 7 additions and 3 deletions

View File

@ -903,10 +903,8 @@ class User < ActiveRecord::Base
def activate
if email_token = self.email_tokens.active.where(email: self.email).first
user = EmailToken.confirm(email_token.token, skip_reviewable: true)
self.update!(active: true) if user.nil?
else
self.update!(active: true)
end
self.update!(active: true)
create_reviewable
end

View File

@ -1867,6 +1867,12 @@ describe User do
expect(inactive.active).to eq(true)
end
it 'works without needing to reload the model' do
inactive.activate
expect(inactive.email_confirmed?).to eq(true)
expect(inactive.active).to eq(true)
end
it 'activates user even if email token is already confirmed' do
token = inactive.email_tokens.find_by(email: inactive.email)
token.update_column(:confirmed, true)