ACME-QuoteDB
view release on metacpan or search on metacpan
t/04-get_quotes_more.t view on Meta::CPAN
is $load_db->success, 1;
}
my $sq = ACME::QuoteDB->new;
is $sq->get_quote({Rating => '8.7'}),
"Me fail English? That's unpossible.\n-- Ralph Wiggum";
is( $sq->list_attr_sources, 'The Simpsons');
is( $sq->list_categories, 'Humor');
{
eval { # quote is mandatory
$sq->add_quote({
Quote => q{},
AttrName => 'Peter Griffin',
Source => 'Family Guy',
Rating => '8.6',
Category => 'TV Humor',
});
};
if ($@) {
if ($@ =~ m/ are mandatory parameters/){
pass 'correct, exception expected'
}
else {fail 'unexpected exception occured'};
}
else {fail 'quote and name are required'};
}
# quote does not yet exist in db
{
eval { # see, not exist yet
$sq->get_quote({AttrName => 'Griffin'});
};
if ($@) {
pass 'ok' if $@ =~ m/attribution not found/;
} else {
fail 'attribution does not yet exist, so should not be found'
};
}
{ # now, add new quote to the db
$sq->add_quote({
Quote => $FG_QUOTE,
AttrName => 'Peter Griffin',
Source => 'Family Guy',
Rating => '8.6',
Category => 'TV Humor',
});
# exist now
ok scalar $sq->get_quote({AttrName => 'GRIFFIN'}); # case insensitve
my $fgc = $FG_QUOTE;
$fgc .= "\n-- Peter Griffin";
is $fgc, $sq->get_quote({AttrName => 'Peter G'});
# get newly updated source and category
is( $sq->list_attr_sources, "Family Guy\nThe Simpsons" );
is( $sq->list_categories, "Humor\nTV Humor");
}
{
# crud
# get_quote id, update quote content, delete quote
my $qid = $sq->get_quote_id({Quote => $FG_QUOTE});
my $qu = $FG_QUOTE;
$qu =~ s/Lois/Marge/xmsg;
$qu =~ s/Peter/Homer/xmsg;
is $sq->get_quote({Rating => '9.6'}), undef;
$sq->update_quote({
QuoteId => $qid,
Quote => $qu,
AttrName => 'Lois Simpson',
Source => 'The Simpsons Guys',
Rating => '9.6',
Category => 'Cartoon Noir',
});
$qu .= "\n-- Lois Simpson";
eval { # see, updated, should now be 'Lois Simpson'
$sq->get_quote({AttrName => 'Peter G'});
};
if ($@) {
pass 'ok' if $@ =~ m/attribution not found/;
} else {fail 'attribution does not yet exist, so should not be found'};
is $sq->get_quote({AttrName => 'Lois Simpson'}), $qu;
is $sq->get_quote({AttrName => 'Lois S'}), $qu;
is $sq->get_quote({Rating => '9.6'}), $qu;
is $sq->get_quote({Source => 'The Simpsons Guys'}), $qu;
is $sq->get_quote({Category => 'Cartoon Noir'}), $qu;
$sq->delete_quote({QuoteId => $qid});
# see, bye, bye
is $sq->get_quote({AttrName => 'Lois S'}), undef;
is $sq->get_quote({Rating => '9.6'}), undef;
}
# TODO
{ # add new quote to the db
$sq->add_quote({
Quote => $FG_QUOTE,
AttrName => 'Peter Griffin',
Source => 'Family Guy',
Rating => '8.6',
Category => [qw(Humor TV PG13 Crude Cartoon ROTFLMAO)]
});
my $qid = $sq->get_quote_id({Quote => $FG_QUOTE});
# one quote can belong to many categories
my $q = $FG_QUOTE;
$q .= "\n-- Peter Griffin";
is $sq->get_quote({
Source => 'Family Guy',
Category => [qw(Humor TV PG13 Crude Cartoon ROTFLMAO)]
}), $q;
# get all quotes from these categories
is $sq->get_quote({
Category => [qw(Crude Cartoon ROTFLMAO)]
}), $q;
is scalar @{$sq->get_quotes({
Category => [qw(Humor ROTFLMAO)]
})}, 30;
ok $sq->delete_quote({QuoteId => $qid});
}
( run in 2.927 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )