diff --git a/app/models/concerns/has_custom_fields.rb b/app/models/concerns/has_custom_fields.rb index a98aad45b3f..923efe846db 100644 --- a/app/models/concerns/has_custom_fields.rb +++ b/app/models/concerns/has_custom_fields.rb @@ -193,7 +193,7 @@ module HasCustomFields if 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 strings end end diff --git a/spec/components/concern/has_custom_fields_spec.rb b/spec/components/concern/has_custom_fields_spec.rb index 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 do expect(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') + end end end end