Index: openacs-4/packages/xotcl-core/tcl/test/xotcl-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/test/Attic/xotcl-test-procs.tcl,v diff -u -N -r1.1.2.5 -r1.1.2.6 --- openacs-4/packages/xotcl-core/tcl/test/xotcl-test-procs.tcl 15 Apr 2019 12:04:53 -0000 1.1.2.5 +++ openacs-4/packages/xotcl-core/tcl/test/xotcl-test-procs.tcl 17 Apr 2019 12:22:54 -0000 1.1.2.6 @@ -7,6 +7,9 @@ Test basic ::xo::db::Object ORM features } { aa_run_with_teardown -test_code { + + + aa_section "Object creation" aa_log "Create object" set orm_object [::xo::db::Object new] $orm_object set title "test_title" @@ -21,6 +24,8 @@ }] aa_true "Object was created" {$orm_exists_p && $db_exists_p} + + aa_section "Object fetching" aa_log "Fetching object from ORM" set orm_object [::xo::db::Class get_instance_from_db -id $object_id] aa_log "Fetching object from DB" @@ -51,9 +56,11 @@ aa_equals "Same $att" [set $att] [$orm_object set $att] } + + aa_section "Object manipulation" aa_log "Setting a different title" - set old_title [$orm_object set object_title] - $orm_object set object_title "a different title" + set new_title "a different title" + $orm_object set object_title $new_title set old_context_id [$orm_object set context_id] # obtain a random different context_id @@ -67,7 +74,19 @@ aa_log "Saving the object" $orm_object save - aa_log "Fetching object again from DB" + + set attributes { + object_title + creation_date + creation_user + creation_ip + package_id + context_id + modifying_user + modifying_ip + last_modified + } + aa_log "Fetching object attributes from DB" ::xo::dc 1row get_object_from_db { select title as object_title, creation_date, @@ -82,38 +101,30 @@ where object_id = :object_id } - # Before re-fetching the object from db, some properties will - # not be updated in the object. We expose this behavior, which - # is somehow suboptimal. - foreach att { - modifying_user - last_modified - } { - aa_true "Attribute $att didn't change before re-fetching" {[set $att] ne [$orm_object set $att]} + + aa_section "Check modifications BEFORE refetching" + aa_equals "title was updated" [$orm_object set object_title] $new_title + aa_equals "context_id was updated" [$orm_object set context_id] $new_context_id + foreach att $attributes { + if {![aa_equals "Attribute $att in the object matches database value" [set $att] [$orm_object set $att]]} { + aa_log "DB: [set $att]| ORM: [$orm_object set $att]" + } } + + aa_section "Check modifications AFTER refetching" aa_log "Fetching object again from ORM" set orm_object [::xo::db::Class get_instance_from_db -id $object_id] - - # Title would not be updated. This is suboptimal and we expose it - aa_equals "Title did not change" [$orm_object set object_title] $old_title - - aa_equals "context_id changed" [$orm_object set context_id] $new_context_id - - foreach att { - object_title - creation_date - creation_user - creation_ip - package_id - context_id - modifying_user - modifying_ip - last_modified - } { - aa_equals "Same $att after modifying the title" [set $att] [$orm_object set $att] + aa_equals "title was updated" [$orm_object set object_title] $new_title + aa_equals "context_id was updated" [$orm_object set context_id] $new_context_id + foreach att $attributes { + if {![aa_equals "Attribute $att in the object matches database value" [set $att] [$orm_object set $att]]} { + aa_log "DB: [set $att]| ORM: [$orm_object set $att]" + } } + + aa_section "Object deletion" $orm_object delete set orm_exists_p [::xo::db::Class exists_in_db -id $object_id] set db_exists_p [::xo::dc 0or1row lookup_object {