DBIx-CouchLike
view release on metacpan or search on metacpan
t/15_view_multi.t view on Meta::CPAN
# -*- mode:perl -*-
use strict;
use Test::More qw/ no_plan /;
use Test::Requires qw/ DBD::SQLite /;
BEGIN { use_ok 'DBIx::CouchLike' }
my $dbh = require 't/connect.pl';
ok $dbh;
my $couch = DBIx::CouchLike->new({ dbh => $dbh, table => "view" });
isa_ok $couch => "DBIx::CouchLike";
is $couch->dbh => $dbh;
ok $couch->dbh->ping;
ok $couch->create_table;
my $func = q|
sub {
my ($obj, $emit) = @_;
for my $tag ( @{ $obj->{tags} } ) {
$emit->( $tag, $obj->{name} );
}
}
|;
ok $couch->post("_design/tags" => {
language => 'perl',
views => {
name => { map => $func, }
}
});
my $a_id = 1;
my $u_id = 2;
$couch->post_multi(
{ _id => 1, tags => ['dog', 'cat'], name => 'animal' },
{ _id => 2, tags => ['cat', 'more', 'less'], name => 'unix command' },
);
my @all = $couch->all();
is_deeply \@all => [
{ id => 1, value => { tags => ['dog', 'cat'], name => 'animal' } },
{ id => 2, value => { tags => ['cat', 'more', 'less'], name => 'unix command' } },
{ id => "_design/tags", value => {
language => 'perl',
views => {
name => { map => $func, }
}
}},
];
@all = $couch->all({ exclude_designs => 1 });
is_deeply \@all => [
{ id => 1, value => { tags => ['dog', 'cat'], name => 'animal' } },
{ id => 2, value => { tags => ['cat', 'more', 'less'], name => 'unix command' } },
];
@all = $couch->all_designs();
is_deeply \@all => [
{ id => "_design/tags", value => {
language => 'perl',
views => {
name => { map => $func, }
}
}},
];
my @res = $couch->view("tags/name");
is_deeply \@res => [
( run in 0.799 second using v1.01-cache-2.11-cpan-5b529ec07f3 )