Skip to content
Browse files

increase test coverage

  • Loading branch information...
1 parent 2bb72e6 commit e607bb34a25df9182b6223b316566282abb5787d @frioux committed
View
1 Makefile.PL
@@ -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>';
View
4 lib/DU/App/Command/inventory/add.pm
@@ -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) = @_;
View
4 lib/DU/App/Command/inventory/ls.pm
@@ -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) = @_;
View
6 lib/DU/Schema/Result/Drink.pm
@@ -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';
View
13 lib/DU/Schema/Result/Drink_Ingredient.pm
@@ -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;
View
7 lib/DU/Schema/Result/Ingredient.pm
@@ -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';
View
10 lib/DU/Schema/ResultSet/Drink.pm
@@ -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
19 lib/DU/Util.pm
@@ -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,7 +30,7 @@ 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
),
'',
@@ -37,7 +38,7 @@ sub drink_as_markdown {
'',
$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
21 t/editors/drink-new-2
@@ -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;
View
14 t/editors/ingredient-edit-2
@@ -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
14 t/editors/ingredient-new-2
@@ -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
55 t/integration/app/drink.t
@@ -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
18 t/integration/app/help.t
@@ -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;
View
32 t/integration/app/ingredient.t
@@ -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 {
View
16 t/integration/app/inventory.t
@@ -14,6 +14,22 @@ my $app = A->app;
local $ENV{PATH} = 't/editors:' . $ENV{PATH};
+subtest 'help' => sub {
+ my $result = test_app($app => [qw(inventory help)]);
+ stdout_is($result, [
+ 'inventory.t <command>',
+ '',
+ 'Available commands:',
+ '',
+ q( commands: list the application's commands),
+ q( help: display a command's help screen),
+ '',
+ ' add: add ingredient to inventory',
+ ' ls: list inventory',
+ ' rm: remove ingredient from inventory'
+ ]);
+};
+
subtest 'add' => sub {
my $result = test_app($app => [qw(inventory add), '* cola']);
stdout_is($result, [ 'ingredient (Coca Cola) added to inventory' ]);
View
6 t/lib/A.pm
@@ -44,10 +44,8 @@ sub _deploy_schema {
my $filename = Path::Class::File->new(__FILE__)->dir
->file('sqlite.sql')->stringify;
my $sql = do { local (@ARGV, $/) = $filename ; <> };
- for my $chunk ( split (/;\s*\n+/, $sql) ) {
- if ( $chunk =~ / ^ (?! --\s* ) \S /xm ) { # there is some real sql in the chunk - a non-space at the start of the string which is not a comment
- $schema->storage->dbh_do(sub { $_[1]->do($chunk) }) or print "Error on SQL: $chunk\n";
- }
+ for my $chunk ( grep { / ^ (?! --\s* ) \S /xm } split (/;\s*\n+/, $sql) ) {
+ $schema->storage->dbh_do(sub { $_[1]->do($chunk) })
}
}
View
108 t/lib/sqlite.sql
@@ -0,0 +1,108 @@
+--
+-- Created by SQL::Translator::Producer::SQLite
+-- Created on Thu Jun 14 15:02:49 2012
+--
+
+--
+-- Table: "drinks"
+--
+CREATE TABLE "drinks" (
+ "id" INTEGER PRIMARY KEY NOT NULL,
+ "description" ntext NOT NULL,
+ "source" nvarchar(50),
+ "variant_of_drink_id" int,
+ FOREIGN KEY ("variant_of_drink_id") REFERENCES "drinks"("id") ON DELETE CASCADE ON UPDATE CASCADE
+);
+
+CREATE INDEX "drinks_idx_variant_of_drink_id" ON "drinks" ("variant_of_drink_id");
+
+--
+-- Table: "ingredients"
+--
+CREATE TABLE "ingredients" (
+ "id" INTEGER PRIMARY KEY NOT NULL,
+ "kind_of_id" int,
+ "materialized_path" varchar(255),
+ "name" nvarchar(50) NOT NULL,
+ "description" ntext,
+ FOREIGN KEY ("kind_of_id") REFERENCES "ingredients"("id") ON DELETE CASCADE ON UPDATE CASCADE
+);
+
+CREATE INDEX "ingredients_idx_kind_of_id" ON "ingredients" ("kind_of_id");
+
+CREATE UNIQUE INDEX "ingredients_name" ON "ingredients" ("name");
+
+--
+-- Table: "units"
+--
+CREATE TABLE "units" (
+ "id" INTEGER PRIMARY KEY NOT NULL,
+ "name" nvarchar(50) NOT NULL,
+ "gills" float
+);
+
+CREATE UNIQUE INDEX "units_name" ON "units" ("name");
+
+--
+-- Table: "users"
+--
+CREATE TABLE "users" (
+ "id" INTEGER PRIMARY KEY NOT NULL,
+ "name" nvarchar(50) NOT NULL
+);
+
+CREATE UNIQUE INDEX "users_name" ON "users" ("name");
+
+--
+-- Table: "drink_names"
+--
+CREATE TABLE "drink_names" (
+ "id" INTEGER PRIMARY KEY NOT NULL,
+ "drink_id" int NOT NULL,
+ "name" nvarchar(50) NOT NULL,
+ "order" float NOT NULL,
+ FOREIGN KEY ("drink_id") REFERENCES "drinks"("id") ON DELETE CASCADE ON UPDATE CASCADE
+);
+
+CREATE INDEX "drink_names_idx_drink_id" ON "drink_names" ("drink_id");
+
+CREATE UNIQUE INDEX "drink_names_drink_id_order" ON "drink_names" ("drink_id", "order");
+
+CREATE UNIQUE INDEX "drink_names_name" ON "drink_names" ("name");
+
+--
+-- Table: "inventory_items"
+--
+CREATE TABLE "inventory_items" (
+ "ingredient_id" int NOT NULL,
+ "user_id" int NOT NULL,
+ PRIMARY KEY ("ingredient_id", "user_id"),
+ FOREIGN KEY ("ingredient_id") REFERENCES "ingredients"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE
+);
+
+CREATE INDEX "inventory_items_idx_ingredient_id" ON "inventory_items" ("ingredient_id");
+
+CREATE INDEX "inventory_items_idx_user_id" ON "inventory_items" ("user_id");
+
+--
+-- Table: "drink_ingredients"
+--
+CREATE TABLE "drink_ingredients" (
+ "drink_id" int NOT NULL,
+ "ingredient_id" int NOT NULL,
+ "unit_id" int,
+ "amount" float,
+ "arbitrary_amount" nvarchar(50),
+ "notes" ntext,
+ PRIMARY KEY ("drink_id", "ingredient_id"),
+ FOREIGN KEY ("drink_id") REFERENCES "drinks"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ FOREIGN KEY ("ingredient_id") REFERENCES "ingredients"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ FOREIGN KEY ("unit_id") REFERENCES "units"("id")
+);
+
+CREATE INDEX "drink_ingredients_idx_drink_id" ON "drink_ingredients" ("drink_id");
+
+CREATE INDEX "drink_ingredients_idx_ingredient_id" ON "drink_ingredients" ("ingredient_id");
+
+CREATE INDEX "drink_ingredients_idx_unit_id" ON "drink_ingredients" ("unit_id");
View
32 t/schema.t
@@ -111,13 +111,29 @@ subtest searches => sub {
cmp_deeply(
[ sort map $_->name, $d->none_by_user_inventory($f)->all ],
[ 'Cuba Libre' ],
- 'none'
+ 'none_by_user_inventory'
+ );
+
+ cmp_deeply(
+ [ sort map $_->name, $d->none_by_ingredient_id([
+ map $_->id, $f->ingredients->all
+ ])->all ],
+ [ 'Cuba Libre' ],
+ 'none_by_ingredient_id'
);
cmp_deeply(
[ sort map $_->name, $d->some_by_user_inventory($f)->all ],
[ 'Frewba Libre', 'Tom Collins' ],
- 'some'
+ 'some_by_user_inventory'
+ );
+
+ cmp_deeply(
+ [ sort map $_->name, $d->some_by_ingredient_id([
+ map $_->id, $f->ingredients->all
+ ])->all ],
+ [ 'Frewba Libre', 'Tom Collins' ],
+ 'some_by_ingredient_id'
);
$f->inventory_items->search({
@@ -134,14 +150,22 @@ subtest searches => sub {
cmp_deeply(
[ sort map $_->name, $d->every_by_user($f)->all ],
[ ],
- 'every'
+ 'every_by_user'
);
$f->add_to_ingredients($sl);
cmp_deeply(
[ sort map $_->name, $d->every_by_user($f)->all ],
[ 'Tom Collins', ],
- 'every (post kind_of addition)'
+ 'every_by_user (post kind_of addition)'
+ );
+
+ cmp_deeply(
+ [ sort map $_->name, $d->every_by_ingredient_id([
+ map $_->id, $f->ingredients->all
+ ])->all ],
+ [ 'Tom Collins', ],
+ 'every_by_ingredient_id'
);
};
View
327 t/unit/util.t
@@ -0,0 +1,327 @@
+#!/usr/bin/env perl
+
+use 5.14.1;
+use warnings;
+
+use Test::More;
+use Test::Deep;
+use Test::Exit;
+
+use DU::Util ':all';
+
+subtest volume_with_unit => sub {
+ is(
+ volume_with_unit(
+ Ingredient->new( arbitrary_amount => 'Package' )
+ ),
+ 'Package',
+ 'arbitrary_amount works',
+ );
+
+ is(
+ volume_with_unit(
+ Ingredient->new(
+ unit_name => 'ounce',
+ amount => .5,
+ )
+ ),
+ '0.5 ounces',
+ 'unit_names + amount',
+ );
+
+ is(
+ volume_with_unit(
+ Ingredient->new(
+ unit_name => 'ounce',
+ amount => 1,
+ )
+ ),
+ '1 ounce',
+ 'unit_name + amount',
+ );
+
+ is(
+ volume_with_unit(
+ Ingredient->new( amount => 1 )
+ ),
+ '???',
+ 'no unit!',
+ );
+};
+
+my $gin_1 = Ingredient->new(
+ ingredient_name => 'Gin',
+ unit_name => 'ounce',
+ amount => 2,
+);
+
+my $g_t = Drink->new(
+ name => 'Gin and Tonic',
+ links_to_drink_ingredients => RSFaker->new(
+ $gin_1,
+ Ingredient->new(
+ ingredient_name => 'Tonic',
+ unit_name => 'ounce',
+ amount => 2,
+ ),
+ ),
+ description => 'just mix em. Ice is ok.',
+);
+
+my $w_c = Drink->new(
+ name => 'Wes Collins',
+ variant_of_drink_name => 'Tom Collins',
+ variants => RSFaker->new(
+ Drink->new( name => 'Geoff Collins' ),
+ ),
+ source => 'Weskers Manlone',
+ links_to_drink_ingredients => RSFaker->new(
+ Ingredient->new(
+ ingredient_name => 'Tonic',
+ unit_name => 'ounce',
+ amount => 4,
+ ),
+ Ingredient->new(
+ ingredient_name => 'Gin',
+ unit_name => 'ounce',
+ amount => 2,
+ ),
+ Ingredient->new(
+ ingredient_name => 'Triple Sec',
+ unit_name => 'ounce',
+ amount => 1,
+ ),
+ ),
+ description => 'just mix em. Ice is ok.',
+);
+
+subtest drink_as_markdown => sub {
+ my $out;
+ $out = <<'CRUMP';
+## Gin and Tonic
+
+## Ingredients
+
+ * 2 ounces of Gin
+ * 2 ounces of Tonic
+
+## Description
+
+just mix em. Ice is ok.
+
+CRUMP
+ is(drink_as_markdown($g_t), $out, 'vanilla');
+
+ $out = <<'CRUMP';
+## Wes Collins
+
+## Ingredients
+
+ * 4 ounces of Tonic
+ * 2 ounces of Gin
+ * 1 ounce of Triple Sec
+
+## Description
+
+just mix em. Ice is ok.
+
+Variant of Tom Collins
+
+Variants: Geoff Collins
+
+Source: Weskers Manlone
+
+CRUMP
+ is(drink_as_markdown($w_c), $out, 'variant_of + variants + source');
+};
+
+my $l_w = Drink->new(
+ name => 'Lol Collins',
+ links_to_drink_ingredients => RSFaker->new(
+ Ingredient->new(
+ ingredient_name => 'Tonic',
+ arbitrary_amount => 'Bottle',
+ notes => 'srsly, the whole bottle!',
+ ),
+ ),
+ description => 'just mix em. Ice is ok.',
+);
+
+subtest drink_as_data => sub {
+ cmp_deeply(
+ drink_as_data($l_w), {
+ name => 'Lol Collins',
+ description => 'just mix em. Ice is ok.',
+ source => undef,
+ ingredients => [{
+ arbitrary_amount => 'Bottle',
+ notes => 'srsly, the whole bottle!',
+ name => "Tonic",
+ }],
+ },
+ 'arbitrary_amount + notes',
+ );
+
+ cmp_deeply(
+ drink_as_data($g_t), {
+ name => 'Gin and Tonic',
+ description => 'just mix em. Ice is ok.',
+ source => undef,
+ ingredients => [{
+ amount => 2,
+ name => "Gin",
+ unit => "ounce"
+ }, {
+ amount => 2,
+ name => "Tonic",
+ unit => "ounce"
+ }],
+ },
+ 'vanilla',
+ );
+
+ cmp_deeply(
+ drink_as_data($w_c), {
+ name => "Wes Collins",
+ ingredients => [{
+ amount => 4,
+ name => "Tonic",
+ unit => "ounce"
+ }, {
+ amount => 2,
+ name => "Gin",
+ unit => "ounce"
+ }, {
+ amount => 1,
+ name => "Triple Sec",
+ unit => "ounce"
+ }],
+ source => "Weskers Manlone",
+ variant_of_drink => "Tom Collins",
+ description => "just mix em. Ice is ok.",
+ },
+ 'variant_of + variants + source',
+ );
+};
+
+use Devel::Dwarn;
+
+subtest ingredient_as_data => sub {
+ cmp_deeply(
+ ingredient_as_data(Ingredient2->new(
+ name => 'cola',
+ )), {
+ name => 'cola',
+ description => undef
+ },
+ 'vanilla',
+ );
+
+ cmp_deeply(
+ ingredient_as_data(Ingredient2->new(
+ name => 'cola',
+ direct_kind_of_name => 'soda',
+ )), {
+ name => 'cola',
+ description => undef,
+ isa => 'soda',
+ },
+ 'direct_kind_of',
+ );
+};
+
+subtest single_item => sub {
+ my $ran;
+ my $found;
+ single_item(
+ sub { $ran = 1; $found = $_[0]->view },
+ 'foo',
+ 'bar',
+ RSFaker->new(
+ Item->new(
+ view => 'lol',
+ )
+ ),
+ );
+ ok($ran, '"single" single_item ran');
+ is($found, 'lol', 'correct thing passed to action');
+
+ exits_nonzero {
+ single_item(
+ sub {}, 'foo', 'bar', RSFaker->new(),
+ )
+ } 'zero';
+
+ exits_nonzero {
+ single_item(
+ sub {}, 'foo', 'bar', RSFaker->new(
+ map Item->new( view => $_ ), 1, 2,
+ ),
+ )
+ } 'many';
+};
+
+done_testing;
+
+BEGIN {
+ package Ingredient;
+
+ use Moo;
+
+ has $_ => (
+ is => 'ro',
+ ) for qw(ingredient_name arbitrary_amount amount unit_name notes );
+
+ sub unit { $_[0]->unit_name }
+
+ package Ingredient2;
+
+ use Moo;
+
+ has $_ => (
+ is => 'ro',
+ ) for qw( name description direct_kind_of_name );
+
+ sub direct_kind_of { $_[0]->direct_kind_of_name }
+
+ package RSFaker;
+
+ use Moo;
+
+ has guts => (
+ is => 'ro',
+ default => sub { [] },
+ );
+
+ sub BUILDARGS { shift; return { guts => [@_], } }
+
+ sub all { @{$_[0]->guts} }
+ sub count { scalar @{$_[0]->guts} }
+ sub single { $_[0]->guts->[0] }
+ sub cli_find { $_[0] }
+
+ package Drink;
+
+ use Moo;
+
+ has $_ => (
+ is => 'ro',
+ ) for qw(
+ name links_to_drink_ingredients variant_of_drink_name source description
+ );
+
+ sub variant_of_drink { $_[0]->variant_of_drink_name }
+
+ has variants => (
+ is => 'ro',
+ default => sub { RSFaker->new() },
+ );
+
+ package Item;
+
+ use Moo;
+
+ has view => (
+ is => 'ro',
+ );
+}

0 comments on commit e607bb3

Please sign in to comment.
Something went wrong with that request. Please try again.