mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: creating a user shouldn't error when optional fields aren't provided
This fixes a bug where the server would 500 if the only user fields where optional ones, and the create_user call didn't provide any values so that params[:user_fields] was nil. Additionally, don't bother double-checked for required fields, since we iterate over all fields and will catch any that are required and blank.
This commit is contained in:
@@ -604,6 +604,28 @@ describe UsersController do
|
||||
end
|
||||
end
|
||||
|
||||
context "with only optional custom fields" do
|
||||
let!(:user_field) { Fabricate(:user_field, required: false) }
|
||||
|
||||
context "without values for the fields" do
|
||||
let(:create_params) { {
|
||||
name: @user.name,
|
||||
password: 'watwatwat',
|
||||
username: @user.username,
|
||||
email: @user.email,
|
||||
} }
|
||||
|
||||
it "should succeed" do
|
||||
xhr :post, :create, create_params
|
||||
expect(response).to be_success
|
||||
inserted = User.where(email: @user.email).first
|
||||
expect(inserted).to be_present
|
||||
expect(inserted.custom_fields).not_to be_present
|
||||
expect(inserted.custom_fields["user_field_#{user_field.id}"]).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '.username' do
|
||||
|
||||
Reference in New Issue
Block a user