Cope with changes in Catalyst 5.90007 in t/model_collectionofrepos.t.
[catagits/Gitalist.git] / t / model_collectionofrepos.t
index 0225ee6..63589a7 100644 (file)
@@ -47,33 +47,34 @@ $mock_log->add_method($_ => sub {}) for qw/ warn info debug /;
 my $logger = $mock_log->name->new;
 $mock_ctx_meta->add_method('log' => sub { $logger });
 
-my $host = "example.gitalist.com";
+my $host = "git.shadowcat.co.uk";
+$mock_ctx_meta->add_method('uri' => sub { URI->new("http://$host/") });
 our $ctx_gen = sub {
     my ($cb, %args) = @_;
     my $ctx = $mock_ctx_meta->new_object(
         response    => Catalyst::Response->new,
-        request     => Catalyst::Request->new(uri => URI->new("http://$host/")),
+        # Too lazy to mock up Catalyst::Log
+        request     => Catalyst::Request->new(uri => URI->new("http://$host/"), _log => 1),
         stash       => {},
         %args
     );
-    $ctx->response->_context($ctx);
-    $ctx->request->_context($ctx);
     $cb->($ctx) if $cb;
     return $ctx;
 };
 
 local %ENV = %ENV;
+delete $ENV{GITALIST_CONFIG};
 delete $ENV{GITALIST_REPO_DIR};
 
 throws_ok { my $i = Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), {}); $i->{_application} = $mock_ctx_meta->name; }
     qr/Don't know where to get repositores from/, 'Blows up nicely with no repos dir';
 
-throws_ok { Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), { repos_dir => '/does/not/exist' }) }
+throws_ok { Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), { repo_dir => '/does/not/exist' }) }
     qr|No such file or directory|, 'Blows up nicely with repos dir does not exist';
 
 {
     my $td = tempdir( CLEANUP => 1 );
-    test_with_config({ repos_dir => $td }, msg => 'repos_dir is tempdir');
+    test_with_config({ repo_dir => $td }, msg => 'repo_dir is tempdir');
     # NOTE - This is cheating, there isn't a real git repository here, so things will explode (hopefully)
     #        if we go much further..
     test_with_config({ repos => $td }, msg => 'repos is tempdir (scalar)');
@@ -103,13 +104,13 @@ throws_ok { Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), { repos
 }
 
 {
-    my $i = test_with_config({ repos_dir => "$FindBin::Bin/lib/repositories"});
+    my $i = test_with_config({ repo_dir => "$FindBin::Bin/lib/repositories"});
     is scalar($i->repositories->flatten), 3, 'Found 3 repos';
     isa_ok $i, 'Gitalist::Git::CollectionOfRepositories::FromDirectory';
 }
 
 {
-    my $i = test_with_config({ repos_dir => "$FindBin::Bin/lib/repositories", search_recursively => 1 });
+    my $i = test_with_config({ repo_dir => "$FindBin::Bin/lib/repositories", search_recursively => 1 });
     is scalar($i->repositories->flatten), 7, 'Found 7 repos recursively using config';
     isa_ok $i, 'Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive';
 }
@@ -117,7 +118,7 @@ throws_ok { Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), { repos
     my($tempfh, $wl) = tempfile(UNLINK => 1);
     print {$tempfh} "repo1";
     close $tempfh;
-    my $i = test_with_config({ repos_dir => "$FindBin::Bin/lib/repositories", whitelist => $wl });
+    my $i = test_with_config({ repo_dir => "$FindBin::Bin/lib/repositories", whitelist => $wl });
     is scalar($i->repositories->flatten), 1, 'Found 1 repos using whitelist';
     isa_ok $i, 'Gitalist::Git::CollectionOfRepositories::FromDirectory::WhiteList';
 }
@@ -134,7 +135,7 @@ throws_ok { Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), { repos
 
 {
     my $i = test_with_config({
-        repos_dir => "$FindBin::Bin/lib/repositories",
+        repo_dir => "$FindBin::Bin/lib/repositories",
         class    => 'TestModelSimple'
     });
     is scalar($i->repositories->flatten), 3, 'Found 3 repos';
@@ -143,7 +144,7 @@ throws_ok { Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), { repos
 
 {
     my $i = test_with_config({
-        repos_dir => "$FindBin::Bin/lib/repositories",
+        repo_dir => "$FindBin::Bin/lib/repositories",
         class    => 'TestModelFancy',
         args     => { fanciness => 1 },
     });
@@ -171,8 +172,8 @@ sub test_vhost_instance {
     });
 }
 
-my $c_name = "$FindBin::Bin/lib/repositories_sets/catgit/Catalyst-Runtime/.git";
-my $m_name = "$FindBin::Bin/lib/repositories_sets/moose/Moose/.git";
+my $c_name = "$FindBin::Bin/lib/repositories_sets/catgit/Catalyst-Runtime";
+my $m_name = "$FindBin::Bin/lib/repositories_sets/moose/Moose";
 {
     my $i = test_vhost_instance();
     is scalar($i->repositories->flatten), 2, 'Found 2 repos on test vhost';
@@ -212,9 +213,6 @@ sub test_with_config {
     ok $m, 'Has model';
     my $i = $m->ACCEPT_CONTEXT($ctx);
     ok $i, 'Has model instance from ACCEPT_CONTEXT';
-    isnt $i, $m, 'Model instance returned from ACCEPT_CONTEXT not same as model';
-    is $i, $m->ACCEPT_CONTEXT($ctx), 'Same model instance for same context';
-    isnt $i, $m->ACCEPT_CONTEXT($ctx_gen->()), 'Different model instance for different context';
     return $i;
 }