[siesta-commit] siesta/t 07list.t,1.22,1.23 07user.t,1.10,1.11 08config.t,1.14,1.15 09plugin_order.t,1.2,1.3 10plugin_listheaders.t,1.1,1.2 10plugin_simplesig.t,1.6,1.7 10plugin_subjecttag.t,1.3,1.4 10plugin_subscribe.t,1.9,1.10 10plugin_unsubscribe.t,1.2,1.3

[prev] [thread] [next] [lurker] [Date index for 2003/03/15]

From: clampr
Subject: [siesta-commit] siesta/t 07list.t,1.22,1.23 07user.t,1.10,1.11 08config.t,1.14,1.15 09plugin_order.t,1.2,1.3 10plugin_listheaders.t,1.1,1.2 10plugin_simplesig.t,1.6,1.7 10plugin_subjecttag.t,1.3,1.4 10plugin_subscribe.t,1.9,1.10 10plugin_unsubscribe.t,1.2,1.3
Date: 20:16 on 15 Mar 2003
Update of /cvsroot/siesta/siesta/t
In directory sc8-pr-cvs1:/tmp/cvs-serv10805/t

Modified Files:
	07list.t 07user.t 08config.t 09plugin_order.t 
	10plugin_listheaders.t 10plugin_simplesig.t 
	10plugin_subjecttag.t 10plugin_subscribe.t 
	10plugin_unsubscribe.t 
Log Message:
A metric ton of changes.

* All tables now have abstract id columns, so a users email address 
  is now $user->email and a lists name is $list->name

* Storage methods take ids, not objects

* User/List methods try to be a bit less magical/vaired about 
  what they take as parameters

Since modules and tests have been changed at the same time I expect 
there to be many bugs, but those'll be squished RSN


Index: 07list.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/07list.t,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- 07list.t	12 Sep 2002 14:14:51 -0000	1.22
+++ 07list.t	15 Mar 2003 20:15:52 -0000	1.23
@@ -10,9 +10,9 @@
 
 my $list = Siesta::List->new('dealers');
 isa_ok( $list, "Siesta::List", );
-ok( $list,     "list created" );
+ok( $list, "list created" );
 
-is( $list->id,           "dealers" );
+is( $list->name,         "dealers" );
 is( $list->owner,        'jay@xxxxxxxx.xxxxxxxxxx' );
 is( $list->post_address, 'dealers@xxxxxxxx.xxxxxxxxxx' );
 is( $list->return_path,  'dealers-bounce@xxxxxxxx.xxxxxxxxxx' );
@@ -21,25 +21,25 @@
 ok( !( $list->is_member('dante@quick-stop') ),   "dante isn't on this list" );
 
 my $user1 =
-  Test::MockObject->new->mock( id => sub { 'jay@xxxxxxxx.xxxxxxxxxx' } );
-ok( $list->is_member($user1), "jay member (object)" );
+  Test::MockObject->new->mock( id => sub { 1 } );
+ok( $list->is_member($user1), "user id 1 member (object)" );
 my $user2 = Test::MockObject->new->mock( id => sub { 'brodie@comic-store' } );
 ok( !( $list->is_member($user2) ), 'brodie (object)' );
 
-is( scalar( $list->members() ), 2, "only two members" );
+is( scalar( $list->members ), 2, "only two members" );
 my $flag = 1;
