FEATURE: can take over a staged account

This commit is contained in:
Régis Hanol 2015-11-13 19:07:28 +01:00
parent a682ec9444
commit 43614439e6
2 changed files with 17 additions and 1 deletions

View file

@ -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

View file

@ -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