FIX: upserting custom fields using keywords converts the array key to a string

This commit is contained in:
Jeff Wong 2019-10-29 11:34:28 -07:00
parent 356e2a4b4a
commit 74dc37c07c
2 changed files with 25 additions and 1 deletions

View File

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

View File

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