Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update instead of croaking when adding existing dist
  • Loading branch information
zoffixznet committed Nov 21, 2015
1 parent 1b637f1 commit 93db555
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web/lib/ModulesPerl6/Model/Dists.pm
Expand Up @@ -58,7 +58,7 @@ sub add {
qw/has_readme panda has_tests travis/,
});

$db->resultset('Dist')->create({
$db->resultset('Dist')->update_or_create({
travis => { status => $dist->{travis_status} },
author => { # use same field for both, for now. TODO:fetch realname
author_id => $dist->{author_id}, name => $dist->{author_id},
Expand Down
13 changes: 12 additions & 1 deletion web/t/01-models/02-dists.t
Expand Up @@ -19,7 +19,18 @@ can_ok $m => qw/add deploy find remove remove_old/;
my ( $dist1, $dist2 ) = t::Helper::dist_out_data;

isa_ok $m->deploy, MODEL, '->deploy returns invocant';
isa_ok $m->add( t::Helper::dist_in_data ), MODEL, '->add returns invocant';

{
# Modify input data; second ->add should update it back to original
# returned from ::dist_in_data
my @d = t::Helper::dist_in_data;
$d[1]{build_id} = 'rvOZAHmQ5RGKE79B+wjaYA==';
isa_ok $m->add( @d ), MODEL, '->add returns invocant';

diag 'Adding same data to database again. '
. 'It must not be duplicated and must instead only be updated';
$m->add( t::Helper::dist_in_data );
}

isa_ok $m->find, 'Mojo::Collection', '->find returns Mojo::Collection object';
is_deeply $m->find, [$dist1, $dist2],
Expand Down

0 comments on commit 93db555

Please sign in to comment.