FIX: allow single string values on custom multiple select fields and not just arrays (#14236)

This commit is contained in:
Jean 2021-09-03 09:26:57 -04:00 committed by GitHub
parent 763f48abc7
commit 85c31c73ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -1607,6 +1607,7 @@ class UsersController < ApplicationController
if field.field_type == "dropdown"
field.user_field_options.find_by_value(field_values)&.value
elsif field.field_type == "multiselect"
field_values = Array.wrap(field_values)
bad_values = field_values - field.user_field_options.map(&:value)
field_values - bad_values
else

View File

@ -1279,6 +1279,16 @@ describe UsersController do
end
end
it "should allow single values and not just arrays" do
expect do
put update_user_url, params: { user_fields: { field_id => 'Axe' } }
end.to change { user.reload.user_fields[field_id] }.from(nil).to('Axe')
expect do
put update_user_url, params: { user_fields: { field_id => %w[Axe Juice Sword] } }
end.to change { user.reload.user_fields[field_id] }.from('Axe').to(%w[Axe Sword])
end
it "shouldn't allow unregistered field values" do
expect do
put update_user_url, params: { user_fields: { field_id => %w[Juice] } }