4 use Test::More 'no_plan';
14 use_ok 'Text::Tradition::Directory';
16 my $fh = File::Temp->new();
17 my $file = $fh->filename;
19 my $dsn = "dbi:SQLite:dbname=$file";
21 my $d = Text::Tradition::Directory->new( 'dsn' => $dsn,
22 'extra_args' => { 'create' => 1 } );
23 is( ref $d, 'Text::Tradition::Directory', "Got directory object" );
25 my $scope = $d->new_scope;
26 my $t = Text::Tradition->new(
29 'file' => 't/data/simple.txt',
31 my $uuid = $d->save( $t );
32 ok( $uuid, "Saved test tradition" );
34 my $s = $t->add_stemma( 't/data/simple.dot' );
35 ok( $d->save( $t ), "Updated tradition with stemma" );
36 is( $d->tradition( $uuid ), $t, "Correct tradition returned for id" );
37 is( $d->tradition( $uuid )->stemma, $s, "...and it has the correct stemma" );
38 warning_like { $d->save( $s ) } qr/not a Text::Tradition/, "Correctly failed to save stemma directly";
40 my $e = Text::Tradition::Directory->new( 'dsn' => $dsn );
41 $scope = $e->new_scope;
42 is( scalar $e->tradition_ids, 1, "Directory index has our tradition" );
43 my $te = $e->tradition( $uuid );
44 is( $te->name, $t->name, "Retrieved the tradition from a new directory" );
45 my $sid = $e->object_to_id( $te->stemma );
46 warning_like { $e->tradition( $sid ) } qr/not a Text::Tradition/, "Did not retrieve stemma via tradition call";
47 warning_like { $e->delete( $sid ) } qr/Cannot directly delete non-Tradition object/, "Stemma object not deleted from DB";
49 ok( !$e->exists( $uuid ), "Object is deleted from DB" );
50 ok( !$e->exists( $sid ), "Object stemma also deleted from DB" );
51 is( scalar $e->tradition_ids, 0, "Object is deleted from index" );