[Bps-public-commit] r16627 - in Prophet/trunk: t

ruz at bestpractical.com ruz at bestpractical.com
Thu Oct 30 08:31:30 EDT 2008


Author: ruz
Date: Thu Oct 30 08:31:30 2008
New Revision: 16627

Modified:
   Prophet/trunk/lib/Prophet/Change.pm
   Prophet/trunk/lib/Prophet/ChangeSet.pm
   Prophet/trunk/t/publish-pull.t
   Prophet/trunk/t/real-conflicting-merge.t
   Prophet/trunk/t/simple-conflicting-merge.t
   Prophet/trunk/t/simple-push.t

Log:
* serialize changes in a changeset in array to preserve order

Modified: Prophet/trunk/lib/Prophet/Change.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Change.pm	(original)
+++ Prophet/trunk/lib/Prophet/Change.pm	Thu Oct 30 08:31:30 2008
@@ -133,10 +133,10 @@
     }
 
     return {
-        record_type    => $self->record_type,
+        record_uuid  => $self->record_uuid,
+        record_type  => $self->record_type,
         change_type  => $self->change_type,
-        prop_changes => $props
-
+        prop_changes => $props,
     };
 }
 

Modified: Prophet/trunk/lib/Prophet/ChangeSet.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/ChangeSet.pm	(original)
+++ Prophet/trunk/lib/Prophet/ChangeSet.pm	Thu Oct 30 08:31:30 2008
@@ -153,9 +153,7 @@
     my $self = shift;
     my $as_hash = { map { $_ => $self->$_() } @SERIALIZE_PROPS };
 
-    for my $change ( $self->changes ) {
-        $as_hash->{changes}->{ $change->record_uuid } = $change->as_hash;
-    }
+    $as_hash->{'changes'} = [ map $_->as_hash, $self->changes ];
 
     return $as_hash;
 }
@@ -178,8 +176,8 @@
     my $hashref = shift;
     my $self    = $class->new( { map { $_ => $hashref->{$_} } @SERIALIZE_PROPS } );
 
-    for my $change ( keys %{ $hashref->{changes} } ) {
-        $self->add_change( change => Prophet::Change->new_from_hashref( $change => $hashref->{changes}->{$change} ) );
+    for my $change ( @{ $hashref->{changes} } ) {
+        $self->add_change( change => Prophet::Change->new_from_hashref( $change->{'record_uuid'} => $change ) );
     }
     return $self;
 }

Modified: Prophet/trunk/t/publish-pull.t
==============================================================================
--- Prophet/trunk/t/publish-pull.t	(original)
+++ Prophet/trunk/t/publish-pull.t	Thu Oct 30 08:31:30 2008
@@ -104,9 +104,10 @@
 
     my $changeset = $args{changeset}->as_hash;
 
