A platform for community discussion. Free, open, simple.
FIX: When activating a user, ensure the change is reflected immediately
David Taylor2bb08d93e4c3
diff --git a/app/models/user.rb b/app/models/user.rbindex b0be74a26be..c1a94949a62 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -903,10 +903,8 @@ class User < ActiveRecord::Basedef activateif email_token = self.email_tokens.active.where(email: self.email).firstuser = 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_reviewableenddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex b06dc815f92..cc50d88b2ea 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -1867,6 +1867,12 @@ describe User doexpect(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' dotoken = inactive.email_tokens.find_by(email: inactive.email)token.update_column(:confirmed, true)