mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 09:08:10 +08:00
Add Support for Arrays to CustomFields
This commit is contained in:
@ -35,6 +35,7 @@ describe Concern::HasCustomFields do
|
||||
|
||||
test_item.custom_fields["bob"] = "marley"
|
||||
test_item.custom_fields["jack"] = "black"
|
||||
|
||||
test_item.save
|
||||
|
||||
test_item = TestItem.find(test_item.id)
|
||||
@ -51,6 +52,21 @@ describe Concern::HasCustomFields do
|
||||
test_item.custom_fields.should == {"jack" => "jill"}
|
||||
end
|
||||
|
||||
it "casts integers to string without error" do
|
||||
test_item = TestItem.new
|
||||
test_item.custom_fields["a"].should == nil
|
||||
test_item.custom_fields["a"] = 0
|
||||
|
||||
test_item.custom_fields["a"].should == 0
|
||||
test_item.save
|
||||
|
||||
# should be casted right after saving
|
||||
test_item.custom_fields["a"].should == "0"
|
||||
|
||||
test_item = TestItem.find(test_item.id)
|
||||
test_item.custom_fields["a"].should == "0"
|
||||
end
|
||||
|
||||
it "double save actually saves" do
|
||||
|
||||
test_item = TestItem.new
|
||||
@ -66,6 +82,33 @@ describe Concern::HasCustomFields do
|
||||
end
|
||||
|
||||
|
||||
it "handles arrays properly" do
|
||||
|
||||
test_item = TestItem.new
|
||||
test_item.custom_fields = {"a" => ["b", "c", "d"]}
|
||||
test_item.save
|
||||
|
||||
db_item = TestItem.find(test_item.id)
|
||||
db_item.custom_fields.should == {"a" => ["b", "c", "d"]}
|
||||
|
||||
db_item.custom_fields["a"] = ["c", "d"]
|
||||
db_item.save
|
||||
db_item.custom_fields.should == {"a" => ["c", "d"]}
|
||||
|
||||
end
|
||||
|
||||
it "casts integers in arrays properly without error" do
|
||||
|
||||
test_item = TestItem.new
|
||||
test_item.custom_fields = {"a" => ["b", 10, "d"]}
|
||||
test_item.save
|
||||
test_item.custom_fields.should == {"a" => ["b", "10", "d"]}
|
||||
|
||||
db_item = TestItem.find(test_item.id)
|
||||
db_item.custom_fields.should == {"a" => ["b", "10", "d"]}
|
||||
|
||||
end
|
||||
|
||||
it "simple modifications don't interfere" do
|
||||
test_item = TestItem.new
|
||||
|
||||
|
Reference in New Issue
Block a user