class Gitalist::Git::CollectionOfRepositories::Vhost
with Gitalist::Git::CollectionOfRepositories {
+ use MooseX::Types::Moose qw/ HashRef Str /;
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
use MooseX::Types::Path::Class qw/Dir/;
+ use Moose::Util::TypeConstraints;
+
+ sub BUILDARGS { # FIXME - This is fuck ugly!
+ my ($class, @args) = @_;
+ my $args = $class->next::method(@args);
+ my %collections = %{ delete $args->{collections} };
+ foreach my $name (keys %collections) {
+ my %args = %{$collections{$name}};
+ my $class = delete $args{class};
+ Class::MOP::load_class($class);
+ $collections{$name} = $class->new(%args);
+ }
+ my $ret = { %$args, collections => \%collections };
+ return $ret;
+ }
has vhost_dispatch => (
isa => HashRef,
- sa => HashRef,
traits => ['Hash'],
required => 1,
handles => {
required => 1,
);
+ role_type 'Gitalist::Git::CollectionOfRepositories';
has chosen_collection => (
does => 'Gitalist::Git::CollectionOfRepositories',
handles => [qw/
/],
default => sub {
my $self = shift;
- $self->_get_collection($self->_get_collection_name_for_vhost($self->vhost) || $self->_get_collection_name_for_vhost('default'));
+ $self->_get_collection($self->_get_collection_name_for_vhost($self->vhost) || $self->_get_collection_name_for_vhost('_default_'));
},
lazy => 1,
);
vhost_dispatch => {
"git.shadowcat.co.uk" => "foo",
"git.moose.perl.org" => "bar",
+ "_default_" => "foo",
},
collections => {
- foo => Gitalist::Git::CollectionOfRepositories::XXX->new(),
- bar => Gitalist::Git::CollectionOfRepositories::XXX->new,
+ foo => { class => Gitalist::Git::CollectionOfRepositories::XXX', %args },
+ bar => { class => Gitalist::Git::CollectionOfRepositories::XXX', %args },
}
);
my $repository_list = $repo->repositories;
my $mock_ctx_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] );
$mock_ctx_meta->add_method('run_options' => sub { $run_options });
$mock_ctx_meta->add_attribute($_, accessor => $_, required => 1) for qw/request response/;
+$mock_ctx_meta->add_method('debug' => sub {});
$mock_ctx_meta->add_attribute('stash', accessor => 'stash', required => 1, default => sub { {} });
$mock_ctx_meta->add_around_method_modifier( stash => sub { # Nicked straight from Catalyst.pm
my $orig = shift;
my $logger = $mock_log->name->new;
$mock_ctx_meta->add_method('log' => sub { $logger });
+my $host = "example.gitalist.com";
our $ctx_gen = sub {
my ($cb, %args) = @_;
my $ctx = $mock_ctx_meta->new_object(
response => Catalyst::Response->new,
- request => Catalyst::Request->new,
+ request => Catalyst::Request->new(uri => URI->new("http://$host/")),
stash => {},
%args
);
ok $i->fanciness, "The TestModelFancy is fancy (so --model-args worked)";
}
+sub test_vhost_instance {
+ test_with_config({
+ class => 'Gitalist::Git::CollectionOfRepositories::Vhost',
+ args => {
+ vhost_dispatch => {
+ "git.shadowcat.co.uk" => "default",
+ "git.moose.perl.org" => "moose",
+ "git.catalyst.perl.org" => "catgit",
+ "_default_" => "default",
+ },
+ collections => {
+ moose => { class => 'Gitalist::Git::CollectionOfRepositories::FromDirectory', repo_dir => "$FindBin::Bin/lib/repositories_sets/moose" },
+ catgit => { class => 'Gitalist::Git::CollectionOfRepositories::FromDirectory', repo_dir => "$FindBin::Bin/lib/repositories_sets/catgit" },
+ default => { class => 'Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive', repo_dir => "$FindBin::Bin/lib/repositories_sets"},
+ }
+ },
+ });
+}
+
+my $c_name = "$FindBin::Bin/lib/repositories_sets/catgit/Catalyst-Runtime/.git";
+my $m_name = "$FindBin::Bin/lib/repositories_sets/moose/Moose/.git";
+{
+ my $i = test_vhost_instance();
+ is scalar($i->repositories->flatten), 2, 'Found 2 repos on test vhost';
+ my @r = $i->repositories->flatten;
+ my @paths = sort map { $_->path . "" } $i->repositories->flatten;
+ is_deeply \@paths, [sort $c_name, $m_name];
+}
+
+{
+ $host = "git.moose.perl.org";
+ my $i = test_vhost_instance();
+ is scalar($i->repositories->flatten), 1, 'Found 1 repos on moose vhost';
+ is $i->repositories->[0]->path.'', $m_name;
+}
+
+{
+ $host = "git.catalyst.perl.org";
+ my $i = test_vhost_instance();
+ is scalar($i->repositories->flatten), 1, 'Found 1 repos on catalyst vhost';
+ is $i->repositories->[0]->path.'', $c_name;
+}
+
+{
+ $host = "git.shadowcat.co.uk";
+ my $i = test_vhost_instance();
+ is scalar($i->repositories->flatten), 2, 'Found 2 repos on git.shadowcat vhost';
+ my @paths = sort map { $_->path . "" } $i->repositories->flatten;
+ is_deeply \@paths, [sort $c_name, $m_name];
+}
+
sub test_with_config {
my ($config, %opts) = @_;
my $msg = delete $opts{msg} || 'Built Model without exception';