From 43614439e69a61fa894be51f9334a1fa3c91cf42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 13 Nov 2015 19:07:28 +0100 Subject: [PATCH] FEATURE: can take over a staged account --- app/controllers/users_controller.rb | 7 ++++++- spec/controllers/users_controller_spec.rb | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3cc1ee3bc..de7722fe5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -259,7 +259,12 @@ class UsersController < ApplicationController return fail_with("login.reserved_username") end - user = User.new(user_params) + if user = User.where(staged: true).find_by(email: params[:email].strip.downcase) + user_params.each { |k, v| user.send("#{k}=", v) } + user.staged = false + else + user = User.new(user_params) + end # Handle custom fields user_fields = UserField.all diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index e9423b826..741a023d4 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -746,6 +746,17 @@ describe UsersController do end end + context "when taking over a staged account" do + let!(:staged) { Fabricate(:staged, email: "staged@account.com") } + + it "succeeds" do + xhr :post, :create, email: staged.email, username: "zogstrip", password: "P4ssw0rd" + result = ::JSON.parse(response.body) + expect(result["success"]).to eq(true) + expect(User.find_by(email: staged.email).staged).to eq(false) + end + end + end context '.username' do