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:
Greg Kempe
2015-01-27 11:48:27 +02:00
parent fbd18f3b69
commit d99ccf6d27
2 changed files with 33 additions and 12 deletions

View File

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