Delete tests for the old model, and add a few to the new model.
Zachary Stevens [Sun, 15 Nov 2009 17:52:48 +0000 (17:52 +0000)]
t/02git_object.t
t/02git_project.t
t/02git_repo.t
t/model_Git.t [deleted file]

index 6c1d461..bc1a544 100644 (file)
@@ -46,3 +46,29 @@ dies_ok {
 dies_ok {
     print $obj2->comment;
 } 'comment is an empty string';
+
+my $commit_obj = Gitalist::Git::Object->new(
+    project => $project,
+    sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e',
+);
+isa_ok($commit_obj, 'Gitalist::Git::Object', "commit object type correct");
+my ($tree, $patch) = $commit_obj->diff(
+    parent => undef,
+    file => undef,
+    patch => 1,
+);
+$patch = $patch->[0];
+is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct');
+is($patch->{a}, 'a/file1', 'patch->{a} is correct');
+is($patch->{b}, 'b/file1', 'patch->{b} is correct');
+is($patch->{file}, 'file1', 'patch->{file} is correct');
+is($patch->{mode}, '100644', 'patch->{mode} is correct');
+is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct');
+is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct');
+is($patch->{diff}, '--- a/file1
++++ b/file1
+@@ -1 +1 @@
+-foo
++bar
+', 'patch->{diff} is correct');
+is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
index fd9864f..4c03933 100644 (file)
@@ -16,7 +16,8 @@ my $gitdir = dir("$Bin/lib/repositories/repo1");
 
 my $proj = Gitalist::Git::Project->new($gitdir);
 isa_ok($proj, 'Gitalist::Git::Project');
-is($proj->path, $gitdir, 'repository path is set');
+is($proj->path, $gitdir, 'project path is set');
+isa_ok($proj->path, 'Path::Class::Dir', 'project path');
 is($proj->name, qw/repo1/, 'repository name is set');
 is($proj->description, qq/some test repository/, 'repository description loaded');
 isa_ok($proj->last_change, 'DateTime', 'last_change');
@@ -45,3 +46,12 @@ my $hbp_sha1 = $proj->hash_by_path('36c6c6708b8360d7023e8a1649c45bcf9b3bd818', '
 my $obj2 = $proj->get_object($hbp_sha1);
 is($obj2->type, 'blob', 'hash_by_path obj is a file');
 is($obj2->content, "foo\n", 'hash_by_path obj is a file');
+
+like($proj->head_hash('HEAD'), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
+
+{
+    my @tree = $proj->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
+    is(scalar @tree, 1, "tree array contains one entry.");
+    isa_ok(@tree[0], 'Gitalist::Git::Object', 'tree element 0');
+}
+
index be1abbf..ab35c59 100644 (file)
@@ -14,8 +14,22 @@ isa_ok($repo, 'Gitalist::Git::Repo');
 
 is($repo->repo_dir, $repo_dir, "repo->repo_dir is correct" );
 
+# 'bare.git' is a bare git repository in the repository dir
+use Path::Class;
+my $repoBare = Path::Class::Dir->new('t/lib/repositories/bare.git');
+ok( $repo->_is_git_repo( $repoBare ), 'is_git_repo true for bare git repo' );
+
+# 'working' is a working copy w/ git repo in the repository dir
+my $repoWorking = Path::Class::Dir->new('t/lib/repositories/working');
+
+# 'empty.git' is an empty directory in the repository dir
+my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git');
+ok( ! $repo->_is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' );
+
 my $project_list = $repo->projects;
 isa_ok(@$project_list[0], 'Gitalist::Git::Project');
+ok(scalar @{$project_list} == 3, 'list_projects returns an array with the correct number of members' );
+is($project_list->[0]->{name}, 'bare.git', 'list_projects has correct name for "bare.git" repo' );
 
 dies_ok {
     my $project = $repo->project('NoSuchProject');
diff --git a/t/model_Git.t b/t/model_Git.t
deleted file mode 100644 (file)
index d6fb5e2..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-use strict;
-use warnings;
-use FindBin qw/$Bin/;
-use Test::More;
-
-BEGIN { use_ok 'Gitalist::Model::Git' }
-
-use Git::PurePerl;
-my $m = Git::Repos->new({ repo_dir => "$Bin/lib/repositories" });
-isa_ok($m, 'Git::Repos');
-
-# 'bare.git' is a bare git repository in the repository dir
-use Path::Class;
-my $repoBare = Path::Class::Dir->new('t/lib/repositories/bare.git');
-ok( $m->is_git_repo( $repoBare ), 'is_git_repo true for bare git repo' );
-
-# 'working' is a working copy w/ git repo in the repository dir
-my $repoWorking = Path::Class::Dir->new('t/lib/repositories/working');
-#ok( $m->is_git_repo( $repoWorking ), 'is_git_repo true for git repo in working copy' );
-
-# 'empty.git' is an empty directory in the repository dir
-my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git');
-ok( ! $m->is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' );
-
-my $projectList = $m->list_projects('t/lib/repositories');
-ok( scalar @{$projectList} == 3, 'list_projects returns an array with the correct number of members' );
-is( $projectList->[0]->{name}, 'bare.git', 'list_projects has correct name for "bare.git" repo' );
-#ok( $projectList->[1]->{name} eq 'working/.git', 'list_projects has correct name for "working" repo' );
-
-
-# Liberally borrowed from rafl's gitweb
-$m->project('repo1');
-is($m->project, 'repo1', 'model project correct');
-my $pd = $m->project_dir($m->project);
-isa_ok($pd, 'Path::Class::Dir', 'model project_dir');
-is($pd, $m->repo_dir . '/' . $m->project, 'model project_dir correct');
-ok( $m->gpp(Git::PurePerl->new( gitdir => $pd, directory => $pd )), 'model gpp set ok' );
-like($m->head_hash('HEAD'), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
-
-{
-    my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
-    is(scalar @tree, 1, "tree array contains one entry.");
-    is_deeply($tree[0], {
-        mode => oct 100644,
-        modestr => '-rw-r--r--',
-        type => 'blob',
-        object => '257cc5642cb1a054f08cc83f2d943e56fd3ebe99',
-        file => 'file1'
-    });
-
-    is($m->get_object_mode_string($tree[0]), '-rw-r--r--');
-}
-
-is($m->get_object_type('729a7c3f6ba5453b42d16a43692205f67fb23bc1'), 'tree');
-is($m->get_object_type('257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), 'blob');
-is($m->get_object_type('5716ca5987cbf97d6bb54920bea6adde242d87e6'), 'blob');
-
-is($m->cat_file('257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), "foo\n");
-is($m->cat_file('5716ca5987cbf97d6bb54920bea6adde242d87e6'), "bar\n");
-
-
-my $commit = $m->get_object('3f7567c7bdf7e7ebf410926493b92d398333116e');
-isa_ok($commit, 'Git::PurePerl::Object::Commit', "commit object type correct");
-my ($tree, $patch) = $m->diff(
-    commit => $commit,
-    parent => '',
-    file => '',
-    patch => 1,
-);
-$patch = $patch->[0];
-is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct');
-is($patch->{a}, 'a/file1', 'patch->{a} is correct');
-is($patch->{b}, 'b/file1', 'patch->{b} is correct');
-is($patch->{file}, 'file1', 'patch->{file} is correct');
-is($patch->{mode}, '100644', 'patch->{mode} is correct');
-is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct');
-is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct');
-is($patch->{diff}, '--- a/file1
-+++ b/file1
-@@ -1 +1 @@
--foo
-+bar
-', 'patch->{diff} is correct');
-is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
-
-done_testing;
-