From: <pau...@us...> - 2007-06-23 09:02:43
|
Revision: 970 http://svn.sourceforge.net/everydevel/?rev=970&view=rev Author: paul_the_nomad Date: 2007-06-23 02:02:38 -0700 (Sat, 23 Jun 2007) Log Message: ----------- Elimination of global in Auth.pm Modified Paths: -------------- trunk/ebase/lib/Everything/Auth.pm trunk/ebase/lib/Everything/Test/Auth.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - 16c2b9cb-492b-4d64-9535-64d4e875048d:/wip/ebase:1022 a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17930 + 16c2b9cb-492b-4d64-9535-64d4e875048d:/wip/ebase:1024 a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17930 Modified: trunk/ebase/lib/Everything/Auth.pm =================================================================== --- trunk/ebase/lib/Everything/Auth.pm 2007-06-06 17:40:56 UTC (rev 969) +++ trunk/ebase/lib/Everything/Auth.pm 2007-06-23 09:02:38 UTC (rev 970) @@ -19,7 +19,6 @@ package Everything::Auth; use strict; -use Everything qw/$DB/; =cut @@ -51,6 +50,8 @@ my ( $class, $options ) = @_; $options ||= {}; + my $DB = $options->{nodebase}; + # We may not always get the guest user pref (if ever). We can default to # plain Guest User @@ -145,6 +146,8 @@ { my ( $this, $user ) = @_; + my $DB = $this->{options}->{nodebase}; + $user ||= $DB->getNode( $this->{options}->{guest_user} ); # No user yet? Now would be a good time to cry... Modified: trunk/ebase/lib/Everything/Test/Auth.pm =================================================================== --- trunk/ebase/lib/Everything/Test/Auth.pm 2007-06-06 17:40:56 UTC (rev 969) +++ trunk/ebase/lib/Everything/Test/Auth.pm 2007-06-23 09:02:38 UTC (rev 970) @@ -9,29 +9,18 @@ use SUPER; use strict; -sub startup : Test( startup => +6 ) { +sub startup : Test( startup => +5 ) { my $self = shift; my $db = Test::MockObject->new(); - local *Everything::Auth::DB; - my @imports; - *Everything::Auth::DB = \$db; - $db->fake_module( - 'Everything', - import => sub { - @imports = @_; - *Everything::Auth::DB = \$db; - } - ); - $self->SUPER; - is( $imports[1], '$DB', '...should import $DB from Everything.pm' ); + can_ok( $self->{class}, 'new' ); $db->set_always( getNode => { node_id => 88 } ); $self->{db} = $db; - my $instance = $self->{class}->new(); + my $instance = $self->{class}->new( { nodebase => $db } ); isa_ok( $instance, $self->{class} ); $self->{instance} = $instance; @@ -120,23 +109,22 @@ my $self = shift; my $package = $self->{class}; my $db = $self->{db}; - local *Everything::Auth::DB; - *Everything::Auth::DB = \$db; + my $instance = $self->{instance}; can_ok( $package, 'generateSession' ); my $mock = Test::MockObject->new(); - $mock->{options} = { guest_user => 'guest' }; + $instance->{options}->{guest_user} = 'guest'; $mock->set_always( getVars => 'vars' ); $db->set_false('getNode')->clear(); - throws_ok { Everything::Auth::generateSession($mock) } + throws_ok { Everything::Auth::generateSession($instance) } qr/Unable to get user!/, 'generateSession() should die with no user'; my ( $method, $args ) = $db->next_call(); is( $method, 'getNode', '... so should fetch a user given none' ); is( $args->[1], 'guest', '... using guest user option' ); - my @results = Everything::Auth::generateSession( $mock, $mock ); + my @results = $instance->generateSession( $mock ); is_deeply( \@results, [ $mock, 'vars' ], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |