6 use Test::More 'no_plan';
10 use_ok('Text::Tradition::Directory');
12 my $fh = File::Temp->new();
13 my $file = $fh->filename;
15 my $dsn = "dbi:SQLite:dbname=$file";
19 my $email = 'john@doe.com';
21 my $user_store = Text::Tradition::Directory->new(
23 'extra_args' => { 'create' => 1 }
26 my $scope = $user_store->new_scope;
29 my $new_user = $user_store->add_user(
31 password => 'bloggspass'
35 my $t = Text::Tradition->new(
38 'file' => 't/data/simple.txt',
41 $uuid = $user_store->save($t);
42 $new_user->add_tradition($t);
43 $new_user->email($email);
44 ok( $t->user, 'sets user' );
45 $user_store->update($new_user);
46 $user_store->save($t);
50 my $user_store = Text::Tradition::Directory->new(
52 'extra_args' => { 'create' => 1 }
54 my $scope = $user_store->new_scope;
56 # change attribute in the user object
57 my $user = $user_store->find_user( { username => 'fred' } );
58 $user->email('foo@bar.baz');
59 $user_store->update($user);
60 is( scalar @{ $user->traditions }, 1 );
61 ok( $user->traditions->[0]->user,
62 'reinflated tradition object from user points to user' );
66 my $user_store = Text::Tradition::Directory->new(
68 'extra_args' => { 'create' => 1 }
70 my $scope = $user_store->new_scope;
73 my $fetched_t = $user_store->tradition($uuid);
75 # assert that the associated user also changed
76 is( $fetched_t->user->email, 'foo@bar.baz' );
80 my $user_store = Text::Tradition::Directory->new(
82 'extra_args' => { 'create' => 1 }
84 my $scope = $user_store->new_scope;
85 my $user = $user_store->find_user( { username => 'fred' } );
87 # change the email back to what it was
89 $user_store->update($user);
93 my $user_store = Text::Tradition::Directory->new(
95 'extra_args' => { 'create' => 1 }
97 my $scope = $user_store->new_scope;
100 my $fetched_t = $user_store->tradition($uuid);
102 # assert that email has actually been reverted
103 is( $fetched_t->user->email, $email );