mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-11-05 03:27:27 +01:00
added record.OriginalCopy() to return a record model copy with the original/initial data
This commit is contained in:
1 parent
d2028143df
commit
04018f931b
2 files changed
+43
No files matched your search
@@ -331,6 +331,33 @@ func TestRecordCollection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordOriginalCopy(t *testing.T) {
|
||||
m := models.NewRecord(&models.Collection{})
|
||||
m.Load(map[string]any{"f": "123"})
|
||||
|
||||
// change the field
|
||||
m.Set("f", "456")
|
||||
|
||||
if v := m.GetString("f"); v != "456" {
|
||||
t.Fatalf("Expected f to be %q, got %q", "456", v)
|
||||
}
|
||||
|
||||
if v := m.OriginalCopy().GetString("f"); v != "123" {
|
||||
t.Fatalf("Expected the initial/original f to be %q, got %q", "123", v)
|
||||
}
|
||||
|
||||
// Loading new data shouldn't affect the original state
|
||||
m.Load(map[string]any{"f": "789"})
|
||||
|
||||
if v := m.GetString("f"); v != "789" {
|
||||
t.Fatalf("Expected f to be %q, got %q", "789", v)
|
||||
}
|
||||
|
||||
if v := m.OriginalCopy().GetString("f"); v != "123" {
|
||||
t.Fatalf("Expected the initial/original f still to be %q, got %q", "123", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordExpand(t *testing.T) {
|
||||
collection := &models.Collection{}
|
||||
m := models.NewRecord(collection)
|
||||
|
||||
Reference in new issue
Block a user