FIX: Staged user creation loses user custom field data (#22206)

Don't cache user_fields on users separately from custom_fields, since they can get out of sync.

---------

Co-authored-by: Daniel Waterworth <me@danielwaterworth.com>
This commit is contained in:
Penar Musaraj
2023-06-21 13:35:24 -04:00
committed by GitHub
parent 114a9a10b7
commit 47ab7eb49a
2 changed files with 28 additions and 10 deletions

View File

@@ -1630,6 +1630,33 @@ RSpec.describe UsersController do
expect(created_user.email).to eq("staged@account.com")
expect(response.status).to eq(403)
end
it "works with custom fields" do
tennis_field = Fabricate(:user_field, show_on_profile: true, name: "Favorite tennis player")
post "/u.json",
params:
honeypot_magic(
email: staged.email,
username: "dude",
password: "P4ssw0rd$$",
user_fields: {
[tennis_field.id] => "Nadal",
},
)
expect(response.status).to eq(200)
result = response.parsed_body
expect(result["success"]).to eq(true)
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
expect(!!created_user.custom_fields["from_staged"]).to eq(true)
expect(created_user.custom_fields["user_field_#{tennis_field.id}"]).to eq("Nadal")
end
end
end