made test run with in independent scopes
Eden Cardim [Fri, 10 Aug 2012 18:34:06 +0000 (15:34 -0300)]
t/text_tradition_user.t
t/text_tradition_user_collapse.t [new file with mode: 0644]

index 7d8b0c7..a401ebe 100644 (file)
@@ -115,27 +115,6 @@ ok($changed->check_password('passbloggs'), 'Modified & retrieved with correct ne
     my $fetched_t = $user_store->tradition($tlist[0]->{id});
     is($fetched_t->user->id, $user->id, 'Traditionlist returns item belonging to this user');
 
-    {
-       # change attribute in the user object
-       my $email = $user->email;
-       $user->email('foo@bar.baz');
-       $user_store->update($user);
-
-       # refetch tradition
-       $fetched_t = $user_store->tradition($tlist[0]->{id});
-       # assert that the associated user also changed
-       is($fetched_t->user->email, 'foo@bar.baz');
-
-       # change the email back to what it was
-       $user->email($email);
-       $user_store->update($user);
-
-       # refetch tradition
-       $fetched_t = $user_store->tradition($tlist[0]->{id});
-       # assert that email has actually been reverted
-       is($fetched_t->user->email, $email);
-    }
-
     ## add a second, not owned by this user, we shouldn't return it from
     ## traditionslist
     my $t2 = Text::Tradition->new( 
diff --git a/t/text_tradition_user_collapse.t b/t/text_tradition_user_collapse.t
new file mode 100644 (file)
index 0000000..dca99bb
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+use File::Temp;
+use Text::Tradition;
+
+use_ok('Text::Tradition::Directory');
+
+my $fh   = File::Temp->new();
+my $file = $fh->filename;
+$fh->close;
+my $dsn = "dbi:SQLite:dbname=$file";
+
+my $user_store = Text::Tradition::Directory->new(
+  'dsn'        => $dsn,
+  'extra_args' => { 'create' => 1 }
+);
+
+my $uuid;
+my $email = 'john@doe.com';
+{
+  my $scope = $user_store->new_scope;
+
+## create user
+  my $new_user = $user_store->add_user(
+    { username => 'fred',
+      password => 'bloggspass'
+    }
+  );
+
+  my $t = Text::Tradition->new(
+    'name'  => 'inline',
+    'input' => 'Tabular',
+    'file'  => 't/data/simple.txt',
+  );
+
+  $uuid = $user_store->save($t);
+  $new_user->add_tradition($t);
+  $new_user->email($email);
+  $user_store->update($new_user);
+}
+
+{
+  my $scope = $user_store->new_scope;
+
+  # change attribute in the user object
+  my $user = $user_store->find_user( { username => 'fred' } );
+  $user->email('foo@bar.baz');
+  $user_store->update($user);
+}
+
+{
+  my $scope = $user_store->new_scope;
+
+  # refetch tradition
+  my $fetched_t = $user_store->tradition($uuid);
+
+  # assert that the associated user also changed
+  is( $fetched_t->user->email, 'foo@bar.baz' );
+}
+
+{
+  my $scope = $user_store->new_scope;
+  my $user = $user_store->find_user( { username => 'fred' } );
+
+  # change the email back to what it was
+  $user->email($email);
+  $user_store->update($user);
+}
+
+{
+  my $scope = $user_store->new_scope;
+
+  # refetch tradition
+  my $fetched_t = $user_store->tradition( $uuid );
+
+  # assert that email has actually been reverted
+  is( $fetched_t->user->email, $email );
+}