-    my $changes = {
-        $args{record_uuid} => {
+    my $changes = [
+        {
             change_type  => 'add_file',
+            record_uuid  => $args{record_uuid},
             record_type  => $args{record_type},
             prop_changes => {
                 status => {
@@ -127,7 +128,7 @@
                 },
             },
         },
-    };
+    ];
 
     if ($args{merge}) {
         my $change_type = $args{sequence_no} > 1
@@ -138,15 +139,16 @@
                                ? $args{sequence_no} - 1
                                : undef;
 
-        $changes->{ replica_uuid_for('alice') } = {
+        push @$changes, {
             change_type  => $change_type,
+            record_uuid  => replica_uuid_for('alice'),
             record_type  => '_merge_tickets',
             prop_changes => {
                 'last-changeset' => {
                     old_value => $prev_changeset_num,
                     new_value => $args{sequence_no},
                 }
-            }
+            },
         };
     }
 

Modified: Prophet/trunk/t/real-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/real-conflicting-merge.t	(original)
+++ Prophet/trunk/t/real-conflicting-merge.t	Thu Oct 30 08:31:30 2008
@@ -164,10 +164,11 @@
     my @hashes = map { $_->as_hash } @changesets;
     is_deeply(
         \@hashes,
-        [   {   changes => {
-                    $record_id => {
+        [   {   changes => [
+                    {
                         change_type  => 'update_file',
-                        record_type    => 'Bug',
+                        record_uuid  => $record_id,
+                        record_type  => 'Bug',
                         prop_changes => {
                             status => {
                                 old_value => 'stalled',
@@ -175,7 +176,7 @@
                             }
                         }
                     }
-                },
+                ],
                 creator              => undef,
                 created              => $changesets[0]->created,
                 is_nullification     => 1,
@@ -194,30 +195,27 @@
                 original_sequence_no => $ALICE_LAST_REV_CACHE,
                 source_uuid          => replica_uuid(),
                 original_source_uuid => as_alice { replica_uuid() },
-                changes              => {
-                    $record_id => {
-                        record_type    => 'Bug',
+                changes              => [
+                    {
+                        record_uuid  => $record_id,
+                        record_type  => 'Bug',
                         change_type  => 'update_file',
                         prop_changes => {
                             status => { old_value => 'new', new_value => 'open' }
-
-                            }
-
+                        },
                     },
-                    as_alice {
-                        replica_uuid();
-                    } => {
-                        record_type    => '_merge_tickets',
+                    {
+                        record_uuid  => as_alice{ replica_uuid() },
+                        record_type  => '_merge_tickets',
                         change_type  => 'update_file',
                         prop_changes => {
                             'last-changeset' => {
                                 old_value => $ALICE_LAST_REV_CACHE - 1,
                                 new_value => $ALICE_LAST_REV_CACHE
                             }
-                            }
-
+                        }
                     }
-                }
+                ],
             },
 
             {
@@ -229,18 +227,16 @@
                 original_sequence_no => replica_last_rev(),
                 source_uuid          => replica_uuid(),
                 original_source_uuid => replica_uuid(),
-                changes              => {
-                    $record_id => {
-                        record_type    => 'Bug',
+                changes              => [
+                    {
+                        record_uuid  => $record_id,
+                        record_type  => 'Bug',
                         change_type  => 'update_file',
                         prop_changes => {
                             status => { old_value => 'open', new_value => 'stalled' }
-
-                            }
-
+                        },
                     }
-                    }
-
+                ]
             }
         ],
         "Bob's final state is as we expect"

Modified: Prophet/trunk/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/simple-conflicting-merge.t	(original)
+++ Prophet/trunk/t/simple-conflicting-merge.t	Thu Oct 30 08:31:30 2008
@@ -125,14 +125,14 @@
             original_source_uuid => undef,
             sequence_no          => undef,
             source_uuid          => undef,
-            changes              => {
-                $record_id => {
+            changes              => [
+                {
                     change_type  => 'update_file',
-                    record_type    => 'Bug',
+                    record_uuid  => $record_id,
+                    record_type  => 'Bug',
                     prop_changes => { status => { old_value => 'stalled', new_value => 'new' } }
-                    }
-
-            }
+                }
+            ]
         }
     );
 
@@ -165,27 +165,28 @@
             sequence_no          => undef,
             original_sequence_no => as_alice { replica_last_rev() },
             original_source_uuid => replica_uuid_for('alice'),
-            changes              => {
-                $record_id => {
-                    record_type    => 'Bug',
+            changes              => [
+                {
+                    record_uuid  => $record_id,
+                    record_type  => 'Bug',
                     change_type  => 'update_file',
                     prop_changes => { status => { old_value => 'new', new_value => 'stalled' } }
                 },
-
-                replica_uuid_for('alice') => {
+                {
                     change_type  => 'update_file',
-                    record_type    => '_merge_tickets',
+                    record_uuid  => replica_uuid_for('alice'),
+                    record_type  => '_merge_tickets',
                     prop_changes => {
                         'last-changeset' => {
                             old_value => as_alice { replica_last_rev() - 1 },
                             new_value => as_alice { replica_last_rev() }
                         }
-                        }
-
                     }
 
                 }
 
+            ],
+
         },
         "yay. the last rev from alice synced right"
     );

Modified: Prophet/trunk/t/simple-push.t
==============================================================================
--- Prophet/trunk/t/simple-push.t	(original)
+++ Prophet/trunk/t/simple-push.t	Thu Oct 30 08:31:30 2008
@@ -72,8 +72,8 @@
             'original_source_uuid' => replica_uuid_for('bob'),
             'is_resolution'        => undef,
             'source_uuid'          => replica_uuid_for('bob'),
-            'changes'              => {
-                $openbug => {
+            'changes'              => [
+                {
                     'change_type'  => 'add_file',
                     'prop_changes' => {
                         'from' => {
@@ -93,9 +93,10 @@
                             'old_value' => undef
                         },
                     },
+                    'record_uuid' => $openbug,
                     'record_type' => 'Bug'
                 }
-            },
+            ],
             'is_nullification' => undef,
         }
     ]
@@ -147,8 +148,8 @@
             'original_source_uuid' => replica_uuid_for('bob'),
             'is_resolution'        => undef,
             'source_uuid'          => replica_uuid_for('bob'),
-            'changes'              => {
-                $last_id => {
+            'changes'              => [
+                {
                     'change_type'  => 'add_file',
                     'prop_changes' => {
                         'from' => {
@@ -168,9 +169,10 @@
                             'old_value' => undef,
                         },
                     },
-                    'record_type' => 'Bug'
+                    'record_uuid' => $last_id,
+                    'record_type' => 'Bug',
                 }
-            },
+            ],
             'is_nullification' => undef,
         }
     ]



More information about the Bps-public-commit mailing list