Permalink
Browse files

add user id property to author document

  • Loading branch information...
1 parent 3e2d3a9 commit 1d43209f97cc5fffbccdc51f20cdfb7efcb7e6cf @monken monken committed Jan 16, 2012
Showing with 30 additions and 12 deletions.
  1. +2 −2 lib/MetaCPAN/Document/Author.pm
  2. +13 −1 lib/MetaCPAN/Model/User/Account.pm
  3. +15 −9 lib/MetaCPAN/Server/Test.pm
@@ -99,9 +99,9 @@ has asciiname => (
has [qw(website email)] =>
( is => 'ro', required => 1, isa => ArrayRef, coerce => 1 );
has pauseid => ( is => 'ro', required => 1, id => 1 );
+has user => ( is => 'rw' );
has dir => ( is => 'ro', required => 1, lazy_build => 1 );
-has gravatar_url =>
- ( is => 'ro', lazy_build => 1, isa => NonEmptySimpleStr );
+has gravatar_url => ( is => 'ro', lazy_build => 1, isa => NonEmptySimpleStr );
has profile => (
is => 'ro',
isa => Profile,
@@ -33,7 +33,19 @@ has access_token => (
has passed_captcha => ( is => 'rw', isa => 'DateTime' );
-has looks_human => ( is => 'ro', isa => 'Bool', required => 1, lazy_build => 1 );
+has looks_human =>
+ ( is => 'ro', isa => 'Bool', required => 1, lazy_build => 1 );
+
+after add_identity => sub {
+ my ( $self, $identity ) = @_;
+ if ( $identity->{name} eq 'pause' ) {
+ my $profile = $self->index->model->index('cpan')->type('author')
+ ->get( $identity->{key} );
+ return unless ($profile);
+ $profile->user( $self->id );
+ $profile->put;
+ }
+};
sub _build_looks_human {
my $self = shift;
@@ -7,23 +7,29 @@ use warnings;
use Plack::Test;
use HTTP::Request::Common qw(POST GET DELETE);
use JSON::XS;
+use Test::More;
use base 'Exporter';
our @EXPORT = qw(POST GET DELETE test_psgi app encode_json decode_json);
BEGIN { $ENV{METACPAN_SERVER_CONFIG_LOCAL_SUFFIX} = 'testing'; }
$FindBin::RealBin .= '/some';
my $app = require MetaCPAN::Server;
-MetaCPAN::Server->model('User::Account')->put(
- { identity => [ { name => 'pause', key => 'MO' } ],
- access_token => [ { client => 'testing', token => 'testing' } ]
- },
- { refresh => 1 }
+ok( my $user = MetaCPAN::Server->model('User::Account')->put(
+ { access_token => [ { client => 'testing', token => 'testing' } ] }
+ ),
+ 'prepare user'
+);
+ok( $user->add_identity( { name => 'pause', key => 'MO' } ),
+ 'add pause identity' );
+ok( $user->put( { refresh => 1 } ), 'put user' );
+
+ok( MetaCPAN::Server->model('User::Account')->put(
+ { access_token => [ { client => 'testing', token => 'bot' } ] },
+ { refresh => 1 }
+ ),
+ 'put bot user'
);
-
-MetaCPAN::Server->model('User::Account')
- ->put( { access_token => [ { client => 'testing', token => 'bot' } ] },
- { refresh => 1 } );
sub app {$app}
1;

0 comments on commit 1d43209

Please sign in to comment.