[Bps-public-commit] RT-Extension-MergeUsers branch, master, updated. 0.10-1-g9a7fa56

Ruslan Zakirov ruz at bestpractical.com
Thu Sep 5 07:46:07 EDT 2013


The branch, master has been updated
       via  9a7fa566f7a51141cfc7e8952c2f2e5a83d5980b (commit)
      from  2bdf5ac3d8a82bf458805a69efb7290b9fa8c21d (commit)

Summary of changes:
 lib/RT/Extension/MergeUsers.pm | 10 ---------
 xt/collection.t                | 48 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 10 deletions(-)
 create mode 100644 xt/collection.t

- Log -----------------------------------------------------------------
commit 9a7fa566f7a51141cfc7e8952c2f2e5a83d5980b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Sep 5 15:39:08 2013 +0400

    don't override _RecordCount
    
    This caused not merged users at the end of the collection
    to be skipped.
    
    _RecordCount is used in SB's Next to stop the iterator.
    If we change return value, but don't change storage then
    iterator stops earlier.

diff --git a/lib/RT/Extension/MergeUsers.pm b/lib/RT/Extension/MergeUsers.pm
index c280836..a456b8c 100644
--- a/lib/RT/Extension/MergeUsers.pm
+++ b/lib/RT/Extension/MergeUsers.pm
@@ -341,16 +341,6 @@ sub GotoFirstItem {
     $self->GotoItem(0);
 }
 
-sub _RecordCount {
-    my $self = shift;
-    return 0 unless defined $self->{'items'};
-
-    my %seen;
-    $seen{$_->id}++ for @{ $self->{'items'} };
-    return scalar keys %seen;
-}
-
-
 =head1 AUTHOR
 
 Alex Vandiver E<lt>alexmv at bestpractical.comE<gt>
diff --git a/xt/collection.t b/xt/collection.t
new file mode 100644
index 0000000..35e268c
--- /dev/null
+++ b/xt/collection.t
@@ -0,0 +1,48 @@
+use strict;
+use RT::Test
+    tests   => 'no_declare',
+    testing => 'RT::Extension::MergeUsers';
+
+my ($id, $message);
+
+# create N unique users  ($$ == our pid)
+my $primary_user = RT::User->new($RT::SystemUser);
+($id, $message) = $primary_user->Create( EmailAddress => "primary-$$\@example.com" );
+ok($id, "Created 'primary' user? $message");
+
+my $secondary_user = RT::User->new($RT::SystemUser);
+($id, $message) = $secondary_user->Create( EmailAddress => "secondary-$$\@example.com" );
+ok($id, "Created 'secondary' user? $message");
+
+my $tertiary_user = RT::User->new($RT::SystemUser);
+($id, $message) = $tertiary_user->Create( EmailAddress => "tertiary-$$\@example.com" );
+ok($id, "Created 'tertiary' user? $message");
+
+my $quaternary_user = RT::User->new($RT::SystemUser);
+($id, $message) = $quaternary_user->Create( EmailAddress => "quaternary-$$\@example.com" );
+ok($id, "Created 'quaternary' user? $message");
+
+my %seen;
+{
+    my $users = RT::Users->new(RT->SystemUser);
+    $users->LimitToEnabled;
+    while (my $user = $users->Next) {
+        $seen{$user->id}++;
+    }
+}
+
+# successfully merges users
+($id, $message) = $secondary_user->MergeInto($primary_user);
+ok($id, "Successfully merges users? $message");
+
+{
+    my $users = RT::Users->new(RT->SystemUser);
+    $users->LimitToEnabled;
+    while (my $user = $users->Next) {
+        $seen{$user->id}--;
+    }
+    ok( delete $seen{ $secondary_user->id }, "havn't seen merged user" );
+    ok( !scalar (grep $_, values %seen), "seen everybody else");
+}
+
+done_testing;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list