Skip to content

Commit

Permalink
Merge 71c5150 into c8e8e71
Browse files Browse the repository at this point in the history
  • Loading branch information
nfg committed Jul 11, 2016
2 parents c8e8e71 + 71c5150 commit d47d5af
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Meerkat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ sub collection {
my $class;
if ( my $prefix = $self->collection_namespace ) {
$class = compose_module_name( $prefix, $suffix );
try { require_module($class) } catch { $class = "Meerkat::Collection" };
try { require_module($class) }
catch {
die $_ unless m/Can't locate/;
$class = "Meerkat::Collection"
};
}
else {
$class = "Meerkat::Collection";
Expand Down
44 changes: 44 additions & 0 deletions t/custom_collection_errors.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use strict;
use warnings;
use Test::Roo;
use Test::FailWarnings;
use Test::Fatal;
use Test::Requires qw/MongoDB/;

my $conn = eval { MongoDB::MongoClient->new; };
plan skip_all => "No MongoDB on localhost"
unless eval { $conn->get_database("admin")->run_command( [ ismaster => 1 ] ) };

use lib 't/lib';

with 'TestFixtures';

sub _build_meerkat_options {
my ($self) = @_;
return {
model_namespace => 'My::Model',
collection_namespace => 'Bad::Collection',
database_name => 'test',
};
}

test 'meerkat will propogate custom collection errors' => sub {
my $self = shift;

my $err = exception { $self->meerkat->collection('Doom') };
like(
$err,
qr/This attribute will blow up on construction/,
"Caught error from custom collection object"
);

my $coll;
$err = exception { $coll = $self->meerkat->collection('Person') };
ok( !$err, 'No exception when custom collection package is missing' );
isa_ok( $coll, 'Meerkat::Collection' );
};

run_me;
done_testing;
# COPYRIGHT
# vim: ts=4 sts=4 sw=4 et:
16 changes: 16 additions & 0 deletions t/lib/Bad/Collection/Doom.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use strict;
use warnings;

package Bad::Collection::Doom;

use Moose 2;
extends 'Meerkat::Collection';

has bad_attribute => (
is => 'ro',
default => sub {
die "This attribute will blow up on construction";
}
);

1;

0 comments on commit d47d5af

Please sign in to comment.