Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 57 lines (43 sloc) 1.168 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/usr/bin/perl

use strict;
use warnings;
use Test::More 0.96;
use Test::Moose;
use Test::Exception;
use Test::Deep;

use lib 't/lib';

BEGIN {
    use_ok 'TypeTest' || print 'Bail out';
}

our ( $test_class, @mapping );

my $model = new_ok 'TypeTest';
isa_ok my $tm = $model->typemap, 'Elastic::Model::TypeMap::Base';

note '';
note "Mapping for $test_class";

does_ok my $class = $model->class_for($test_class),
    'Elastic::Model::Role::Doc';

my $meta = $class->meta;

while (@mapping) {
    test_mapping( $meta, splice @mapping, 0, 2 );
}

note '';
done_testing;

#===================================
sub test_mapping {
#===================================
    my ( $meta, $name, $test ) = @_;
    $name .= '_attr';
    ok my $attr = $meta->find_attribute_by_name($name), "Has attr: $name";
    return unless $attr;

# use Data::Dump qw(pp); pp(eval {+{$name=> {$tm->find_mapper($attr)}}}||$@);
    if ( ref($test) eq 'HASH' ) {
        is_deeply
            eval { +{ $tm->find_mapper($attr) } } || $@,
            $test,
            "Mapping: $name";
    }
    else {
        throws_ok sub { $tm->find_mapper($attr) }, $test, "$name fails ok";
    }
}

1;
Something went wrong with that request. Please try again.