FIX: when registering custom_field types, ensure we're casting them before checking for equality
This commit is contained in:
parent
55f449edc5
commit
629810bd07
|
@ -139,7 +139,6 @@ module HasCustomFields
|
|||
end
|
||||
|
||||
def custom_fields
|
||||
|
||||
if @preloaded_custom_fields
|
||||
return @preloaded_proxy ||= PreloadedProxy.new(@preloaded_custom_fields)
|
||||
end
|
||||
|
@ -177,7 +176,10 @@ module HasCustomFields
|
|||
dup.delete(f.name)
|
||||
end
|
||||
else
|
||||
if dup[f.name] != f.value
|
||||
t = {}
|
||||
self.class.append_custom_field(t, f.name, f.value)
|
||||
|
||||
if dup[f.name] != t[f.name]
|
||||
f.destroy
|
||||
else
|
||||
dup.delete(f.name)
|
||||
|
|
|
@ -142,6 +142,16 @@ describe HasCustomFields do
|
|||
test_item.reload
|
||||
|
||||
expect(test_item.custom_fields).to eq("bool" => true, "int" => 1, "json" => { "foo" => "bar" })
|
||||
|
||||
before_ids = CustomFieldsTestItemCustomField.where(custom_fields_test_item_id: test_item.id).pluck(:id)
|
||||
|
||||
test_item.custom_fields["bool"] = false
|
||||
test_item.save
|
||||
|
||||
after_ids = CustomFieldsTestItemCustomField.where(custom_fields_test_item_id: test_item.id).pluck(:id)
|
||||
|
||||
# we updated only 1 custom field, so there should be only 1 different id
|
||||
expect((before_ids - after_ids).size).to eq(1)
|
||||
end
|
||||
|
||||
it "simple modifications don't interfere" do
|
||||
|
|
Loading…
Reference in New Issue