From 7c3ae50dcd111bf0466518c89b5d86fb42345b5e Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 20 Mar 2017 15:10:48 +0530 Subject: [PATCH] FIX: send activation email if user have unconfirmed email --- app/controllers/users_controller.rb | 2 +- spec/controllers/users_controller_spec.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0fb1de4e00f..6874fff56d2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -585,7 +585,7 @@ class UsersController < ApplicationController session.delete(SessionController::ACTIVATE_USER_KEY) - if @user.active + if @user.active && @user.email_confirmed? render_json_error(I18n.t('activation.activated'), status: 409) else @email_token = @user.email_tokens.unconfirmed.active.first diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index e227dd7afdd..d69165c35f3 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1424,9 +1424,11 @@ describe UsersController do context 'for an existing user' do let(:user) { Fabricate(:user, active: false) } - context 'for an activated account' do + context 'for an activated account with email confirmed' do it 'fails' do active_user = Fabricate(:user, active: true) + email_token = active_user.email_tokens.create(email: active_user.email).token + EmailToken.confirm(email_token) session[SessionController::ACTIVATE_USER_KEY] = active_user.id xhr :post, :send_activation_email, username: active_user.username @@ -1440,6 +1442,20 @@ describe UsersController do end end + context 'for an activated account with unconfirmed email' do + it 'should send an email' do + unconfirmed_email_user = Fabricate(:user, active: true) + unconfirmed_email_user.email_tokens.create(email: unconfirmed_email_user.email) + session[SessionController::ACTIVATE_USER_KEY] = unconfirmed_email_user.id + Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup)) + xhr :post, :send_activation_email, username: unconfirmed_email_user.username + + expect(response.status).to eq(200) + + expect(session[SessionController::ACTIVATE_USER_KEY]).to eq(nil) + end + end + describe 'when user does not have a valid session' do it 'should not be valid' do user = Fabricate(:user)