mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-28 23:14:04 -04:00
FIX: 🐛 Saving the same custom field array twice would raise an error
This commit is contained in:
parent
3ab2f105b4
commit
505fa9f1cf
2 changed files with 9 additions and 1 deletions
|
@ -117,7 +117,7 @@ module HasCustomFields
|
||||||
array_fields.each do |field_name, fields|
|
array_fields.each do |field_name, fields|
|
||||||
if fields.length == dup[field_name].length &&
|
if fields.length == dup[field_name].length &&
|
||||||
fields.map{|f| f.value} == dup[field_name]
|
fields.map{|f| f.value} == dup[field_name]
|
||||||
dup.delete(f.name)
|
dup.delete(field_name)
|
||||||
else
|
else
|
||||||
fields.each{|f| f.destroy }
|
fields.each{|f| f.destroy }
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,6 +115,14 @@ describe HasCustomFields do
|
||||||
db_item.save
|
db_item.save
|
||||||
expect(db_item.custom_fields).to eq({"a" => ["c", "d"]})
|
expect(db_item.custom_fields).to eq({"a" => ["c", "d"]})
|
||||||
|
|
||||||
|
# It can be updated to the exact same value
|
||||||
|
db_item.custom_fields.update('a' => ['c'])
|
||||||
|
db_item.save
|
||||||
|
expect(db_item.custom_fields).to eq({"a" => "c"})
|
||||||
|
db_item.custom_fields.update('a' => ['c'])
|
||||||
|
db_item.save
|
||||||
|
expect(db_item.custom_fields).to eq({"a" => "c"})
|
||||||
|
|
||||||
db_item.custom_fields.delete('a')
|
db_item.custom_fields.delete('a')
|
||||||
expect(db_item.custom_fields).to eq({})
|
expect(db_item.custom_fields).to eq({})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue