mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 19:53:53 -06:00
FIX: Nil-filled CF arrays were not being deleted (#13518)
This commit is contained in:
parent
8ab6fd88ef
commit
b4f0a0fb94
@ -233,10 +233,10 @@ module HasCustomFields
|
||||
t = {}
|
||||
self.class.append_custom_field(t, f.name, f.value)
|
||||
|
||||
if dup[f.name] != t[f.name]
|
||||
f.destroy!
|
||||
else
|
||||
if dup.has_key?(f.name) && dup[f.name] == t[f.name]
|
||||
dup.delete(f.name)
|
||||
else
|
||||
f.destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,6 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe HasCustomFields do
|
||||
|
||||
context "custom_fields" do
|
||||
before do
|
||||
DB.exec("create temporary table custom_fields_test_items(id SERIAL primary key)")
|
||||
@ -104,7 +103,6 @@ describe HasCustomFields do
|
||||
end
|
||||
|
||||
it "handles arrays properly" do
|
||||
|
||||
CustomFieldsTestItem.register_custom_field_type "array", [:integer]
|
||||
test_item = CustomFieldsTestItem.new
|
||||
test_item.custom_fields = { "array" => ["1"] }
|
||||
@ -136,6 +134,19 @@ describe HasCustomFields do
|
||||
expect(db_item.custom_fields).to eq({})
|
||||
end
|
||||
|
||||
it "deletes nil-filled arrays" do
|
||||
test_item = CustomFieldsTestItem.create!
|
||||
db_item = CustomFieldsTestItem.find(test_item.id)
|
||||
|
||||
db_item.custom_fields.update("a" => [nil, nil])
|
||||
db_item.save_custom_fields
|
||||
db_item.custom_fields.delete("a")
|
||||
expect(db_item.custom_fields).to eq({})
|
||||
|
||||
db_item.save_custom_fields
|
||||
expect(db_item.custom_fields).to eq({})
|
||||
end
|
||||
|
||||
it "casts integers in arrays properly without error" do
|
||||
test_item = CustomFieldsTestItem.new
|
||||
test_item.custom_fields = { "a" => ["b", 10, "d"] }
|
||||
|
Loading…
Reference in New Issue
Block a user