1use warnings; 2use strict; 3use Test::More tests => 23; 4 5use File::Temp qw'tempdir'; 6 7use_ok('Prophet::CLI'); 8$ENV{'PROPHET_REPO'} = 9 tempdir( CLEANUP => !$ENV{PROPHET_DEBUG} ) . '/repo-' . $$; 10my $cli = Prophet::CLI->new(); 11my $cxn = $cli->handle; 12 13isa_ok( $cxn, 'Prophet::Replica', "Got the cxn" ); 14 15$cxn->initialize; 16 17use_ok('Prophet::Record'); 18my $record = Prophet::Record->new( handle => $cxn, type => 'Person' ); 19isa_ok( $record, 'Prophet::Record' ); 20my $uuid = $record->create( props => { name => 'Jesse', age => 31 } ); 21ok($uuid); 22is( $record->prop('age'), 31 ); 23$record->set_prop( name => 'age', value => 32 ); 24is( $record->prop('age'), 32 ); 25 26my $kaia = $record->create( props => { name => 'Kaia', age => 24 } ); 27ok($kaia); 28my $mao = 29 $record->create( props => { name => 'Mao', age => 0.7, species => 'cat' } ); 30ok($mao); 31my $mei = $record->create( 32 props => { name => 'Mei', age => "0.7", species => 'cat' } ); 33ok($mei); 34use_ok('Prophet::Collection'); 35 36my $people = Prophet::Collection->new( handle => $cxn, type => 'Person' ); 37$people->matching( sub { ( shift->prop('species') || '' ) ne 'cat' } ); 38is( $people->count, 2 ); 39is_deeply( [ sort map { $_->prop('name') } @$people ], [qw(Jesse Kaia)] ); 40 41my $cats = Prophet::Collection->new( handle => $cxn, type => 'Person' ); 42$cats->matching( sub { ( shift->prop('species') || '' ) eq 'cat' } ); 43is( $cats->count, 2 ); 44for (@$cats) { 45 is( $_->prop('age'), "0.7" ); 46} 47is_deeply( [ sort map { $_->prop('name') } @$cats ], [qw(Mao Mei)] ); 48 49my $cat = Prophet::Record->new( handle => $cxn, type => 'Person' ); 50$cat->load( uuid => $mao ); 51$cat->set_prop( name => 'age', value => '0.8' ); 52my $cat2 = Prophet::Record->new( handle => $cxn, type => 'Person' ); 53$cat2->load( uuid => $mei ); 54$cat2->set_prop( name => 'age', value => '0.8' ); 55 56# Redo our search for cats 57$cats = Prophet::Collection->new( handle => $cxn, type => 'Person' ); 58$cats->matching( sub { ( shift->prop('species') || '' ) eq 'cat' } ); 59is( $cats->count, 2 ); 60for (@$cats) { 61 is( $_->prop('age'), "0.8" ); 62} 63 64for (@$cats) { 65 ok( $_->delete ); 66} 67 68my $records = Prophet::Collection->new( type => 'Person', handle => $cxn ); 69$records->matching( sub {1} ); 70is( $records->count, 2 ); 711; 72