-foreach my $member ( $list->members() ) {
+foreach my $member ( $list->members ) {
     $flag = $flag && $list->is_member($member);
 }
 ok( $flag, "->is_member agrees with ->members" );
 
 # removal
-my $old_cnt = scalar( $list->members() );
+my $old_cnt = scalar( $list->members );
 ok( $list->is_member('bob@xxxxxxxx.xxxxxxxxxx'), "unsub - bob is a member" );
 ok( $list->remove_member('bob@xxxxxxxx.xxxxxxxxxx'), "remove successful" );
-ok( !$list->remove_member('dante@quick-stop'),   "remove of non-member" );
+ok( !$list->remove_member('dante@quick-stop'), "remove of non-member" );
 ok( !$list->remove_member('brodie@comic-store'), "remove of a system nobody" );
-is( scalar( $list->members() ), $old_cnt - 1, "members count went down" );
+is( scalar( $list->members ), $old_cnt - 1, "members count went down" );
 ok( !( $list->is_member('bob@xxxxxxxx.xxxxxxxxxx') ),
     "bob no longer a member" );
 ok( $list->is_member('jay@xxxxxxxx.xxxxxxxxxx'), "jay still is" );
@@ -51,10 +51,10 @@
 ok( $list->is_member('bob@xxxxxxxx.xxxxxxxxxx') );
 
 # test instantiating from hash
-my $test_list = Siesta::List->new_from_hash( id    => 'testing',
+my $test_list = Siesta::List->new_from_hash( name  => 'testing',
                                              owner => 'test@xxxxxxx.xxx', );
 
-ok( $test_list,     "list created from hash" );
+ok( $test_list, "list created from hash" );
 isa_ok( $test_list, "Siesta::List" );
 
 # save that
@@ -63,10 +63,10 @@
 $test_list = undef;
 
 # now reload it
-$test_list = Siesta::List->new('testing');
-ok( $test_list,     "list reloaded" );
+$test_list = Siesta::List->new( 'testing');
+ok( $test_list, "list reloaded" );
 isa_ok( $test_list, "Siesta::List" );
-is( $test_list->owner(), 'test@xxxxxxx.xxx', "correct data" );
+is( $test_list->owner, 'test@xxxxxxx.xxx', "correct data" );
 
 # now delete it
 ok( Siesta->storage->delete_list($test_list) );
@@ -74,7 +74,7 @@
 is( $test_list, undef );
 
 # now try all those again with class methods
-my $again = Siesta::List->new_from_hash( id    => 'testing',
+my $again = Siesta::List->new_from_hash( name  => 'testing',
                                          owner => 'test@xxxxxxx.xxx', );
 
 ok($again);
@@ -82,26 +82,26 @@
 ok( $again->save );
 $again = undef;
 $again = Siesta::List->new('testing');
-is( $again->owner(), 'test@xxxxxxx.xxx' );
-ok( $again->delete() );
+is( $again->owner, 'test@xxxxxxx.xxx' );
+ok( $again->delete );
 $test_list = Siesta::List->new('testing');
 is( $test_list, undef );
 
 # make sure that we insert when there's nothing there
 # before and update when there is
-my $us = Siesta::List->new_from_hash( id => 'caitlin' );
-ok( $us->save(), "saved 'caitlin'" );
+my $us = Siesta::List->new_from_hash( name => 'caitlin' );
+ok( $us->save, "saved 'caitlin'" );
 $flag = 0;
-foreach my $list ( Siesta->storage->get_lists() ) {
-    $flag++ if ( $list->id() eq 'caitlin' );
+foreach my $list ( Siesta->storage->get_lists ) {
+    $flag++ if $list->name eq 'caitlin';
 }
 is( $flag, 1, "inserted" );
 ok( $us->owner('test') );
-ok( $us->save() );
+ok( $us->save );
 $flag = 0;
-foreach my $list ( Siesta->storage->get_lists() ) {
-    $flag++ if ( $list->id() eq 'caitlin' );
+foreach my $list ( Siesta->storage->get_lists ) {
+    $flag++ if $list->name eq 'caitlin';
 }
 
 is( $flag, 1, "updated" );
-is( $us->owner(), 'test' );
+is( $us->owner, 'test' );

Index: 07user.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/07user.t,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- 07user.t	15 Oct 2002 10:57:04 -0000	1.10
+++ 07user.t	15 Mar 2003 20:15:53 -0000	1.11
@@ -1,49 +1,48 @@
 #!perl -w
 use strict;
-use Test::More tests => 23;
+use Test::More tests => 24;
 use Test::MockObject;
 use Siesta;
 use Siesta::User;
 
 Siesta->connect( DBI => "dbi:SQLite:t/test.db" );
 
-my $user = Siesta::User->new('jay@xxxxxxxx.xxxxxxxxxx');
-ok( $user,     "user created" );
+my $user = Siesta::User->new_from_email('jay@xxxxxxxx.xxxxxxxxxx');
+ok( $user, "user created" );
 isa_ok( $user, "Siesta::User", );
 
-is_deeply( [ map { $_->id } $user->lists ], ['dealers'], 'lists' );
+is_deeply( [ map { $_->name } $user->lists ], ['dealers'], 'lists' );
 
 # test new from hash
 my $other = Siesta::User->new_from_hash(
-                                         id       => 'bluntman@xxxxxxx.xxx',
+                                         email    => 'bluntman@xxxxxxx.xxx',
                                          forename => 'bluntman',
                                          surname  => 'chronic'
                                          );
-ok( $other,     "user created from hash" );
+ok( $other, "user created from hash" );
 isa_ok( $other, "Siesta::User" );
 
 # save that
-ok( Siesta->storage->save_user($other) );
+ok( $other->save );
+ok( $other->id, "saving allocated an id" );
 
 $other = undef;
 
 # we now reload that user
-$other = Siesta::User->new('bluntman@xxxxxxx.xxx');
-ok( $other,     "user reloaded" );
+$other = Siesta::User->new_from_email('bluntman@xxxxxxx.xxx');
+ok( $other, "user reloaded" );
 isa_ok( $other, "Siesta::User" );
-is( $other->forename(), 'bluntman', "correct data" );
+is( $other->forename, 'bluntman', "correct data" );
 
 # now delete it
 ok( Siesta->storage->delete_user($other) );
 
-$other = Siesta::User->new('bluntman@xxxxxxx.xxx');
-
 # now reload it
-is( $other, undef );
+is( Siesta::User->new_from_email('bluntman@xxxxxxx.xxx'), undef );
 
 # now try all these as User class methods
 my $again = Siesta::User->new_from_hash(
-                                         id       => 'chronic@xxxxxxx.xxx',
+                                         email    => 'chronic@xxxxxxx.xxx',
                                          forename => 'charles',
                                          surname  => 'hronic'
                                          );
@@ -51,30 +50,30 @@
 isa_ok( $again, 'Siesta::User' );
 ok( $again->save );
 $again = undef;
-$again = Siesta::User->new('chronic@xxxxxxx.xxx');
-is( $again->forename(), 'charles' );
-ok( $again->delete() );
+$again = Siesta::User->new_from_email('chronic@xxxxxxx.xxx');
+is( $again->forename, 'charles' );
+ok( $again->delete );
 $again = Siesta::User->new('charles@xxxxxxx.xxx');
 is( $again, undef );
 
-# make sure that we insert when there's nothing there 
+# make sure that we insert when there's nothing there
 # before and update when there is
-my $us = Siesta::User->new_from_hash( id => 'test@test' );
-ok( $us->save(), "saved 'test\@test'" );
+my $us = Siesta::User->new_from_hash( email => 'test@test' );
+ok( $us->save, "saved 'test\@test'" );
 my $flag = 0;
-foreach my $user ( Siesta->storage->get_users() ) {
-    $flag++ if ( $user->id() eq 'test@test' );
+foreach my $user ( Siesta->storage->get_users ) {
+    $flag++ if ( $user->email eq 'test@test' );
 }
 is( $flag, 1, "inserted" );
 ok( $us->forename('test') );
-ok( $us->save() );
+ok( $us->save );
 $flag = 0;
-foreach my $user ( Siesta->storage->get_users() ) {
-    $flag++ if ( $user->id() eq 'test@test' );
+foreach my $user ( Siesta->storage->get_users ) {
+    $flag++ if ( $user->email eq 'test@test' );
 }
 
 is( $flag, 1, "updated" );
-is( $us->forename(), 'test' );
+is( $us->forename, 'test' );
 
 # option
 # config

Index: 08config.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/08config.t,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- 08config.t	17 Oct 2002 12:57:30 -0000	1.14
+++ 08config.t	15 Mar 2003 20:15:54 -0000	1.15
@@ -142,7 +142,7 @@
 # fall through
 ##############
 
-# check to see that a config check will fall through 
+# check to see that a config check will fall through
 # like this ...
 #
 #         per user, per list

Index: 09plugin_order.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/09plugin_order.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- 09plugin_order.t	12 Sep 2002 12:55:32 -0000	1.2
+++ 09plugin_order.t	15 Mar 2003 20:15:54 -0000	1.3
@@ -9,8 +9,8 @@
 Siesta->connect( DBI => "dbi:SQLite:t/test.db" );
 
 # create a new, virgin list
-my $list = Siesta::List->new_from_hash( id      => 'pluginorder',
-                                        'owner' => 'foo', );
+my $list = Siesta::List->new_from_hash( name  => 'pluginorder',
+                                        owner => 'foo', );
 
 $list->save();
 
@@ -19,78 +19,55 @@
 ##
 
 # the list of plugins should be empty
-is( Siesta->storage->list_plugins($list), 0, "empty list" );
+is( Siesta->storage->list_plugins($list->id), 0, "empty list" );
 
 my @plugins = qw(Bounce ReplyTo);
 
 # set the list of plugins
-ok( Siesta->storage->set_plugins( $list, @plugins ) );
-
-my @new = Siesta->storage->list_plugins( $list->id() );
-
-my $flag = 1;
-foreach my $p (@new) {
-    $flag &&= ( $p eq shift @plugins );
-}
-
-is( $flag, 1, "set the plugins" );
+ok( Siesta->storage->set_plugins( $list->id, @plugins ) );
 
-# add one at the end 
-ok( Siesta->storage->add_plugin_to_list( $list, 'Send' ) );
+is_deeply( [ Siesta->storage->list_plugins( $list->id ) ], \@plugins, "set the plugins");
 
-@plugins = Siesta->storage->list_plugins( $list->id() );
+# add one at the end
+ok( Siesta->storage->add_plugin_to_list( $list->id, 'Send' ) );
 
-my $last = pop @plugins;
-is( $last, 'Send', "Add on the end" );
+@plugins = Siesta->storage->list_plugins( $list->id );
+is( $plugins[-1], 'Send', "Add on the end" );
 
 # add at the start
-ok( Siesta->storage->add_plugin_to_list( $list, 'First', 1 ) );
+ok( Siesta->storage->add_plugin_to_list( $list->id, 'First', 1 ) );
 
-@plugins = Siesta->storage->list_plugins( $list->id() );
-my $first = shift @plugins;
-is( $first, 'First', "Add at the start" );
+@plugins = Siesta->storage->list_plugins( $list->id );
+is( $plugins[0], 'First', "Add at the start" );
 
 # now delete them all
-ok( Siesta->storage->set_plugins( $list, qw() ) );
+ok( Siesta->storage->set_plugins( $list->id, qw() ) );
 
 # the list of plugins should be empty
-is( Siesta->storage->list_plugins($list), 0, "empty list again" );
+is( Siesta->storage->list_plugins( $list->id ), 0, "empty list again" );
 
 ##
 # now do it all again but with the list interface
 ##
 
 # the list of plugins should be empty
-is( $list->plugins(), 0, "empty list" );
+is( $list->plugins, 0, "empty list" );
 
 @plugins = qw(Bounce ReplyTo);
-
-# set the list of plugins
-ok( $list->set_plugins(@plugins) );
-
-@new = $list->plugins();
-
-$flag = 1;
-foreach my $p (@new) {
-    $flag &&= ( $p eq shift @plugins );
-}
-
-is( $flag, 1, "set the plugins" );
+ok( $list->set_plugins(@plugins), "set" );
+is_deeply( [ $list->plugins ], \@plugins, "plugins are set correctly" );
 
 # add one at the end
 ok( $list->add_plugin('Send') );
+@plugins = $list->plugins;
 
-@plugins = $list->plugins();
-
-$last = pop @plugins;
-is( $last, 'Send', "Add on the end" );
+is( $plugins[-1], 'Send', "Add on the end" );
 
 # add at the start
 ok( $list->add_plugin( 'First', 1 ) );
 
 @plugins = $list->plugins();
-$first   = shift @plugins;
-is( $first, 'First', "Add at the start" );
+is( $plugins[0], 'First', "Add at the start" );
 
 # now delete them all
 ok( $list->set_plugins(qw()) );

Index: 10plugin_listheaders.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/10plugin_listheaders.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- 10plugin_listheaders.t	15 Oct 2002 13:31:45 -0000	1.1
+++ 10plugin_listheaders.t	15 Mar 2003 20:15:55 -0000	1.2
@@ -10,7 +10,7 @@
 my $mail = Siesta::Message->new;
 my $list =
   Test::MockObject->new->mock( post_address => sub { 'foo@xxx.xxx' } )
-  ->mock( id => sub { 'test' } )->mock( owner => sub { 'foo-owner@xxx.xxx' } );
+  ->mock( name => sub { 'test' } )->mock( owner => sub { 'foo-owner@xxx.xxx' } );
 
 $mail->list($list);
 

Index: 10plugin_simplesig.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/10plugin_simplesig.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- 10plugin_simplesig.t	12 Sep 2002 12:55:32 -0000	1.6
+++ 10plugin_simplesig.t	15 Mar 2003 20:15:56 -0000	1.7
@@ -28,7 +28,7 @@
 
 my $list =
   Test::MockObject->new->mock( owner => sub { "Daddy" } )
-  ->mock( id => sub { 'test' } );
+  ->mock( id                         => sub { 'test' } );
 
 my $mail =
   Test::MockObject->new->mock( body => sub { [@mail] } )

Index: 10plugin_subjecttag.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/10plugin_subjecttag.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- 10plugin_subjecttag.t	12 Sep 2002 12:55:32 -0000	1.3
+++ 10plugin_subjecttag.t	15 Mar 2003 20:15:56 -0000	1.4
@@ -8,7 +8,7 @@
 my $plugin = Siesta::Plugin::SubjectTag->new;
 
 my $mail = Siesta::Message->new;
-$mail->list( Test::MockObject->new->mock( id => sub { 'cockknocker' } ) );
+$mail->list( Test::MockObject->new->mock( name => sub { 'cockknocker' } ) );
 
 $mail->subject("Mark Hamill\n");
 is( $mail->subject, "Mark Hamill\n", "before" );

Index: 10plugin_subscribe.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/10plugin_subscribe.t,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- 10plugin_subscribe.t	10 Oct 2002 12:58:49 -0000	1.9
+++ 10plugin_subscribe.t	15 Mar 2003 20:15:57 -0000	1.10
@@ -1,5 +1,46 @@
 #!perl -w
 use strict;
+use Test::More tests => 4;
+use Test::MockObject;
+
+use Siesta::Plugin::Subscribe;
+
+Siesta->connect( DBI => "dbi:SQLite:t/test.db" );
+
+my $plugin = Siesta::Plugin::Subscribe->new;
+my $list   =
+  Test::MockObject->new->mock( name => sub { 'escapees' } )
+  ->mock( owner      => sub { 'houdini@elsewhere' } )
+  ->mock( add_member => sub { $_[1]->email eq 'suzanne@lab' } )
+  ->mock( is_member => sub { $_[1] eq 'houdini@elsewhere' } );
+
+my $reply;
+my $mail =
+  Test::MockObject->new->mock( list => sub { $list } )
+  ->mock( from  => sub { 'suzanne@lab' } )
+  ->mock( reply => sub { shift; $reply = {@_}->{body} } );
+
+ok( $plugin->process($mail), "request handled" );
+like( $reply,
+      qr/You have been successfully subscribed to escapees/,
+      "subscribed suzanne" );
+
+$mail->mock( from => sub { 'jay@jail' } );
+ok( $plugin->process($mail) );
+like( $reply,
+      qr/You could not be subscribed to escapees./,
+      "subscribing jay failed" );
+
+1;
+
+
+__END__
+# all this magic, argh!
+# temporarily we're using the stuff above, which dates back to v1.5
+# --richardc 2003-03-15
+
+#!perl -w
+use strict;
 use Test::More tests => 11;
 use Test::MockObject;
 
@@ -12,14 +53,14 @@
 # set up the mock objects
 my $reply;
 my $subject = "";
-my $user    = Test::MockObject->new->mock( id => sub { 'suzanne@lab' } );
-my $juser   = Test::MockObject->new->mock( id => sub { 'jay@jail' } );
+my $user    = Test::MockObject->new->mock( email => sub { 'suzanne@lab' } );
+my $juser   = Test::MockObject->new->mock( email => sub { 'jay@jail' } );
 
 my $list =
-  Test::MockObject->new->mock( id => sub { 'escapees' } )
-  ->mock( owner => sub { 'houdini@elsewhere' } )
+  Test::MockObject->new->mock( name => sub { 'escapees' } )
+  ->mock( owner                     => sub { 'houdini@elsewhere' } )
   ->mock( add_member => sub { $_[1] eq 'suzanne@lab' || $_[1] eq 'foo@bar' } )
-  ->mock( is_member => sub { $_[1] eq $juser->id } );
+  ->mock( is_member => sub { $_[1] eq $juser->email } );
 
 my $mail =
   Test::MockObject->new->mock( list => sub { $list } )
@@ -78,7 +119,7 @@
 
 $subject = 'Bar';
 
-$user = Test::MockObject->new()->mock( id => sub { 'bob@jail' } );
+$user = Test::MockObject->new()->mock( email => sub { 'bob@jail' } );
 $plugin->process($mail);
 like( $reply, qr/You have requested to be subscribed to/, "trying to sub bob" );
 

Index: 10plugin_unsubscribe.t
===================================================================
RCS file: /cvsroot/siesta/siesta/t/10plugin_unsubscribe.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- 10plugin_unsubscribe.t	12 Sep 2002 12:55:32 -0000	1.2
+++ 10plugin_unsubscribe.t	15 Mar 2003 20:15:59 -0000	1.3
@@ -7,14 +7,14 @@
 
 my $plugin = Siesta::Plugin::UnSubscribe->new;
 my $list   =
-  Test::MockObject->new->mock( id => sub { 'escapees' } )
-  ->mock( owner         => sub { 'houdini@elsewhere' } )
+  Test::MockObject->new->mock( name => sub { 'escapees' } )
+  ->mock( owner                     => sub { 'houdini@elsewhere' } )
   ->mock( remove_member => sub { $_[1] eq 'suzanne@lab' } );
 
 my $reply;
 my $mail =
   Test::MockObject->new->mock( list => sub { $list } )
-  ->mock( from  => sub { 'suzanne@lab' } )
+  ->mock( from                      => sub { 'suzanne@lab' } )
   ->mock( reply => sub { $reply = join '', @_ } );
 
 ok( $plugin->process($mail), "request handled" );



Generated at 13:57 on 01 Jul 2004 by mariachi 0.52