Skip to content

Commit

Permalink
test recipe parser in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Oct 13, 2012
1 parent 054a9e5 commit 8299b71
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/DU/RecipeParser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ sub encode_recipe {
$ingredients .= " # $i->{note}\n" if $i->{note};
}

my $source = "Source: $_[0]->{source}" if $_[0]->{source};
my $source = '';
$source = "Source: $_[0]->{source}" if $_[0]->{source};

<<"RECIPE";
$_[0]->{name}
Expand Down
2 changes: 1 addition & 1 deletion lib/DU/Schema/Result/Drink.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ sub update {
for (@{$data->{ingredients}}) {
my @unit;
if ($_->{unit}) {
my $unit_id = $self->app->app->schema->resultset('Unit')
my $unit_id = $self->result_source->schema->resultset('Unit')
->search({ name => $_->{unit} })
->get_column('id')
->single
Expand Down
20 changes: 20 additions & 0 deletions t/editors/drink-edit-recipe-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env perl

use 5.16.1;
use warnings;

my $file = shift;
open my $fh, '>', $file;
my $recipe = <<'RECIPE';
Face Mask
It's a mask of your own face. Could a halloween mask
be any better than that?
* 1 oz of plastic
* 2 t humanish rubber
Source: my brain, sector 6
RECIPE
print $fh $recipe;
close $fh;
22 changes: 22 additions & 0 deletions t/editors/drink-new-recipe-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env perl

use 5.16.1;
use warnings;

my $file = shift;
open my $fh, '>', $file;
my $recipe = <<'RECIPE';
Blood Wallet
This is a thing from a song by Godspeed! You Black Emperor.
I'm not actually much of a fan.
* 1 ounce of Wallet
* 2 tablespoons of Blood
# Non-human, plz
Source: my brain, sector 5
RECIPE
print $fh $recipe;
close $fh;
50 changes: 50 additions & 0 deletions t/integration/app/drink.t
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ subtest 'new' => sub {
'',
'drink (Awesome bevvy2) created',
]);

local $ENV{EDITOR} = 'drink-new-recipe-1';
$result = test_app($app => [qw(drink new stuplidly-ignored)]);
stdout_is($result, [
'## Blood Wallet',
'',
'## Ingredients',
'',
' * 1 ounce of Wallet',
' * 2 tablespoons of Blood',
'',
'## Description',
'',
'This is a thing from a song by Godspeed! You Black Emperor.',
'',
q(I'm not actually much of a fan.),
'',
'',
q(Source: my brain, sector 5),
'',
'',
'drink (Blood Wallet) created',
]);
};

subtest 'new --based_on' => sub {
Expand Down Expand Up @@ -129,6 +152,33 @@ subtest 'edit' => sub {
'',
'drink (Frewba Libre) updated',
]);


my $app = A->app;

local $ENV{EDITOR} = 'drink-edit-recipe-1';
$result = test_app($app => [qw(drink edit), 'cuba libre']);
stdout_is($result, [
'## Face Mask',
'',
'## Ingredients',
'',
' * 1 ounce of plastic',
' * 2 teaspoons of humanish rubber',
'',
'## Description',
'',
"It's a mask of your own face. Could a halloween mask",
'be any better than that?',
'',
'',
'Variants: Frewba Libre',
'',
'Source: my brain, sector 6',
'',
'',
'drink (Face Mask) updated',
]);
};

subtest 'show' => sub {
Expand Down

0 comments on commit 8299b71

Please sign in to comment.