Accounted for the change while reading the fields added specs to confirm working
This commit is contained in:
parent
352ad826c1
commit
c363189858
|
@ -274,7 +274,7 @@ module HasCustomFields
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def refresh_custom_fields_from_db
|
def refresh_custom_fields_from_db
|
||||||
target = Hash.new
|
target = HashWithIndifferentAccess.new
|
||||||
_custom_fields.order('id asc').pluck(:name, :value).each do |key, value|
|
_custom_fields.order('id asc').pluck(:name, :value).each do |key, value|
|
||||||
self.class.append_custom_field(target, key, value)
|
self.class.append_custom_field(target, key, value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -337,6 +337,32 @@ describe HasCustomFields do
|
||||||
expect(test_item.custom_fields['hello']).to eq('world')
|
expect(test_item.custom_fields['hello']).to eq('world')
|
||||||
expect(test_item.custom_fields['abc']).to eq('ghi')
|
expect(test_item.custom_fields['abc']).to eq('ghi')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows using string and symbol indices interchangably' do
|
||||||
|
test_item = CustomFieldsTestItem.new
|
||||||
|
|
||||||
|
test_item.custom_fields["bob"] = "marley"
|
||||||
|
test_item.custom_fields["jack"] = "black"
|
||||||
|
|
||||||
|
# In memory
|
||||||
|
expect(test_item.custom_fields[:bob]).to eq('marley')
|
||||||
|
expect(test_item.custom_fields[:jack]).to eq('black')
|
||||||
|
|
||||||
|
# Persisted
|
||||||
|
test_item.save
|
||||||
|
test_item.reload
|
||||||
|
expect(test_item.custom_fields[:bob]).to eq('marley')
|
||||||
|
expect(test_item.custom_fields[:jack]).to eq('black')
|
||||||
|
|
||||||
|
## Update via string index again
|
||||||
|
test_item.custom_fields['bob'] = 'the builder'
|
||||||
|
|
||||||
|
expect(test_item.custom_fields[:bob]).to eq('the builder')
|
||||||
|
test_item.save
|
||||||
|
test_item.reload
|
||||||
|
|
||||||
|
expect(test_item.custom_fields[:bob]).to eq('the builder')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue