[Bps-public-commit] r16755 - in Prophet/branches/init-and-clone: . lib/Prophet/CLI/Command t

sartak at bestpractical.com sartak at bestpractical.com
Sat Nov 8 00:35:51 EST 2008


Author: sartak
Date: Sat Nov  8 00:35:51 2008
New Revision: 16755

Modified:
   Prophet/branches/init-and-clone/   (props changed)
   Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm
   Prophet/branches/init-and-clone/lib/Prophet/Replica/prophet.pm
   Prophet/branches/init-and-clone/t/init.t

Log:
 r75190 at onn:  sartak | 2008-11-08 00:35:40 -0500
 Make the API silently return success; the CLI notifies the user that there's already a Prophet database


Modified: Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm
==============================================================================
--- Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm	(original)
+++ Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm	Sat Nov  8 00:35:51 2008
@@ -5,10 +5,14 @@
 sub run {
     my $self = shift;
 
+    if ($self->app_handle->handle->replica_exists) {
+        print "Your Prophet database already exists.\n";
+        return;
+    }
+
     $self->app_handle->handle->after_initialize( sub { shift->app_handle->set_db_defaults } );
     $self->app_handle->handle->initialize;
-    $self->app_handle->log("Initialized");
-
+    print "Initialized your new Prophet database.\n";
 }
 
 

Modified: Prophet/branches/init-and-clone/lib/Prophet/Replica/prophet.pm
==============================================================================
--- Prophet/branches/init-and-clone/lib/Prophet/Replica/prophet.pm	(original)
+++ Prophet/branches/init-and-clone/lib/Prophet/Replica/prophet.pm	Sat Nov  8 00:35:51 2008
@@ -285,8 +285,7 @@
         }
     }
 
-    die "The replica is already initialized.\n"
-        if $self->replica_exists;
+    return if $self->replica_exists;
 
     dir( $self->fs_root, $_ )->mkpath
         for (

Modified: Prophet/branches/init-and-clone/t/init.t
==============================================================================
--- Prophet/branches/init-and-clone/t/init.t	(original)
+++ Prophet/branches/init-and-clone/t/init.t	Sat Nov  8 00:35:51 2008
@@ -1,24 +1,13 @@
 use warnings;
 use strict;
-use Test::More tests => 4;
-use Test::Exception;
+use Prophet::Test tests => 2;
 
-use File::Temp qw'tempdir';
-
-use_ok('Prophet::CLI');
-$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => 0 ) . '/repo-' . $$;
-my $cli = Prophet::CLI->new();
-my $cxn = $cli->handle;
-
-isa_ok( $cxn, 'Prophet::Replica', "Got the cxn" );
-
-lives_ok {
-    $cxn->initialize;
-} "initialize the connection";
-
-throws_ok {
-    $cxn->initialize;
-} qr/The replica is already initialized/, "attempting to reinitialize a replica throws an error";
+as_alice {
+    run_output_matches('prophet', [qw(init)],
+        [qr/Initialized your new Prophet database/]);
+    run_output_matches('prophet', [qw(init)],
+        [qr/Your Prophet database already exists/]);
+};
 
 1;
 



More information about the Bps-public-commit mailing list