A platform for community discussion. Free, open, simple.
FIX: upserting custom fields using keywords converts the array key to a string
Jeff Wong74dc37c07cb5
diff --git a/app/models/concerns/has_custom_fields.rb b/app/models/concerns/has_custom_fields.rbindex a98aad45b3f..923efe846db 100644--- a/app/models/concerns/has_custom_fields.rb+++ b/app/models/concerns/has_custom_fields.rb@@ -193,7 +193,7 @@ module HasCustomFieldsif row_count == 0_custom_fields.create!(name: k, value: v)end- custom_fields[k] = v+ custom_fields[k.to_s] = v # We normalize custom_fields as stringsendenddiff --git a/spec/components/concern/has_custom_fields_spec.rb b/spec/components/concern/has_custom_fields_spec.rbindex 5696f113f12..24ecefaca54 100644--- a/spec/components/concern/has_custom_fields_spec.rb+++ b/spec/components/concern/has_custom_fields_spec.rb@@ -313,6 +313,30 @@ describe HasCustomFields doexpect(test_item.custom_fields['hello']).to eq('world')expect(test_item.custom_fields['abc']).to eq('ghi')end++ it 'allows upsert to use keywords' do+ test_item = CustomFieldsTestItem.create+ test_item.upsert_custom_fields(hello: 'world', abc: 'def')++ # In memory+ expect(test_item.custom_fields['hello']).to eq('world')+ expect(test_item.custom_fields['abc']).to eq('def')++ # Persisted+ test_item.reload+ expect(test_item.custom_fields['hello']).to eq('world')+ expect(test_item.custom_fields['abc']).to eq('def')++ # In memory+ test_item.upsert_custom_fields('abc' => 'ghi')+ expect(test_item.custom_fields['hello']).to eq('world')+ expect(test_item.custom_fields['abc']).to eq('ghi')++ # Persisted+ test_item.reload+ expect(test_item.custom_fields['hello']).to eq('world')+ expect(test_item.custom_fields['abc']).to eq('ghi')+ endendendend