mirror of
https://github.com/discourse/discourse.git
synced 2025-04-11 16:02:25 +08:00
fix double save missing error by using copy not actual reference
This commit is contained in:
parent
2450088c03
commit
48f016c7f5
@ -14,6 +14,10 @@ module Concern
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def custom_fields=(data)
|
||||||
|
custom_fields.replace(data)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def save_custom_fields
|
def save_custom_fields
|
||||||
@ -24,7 +28,7 @@ module Concern
|
|||||||
if dup[f.name] != f.value
|
if dup[f.name] != f.value
|
||||||
f.destroy
|
f.destroy
|
||||||
else
|
else
|
||||||
dup.remove[f.name]
|
dup.delete(f.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,7 +36,7 @@ module Concern
|
|||||||
_custom_fields.create(name: k, value: v)
|
_custom_fields.create(name: k, value: v)
|
||||||
end
|
end
|
||||||
|
|
||||||
@custom_fields_orig = @custom_fields
|
@custom_fields_orig = dup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -51,6 +51,20 @@ describe Concern::HasCustomFields do
|
|||||||
test_item.custom_fields.should == {"jack" => "jill"}
|
test_item.custom_fields.should == {"jack" => "jill"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "double save actually saves" do
|
||||||
|
|
||||||
|
test_item = TestItem.new
|
||||||
|
test_item.custom_fields = {"a" => "b"}
|
||||||
|
test_item.save
|
||||||
|
|
||||||
|
test_item.custom_fields["c"] = "d"
|
||||||
|
test_item.save
|
||||||
|
|
||||||
|
db_item = TestItem.find(test_item.id)
|
||||||
|
db_item.custom_fields.should == {"a" => "b", "c" => "d"}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
it "simple modifications don't interfere" do
|
it "simple modifications don't interfere" do
|
||||||
test_item = TestItem.new
|
test_item = TestItem.new
|
||||||
|
Loading…
x
Reference in New Issue
Block a user