FIX: upserting custom fields using keywords converts the array key to a string
This commit is contained in:
parent
356e2a4b4a
commit
74dc37c07c
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue