From e4287d9de9458aa29b8f7dbd7a4e3d5f17e6bcd4 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 28 Aug 2014 12:07:13 -0400 Subject: [PATCH] FIX: Resend activation email was busted --- app/controllers/application_controller.rb | 7 +++++-- app/controllers/users_controller.rb | 2 +- spec/controllers/users_controller_spec.rb | 6 +----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 30cea7940f5..27179e4abba 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -212,11 +212,14 @@ class ApplicationController < ActionController::Base Middleware::AnonymousCache.anon_cache(request.env, time_length) end - def fetch_user_from_params + def fetch_user_from_params(opts=nil) + opts ||= {} user = if params[:username] username_lower = params[:username].downcase username_lower.gsub!(/\.json$/, '') - User.find_by(username_lower: username_lower, active: true) + find_opts = {username_lower: username_lower} + find_opts[:active] = true unless opts[:include_inactive] + User.find_by(find_opts) elsif params[:external_id] SingleSignOnRecord.find_by(external_id: params[:external_id]).try(:user) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a7b8c361bbd..b7f1fc73276 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -312,7 +312,7 @@ class UsersController < ApplicationController end def send_activation_email - @user = fetch_user_from_params + @user = fetch_user_from_params(include_inactive: true) @email_token = @user.email_tokens.unconfirmed.active.first enqueue_activation_email if @user render nothing: true diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 1060338053d..cb3336597dd 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -961,11 +961,7 @@ describe UsersController do describe 'send_activation_email' do context 'for an existing user' do - let(:user) { Fabricate(:user) } - - before do - UsersController.any_instance.stubs(:fetch_user_from_params).returns(user) - end + let(:user) { Fabricate(:user, active: false) } context 'with a valid email_token' do it 'should send the activation email' do