Permalink
Browse files

increase test coverage

  • Loading branch information...
frioux committed Aug 21, 2012
1 parent 2bb72e6 commit e607bb34a25df9182b6223b316566282abb5787d
View
@@ -15,6 +15,7 @@ requires 'YAML::Syck';
requires 'Test::More';
requires 'Module::Load';
requires 'Sub::Exporter::Progressive';
+requires 'Test::Exit';
name 'Drinkup';
author 'Arthur Axel fREW Schmidt <frioux@gmail.com>';
@@ -6,9 +6,9 @@ use warnings;
use DU::App -command;
use DU::Util 'single_item';
-sub abstract { 'remove ingredient from inventory' }
+sub abstract { 'add ingredient to inventory' }
-sub usage_desc { 'du inventory rm $ingredient' }
+sub usage_desc { 'du inventory add $ingredient' }
sub execute {
my ($self, $opt, $args) = @_;
@@ -5,9 +5,9 @@ use warnings;
use DU::App -command;
-sub abstract { 'remove ingredient from inventory' }
+sub abstract { 'list inventory' }
-sub usage_desc { 'du inventory rm $ingredient' }
+sub usage_desc { 'du ls' }
sub execute {
my ($self, $opt, $args) = @_;
@@ -20,7 +20,11 @@ column variant_of_drink_id => {
is_nullable => 1,
};
-belongs_to variant_of_drink => '::Drink', 'variant_of_drink_id';
+belongs_to variant_of_drink => '::Drink', 'variant_of_drink_id', {
+ proxy => {
+ variant_of_drink_name => 'name',
+ },
+};
has_many variants => '::Drink', 'variant_of_drink_id';
has_many names => '::DrinkName', 'drink_id';
has_many links_to_drink_ingredients => '::Drink_Ingredient', 'drink_id';
@@ -27,8 +27,17 @@ column notes => {
};
belongs_to drink => '::Drink', 'drink_id';
-belongs_to ingredient => '::Ingredient', 'ingredient_id';
-belongs_to unit => '::Unit', 'unit_id';
+belongs_to ingredient => '::Ingredient', 'ingredient_id', {
+ proxy => {
+ ingredient_name => 'name',
+ },
+};
+
+belongs_to unit => '::Unit', 'unit_id', {
+ proxy => {
+ unit_name => 'name',
+ },
+};
1;
@@ -49,7 +49,12 @@ sub materialized_path_columns {
}
-belongs_to direct_kind_of => '::Ingredient', 'kind_of_id', { join_type => 'left' };
+belongs_to direct_kind_of => '::Ingredient', 'kind_of_id', {
+ join_type => 'left',
+ proxy => {
+ direct_kind_of_name => 'name',
+ },
+};
has_many direct_kinds => '::Ingredient', 'kind_of_id';
has_many inventory_items => '::InventoryItem', 'ingredient_id';
has_many links_to_drink_ingredients => '::Drink_Ingredient', 'ingredient_id';
@@ -82,10 +82,12 @@ sub cli_find {
}
sub some_by_user_inventory {
- $_[0]->some($_[1]->inventory_items->get_column('ingredient_id')->as_query)
+ $_[0]->some_by_ingredient_id(
+ $_[1]->inventory_items->get_column('ingredient_id')->as_query
+ )
}
-sub some {
+sub some_by_ingredient_id {
my ($self, $ingredient_ids) = @_;
my $ids = $self->search({
@@ -202,10 +204,14 @@ SQL
sub nearly_by_user { $_[0]->ineq_by_user($_[1], $_[2], $_[2]); }
+sub nearly_by_ingredient_id { $_[0]->ineq_by_ingredient_id($_[1], $_[2], $_[2]); }
+
sub nearly { $_[0]->ineq($_[1], $_[2], $_[2]); }
sub every_by_user { $_[0]->nearly_by_user($_[1], 0) }
+sub every_by_ingredient_id { $_[0]->nearly_by_ingredient_id($_[1], 0) }
+
sub every { $_[0]->nearly($_[1], 0) }
1;
View
@@ -3,9 +3,10 @@ package DU::Util;
use 5.14.1;
use warnings;
-use Sub::Exporter -setup => {
+use Sub::Exporter::Progressive -setup => {
exports => [qw{
- ingredient_as_data volume_with_unit drink_as_markdown drink_as_data single_item edit_data
+ ingredient_as_data volume_with_unit drink_as_markdown drink_as_data
+ single_item edit_data
}],
};
use Lingua::EN::Inflect 'PL';
@@ -17,7 +18,7 @@ sub volume_with_unit {
return $v if $v;
- return $d_i->amount . ' ' . PL($d_i->unit->name, $d_i->amount) if $d_i->unit;
+ return $d_i->amount . ' ' . PL($d_i->unit_name, $d_i->amount) if $d_i->unit;
return '???'
}
@@ -29,15 +30,15 @@ sub drink_as_markdown {
'',
'## Ingredients',
'',
- (map ' * ' . volume_with_unit($_) . ' of ' . $_->ingredient->name,
+ (map ' * ' . volume_with_unit($_) . ' of ' . $_->ingredient_name,
$drink->links_to_drink_ingredients->all
),
'',
'## Description',
'',
$drink->description,
( $drink->variant_of_drink ? (
- '', 'Variant of ' . $drink->variant_of_drink->name,
+ '', 'Variant of ' . $drink->variant_of_drink_name,
) : () ),
( $drink->variants->count ? (
'', 'Variants: ' . join ', ', map $_->name, $drink->variants->all,
@@ -54,7 +55,7 @@ sub drink_as_data {
description => $_[0]->description,
source => $_[0]->source,
( $_[0]->variant_of_drink ? (
- variant_of_drink => $_[0]->variant_of_drink->name,
+ variant_of_drink => $_[0]->variant_of_drink_name,
) : () ),
ingredients => [
map +{
@@ -64,13 +65,13 @@ sub drink_as_data {
),
( $_->unit
? (
- unit => $_->unit->name,
+ unit => $_->unit_name,
amount => $_->amount,
)
: ()
),
( $_->notes ? ( notes => $_->notes ) : () ),
- name => $_->ingredient->name,
+ name => $_->ingredient_name,
}, $_[0]->links_to_drink_ingredients->all
],
}
@@ -81,7 +82,7 @@ sub ingredient_as_data {
name => $_[0]->name,
description => $_[0]->description,
( $_[0]->direct_kind_of ? (
- isa => $_[0]->direct_kind_of->name,
+ isa => $_[0]->direct_kind_of_name,
) : () ),
}
}
View
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use 5.14.1;
+use warnings;
+
+my $file = shift;
+open my $fh, '>', $file;
+my $yml = <<'YML';
+---
+name: Awesome bevvy2
+isa: Awesome bevvy
+description: YUMM
+source: Boy's Life
+ingredients:
+ -
+ name: ice
+ unit: ounce
+ amount: 5
+YML
+print $fh $yml;
+close $fh;
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+
+use 5.14.1;
+use warnings;
+
+my $file = shift;
+open my $fh, '>', $file;
+my $yml = <<'YML';
+---
+name: plastic buttons
+description: eyeball
+YML
+print $fh $yml;
+close $fh;
View
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+
+use 5.14.1;
+use warnings;
+
+my $file = shift;
+open my $fh, '>', $file;
+my $yml = <<'YML';
+---
+name: metal coins
+description: blood
+YML
+print $fh $yml;
+close $fh;
View
@@ -14,6 +14,24 @@ my $app = A->app;
local $ENV{PATH} = 't/editors:' . $ENV{PATH};
+subtest 'help' => sub {
+ my $result = test_app($app => [qw(drink help)]);
+ stdout_is($result, [
+ 'drink.t <command>',
+ '',
+ 'Available commands:',
+ '',
+ q( commands: list the application's commands),
+ q( help: display a command's help screen),
+ '',
+ ' edit: edit drink',
+ ' ls: list drinks',
+ ' new: create new drink',
+ ' rm: delete drink',
+ ' show: show drink'
+ ]);
+};
+
subtest 'ls' => sub {
my $result = test_app($app => [qw(drink ls)]);
stdout_is($result, [
@@ -42,6 +60,25 @@ subtest 'new' => sub {
'',
'drink (Awesome bevvy) created',
]);
+
+ local $ENV{EDITOR} = 'drink-new-2';
+ $result = test_app($app => [qw(drink new -b), 'Awesome bevvy']);
+ stdout_is($result, [
+ '## Awesome bevvy2',
+ '',
+ '## Ingredients',
+ '',
+ ' * 5 ounces of ice',
+ '',
+ '## Description',
+ '',
+ "YUMM",
+ '',
+ q(Source: Boy's Life),
+ '',
+ '',
+ 'drink (Awesome bevvy2) created',
+ ]);
};
subtest 'new --based_on' => sub {
@@ -94,5 +131,23 @@ subtest 'edit' => sub {
]);
};
+subtest 'show' => sub {
+ my $result = test_app($app => [qw(drink show), 'frewba libre']);
+ stdout_is($result, [
+ '## Frewba Libre',
+ '',
+ '## Ingredients',
+ '',
+ '',
+ '## Description',
+ '',
+ "A Delicious beverage of frew's own design",
+ '',
+ 'Variant of Cuba Libre',
+ '',
+ 'Source: TV Guide wtf?',
+ ]);
+};
+
done_testing;
View
@@ -14,21 +14,17 @@ my $app = A->app;
local $ENV{PATH} = 't/editors:' . $ENV{PATH};
-local $TODO = q(App::Cmd can't test help for subcommands?);
-my $result = test_app($app => [qw(drink help)]);
+my $result = test_app($app => [qw(help)]);
stdout_is($result, [
- 'app.t <command>',
- '',
'Available commands:',
'',
- q( commands: list the application's commands),
- q( help: display a command's help screen),
- '',
- ' drink: interact with drinks',
- 'ingredient: interact with ingredients',
- ' inventory: interact with inventory',
- ' maint: ',
+ q( commands: list the application's commands),
+ q( help: display a command's help screen),
'',
+ ' drink: interact with drinks',
+ ' ingredient: interact with ingredients',
+ ' inventory: interact with inventory',
+ ' maint: ',
]);
done_testing;
@@ -14,10 +14,31 @@ my $app = A->app;
local $ENV{PATH} = 't/editors:' . $ENV{PATH};
+subtest 'help' => sub {
+ my $result = test_app($app => [qw(ingredient help)]);
+ stdout_is($result, [
+ 'ingredient.t <command>',
+ '',
+ 'Available commands:',
+ '',
+ q( commands: list the application's commands),
+ q( help: display a command's help screen),
+ '',
+ ' edit: edit ingredient',
+ ' ls: list ingredients',
+ ' new: create new ingredient',
+ ' rm: delete ingredient'
+ ]);
+};
+
subtest 'new' => sub {
local $ENV{EDITOR} = 'ingredient-new-1';
my $result = test_app($app => [qw(ingredient new)]);
- stdout_is($result, [ 'ingredient (copper coins) created' ]);
+ stdout_is($result, [ 'ingredient (copper coins) created' ], 'with isa');
+
+ local $ENV{EDITOR} = 'ingredient-new-2';
+ $result = test_app($app => [qw(ingredient new)]);
+ stdout_is($result, [ 'ingredient (metal coins) created' ], 'without isa');
};
subtest 'ls' => sub {
@@ -35,6 +56,7 @@ subtest 'ls' => sub {
' * Vanilla Extract',
' * coin',
' * copper coins',
+ ' * metal coins',
]);
};
@@ -43,7 +65,13 @@ subtest 'edit' => sub {
my $result = test_app($app => [qw(ingredient edit), 'lime *']);
stdout_is($result, [
'ingredient (plastic buttons) updated',
- ]);
+ ], 'with isa');
+
+ local $ENV{EDITOR} = 'ingredient-edit-2';
+ $result = test_app($app => [qw(ingredient edit), 'plastic buttons']);
+ stdout_is($result, [
+ 'ingredient (plastic buttons) updated',
+ ], 'without isa');
};
subtest 'rm' => sub {
Oops, something went wrong.

0 comments on commit e607bb3

Please sign in to comment.