From a393d3bcbb4e39d309d506d422e6823d829f6b5b Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 13 Dec 2017 14:21:56 +1100 Subject: [PATCH] FIX: ensure staged accounts are always inactive If for any reason active is stored in the user model, clear it out prior to creating an account --- app/controllers/users_controller.rb | 1 + spec/controllers/users_controller_spec.rb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c6999ed00bb..bede58eba15 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -321,6 +321,7 @@ class UsersController < ApplicationController if user = User.where(staged: true).with_email(params[:email].strip.downcase).first user_params.each { |k, v| user.send("#{k}=", v) } user.staged = false + user.active = false else user = User.new(user_params) end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index c63de160362..ca244ffca6e 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1035,7 +1035,7 @@ describe UsersController do end context "when taking over a staged account" do - let!(:staged) { Fabricate(:staged, email: "staged@account.com") } + let!(:staged) { Fabricate(:staged, email: "staged@account.com", active: true) } it "succeeds" do post :create, params: { @@ -1045,9 +1045,10 @@ describe UsersController do result = ::JSON.parse(response.body) expect(result["success"]).to eq(true) - active_user = User.find_by_email(staged.email) - expect(active_user.staged).to eq(false) - expect(active_user.registration_ip_address).to be_present + created_user = User.find_by_email(staged.email) + expect(created_user.staged).to eq(false) + expect(created_user.active).to eq(false) + expect(created_user.registration_ip_address).to be_present end end