CatalystX-Resource

 view release on metacpan or  search on metacpan

t/02_crud.t  view on Meta::CPAN

    location => 'Madison Cube Garden',
});

lives_ok(sub { $artist->albums->create({ id => 1, name => 'Mach et einfach!' }); }, 'create album');

# test / for no special reason
{
    my $path = '/';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/TestApp/', "$path content contains string 'TestApp'");
}

# identifier_candidates
{
    my $path = '/artists/' . $artist->id . '/concerts/'. $concert->id .  '/edit';
    #my $res = request(POST $path);
    my $res = request(POST $path, [ location => 'Madison Square Garden' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/' . $artist->id . '/concerts/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/Madison Square Garden updated/', 'check update success notification');
}

# SHOW
{
    my $path ='/artists/1/show';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/davewood/', "$path content contains string 'davewood'");
    $path = '/artists/99/show';
    ok(request($path)->code == 404, "Unknown resource $path returns HTTP 404");
}

# LIST
{
    my $path ='/artists/list';
    my $res = request($path);
    ok($res->is_success, "Get $path");
    like($res->decoded_content, '/davewood[\s\S]*flipper/', "$path content contains 'davewood' and 'flipper'");
}

# DELETE
{
    my $path ='/artists/1/delete';
    my $res = request($path);
    ok($res->is_error, "delete with GET returns HTTP 404");
    $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

# CREATE
{
    my $path ='/artists/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post".*password/s', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'simit', password => 'asdf', password_repeat => 'asdf' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    $path ='/artists/list';
    $res = request($path);
    like($res->decoded_content, '/simit/', "$path content contains 'simit'");
}

# EDIT
{
    my $path ='/artists/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    my $content = $res->decoded_content;
    like($content, '/method="post"/', "$path content contains 'method=\"post\"'");
    like($content, '/flipper/', "$path content contains 'flipper'");
    unlike($content, '/password/', "$path does not contain 'password'");
    $res = request(POST $path, [ name => 'willy' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    $path ='/artists/2/show';
    $res = request($path);
    like($res->decoded_content, '/willy/', "$path content contains 'willy'");
}

# and now for nested resources
# SHOW
{
    my $path ='/artists/2/albums/1/show';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/Mach et einfach/', "$path content contains string 'Mach et einfach'");
    $path = '/artists/2/albums/99/show';
    ok(request($path)->code == 404, "Unknown resource $path returns HTTP 404");
}

# LIST
{
    my $path ='/artists/2/albums/list';
    my $res = request($path);
    ok($res->is_success, "Get $path");
    like($res->decoded_content, '/Mach et einfach/', "$path content contains 'Mach et einfach'");
}

# DELETE
{
    my $path ='/artists/2/albums/1/delete';
    my $res = request($path);
    ok($res->is_error, "delete with GET returns HTTP 404");
    $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

# CREATE
{
    my $path ='/artists/2/albums/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'I Brake Together' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    $path ='/artists/2/albums/list';
    $res = request($path);
    like($res->decoded_content, '/I Brake Together/', "$path content contains 'I Brake Together'");
}

# EDIT
{
    my $path ='/artists/2/albums/1/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    like($res->decoded_content, '/I Brake Together/', "$path content contains 'I Brake Together'");
    $res = request(POST $path, [ name => 'Es gibt Reis, Baby' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    $path ='/artists/2/albums/1/show';
    $res = request($path);
    like($res->decoded_content, '/Es gibt Reis, Baby/', "$path content contains 'Es gibt Reis, Baby'");
}

# EDIT with TT variable interpolation (example: [% moby %])
# album.name is using an inline form template
# artist.name is using a form.tt file
# this test makes sure the behaviour of the two is the same
{
    my $path ='/artists/2/albums/1/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    like($res->decoded_content, '/Es gibt Reis, Baby/', "POST $path content contains 'Es gibt Reis, Baby'");
    $res = request(POST $path, [ name => 'Es gibt [% Reis %], Baby' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    $path ='/artists/2/albums/1/show';
    $res = request($path);
    like($res->decoded_content, '/Es gibt \[% Reis %\], Baby/', "GET $path content contains 'Es gibt [% Reis %], Baby'");

    $path ='/artists/2/albums/1/edit';
    $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/value="Es gibt \[% Reis %\], Baby/', "GET $path content contains 'Es gibt [% Reis %], Baby'");

    $path ='/artists/2/edit';
    $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    my $content = $res->decoded_content;
    like($content, '/method="post"/', "$path content contains 'method=\"post\"'");
    like($content, '/willy/', "$path content contains 'willy'");
    unlike($content, '/password/', "$path does not contain 'password'");
    $res = request(POST $path, [ name => '[% moby %]' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    $path ='/artists/2/show';
    $res = request($path);
    like($res->decoded_content, '/\[% moby %\]/', "$path content contains '[% moby %]'");
}

done_testing;

t/03_redirect_mode_list.t  view on Meta::CPAN


# check redirection for redirect_mode = 'list'
# DELETE
{
    my $path ='/artists/1/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    unlike($content, '/>davewood<\/a>/', 'resource has been deleted');
    like($content, '/davewood deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

# CREATE
{
    my $path ='/artists/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'simit', password => 'asdf', password_repeat => 'asdf' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/>simit<\/a>/', 'resource has been created');
    like($content, '/simit created/', 'check create success notification');
}

# EDIT
{
    my $path ='/artists/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'foobar' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/>foobar<\/a>/', 'resource has been edited');
    like($content, '/foobar updated/', 'check edit success notification');
}

# for nested resources
# CREATE
{
    my $path ='/artists/2/albums/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'I Brake Together' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/albums/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/>I Brake Together<\/a>/', 'resource has been created');
    like($content, '/I Brake Together created/', 'check create success notification');
}

# EDIT
{
    my $path ='/artists/2/albums/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'Es gibt Reis, Baby' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/albums/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/>Es gibt Reis, Baby<\/a>/', 'resource has been edited');
    like($content, '/Es gibt Reis, Baby updated/', 'check edit success notification');
}

# DELETE
{
    my $path ='/artists/2/albums/2/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/albums/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    unlike($content, '/>Es gibt Reis, Baby<\/a>/', 'resource has been deleted');
    like($content, '/Es gibt Reis, Baby deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

done_testing;

t/04_redirect_mode_show.t  view on Meta::CPAN

        my $controller = $c->controller("Resource::$resource");
        $controller->redirect_mode('show');
    }
}

# CREATE
{
    my $path ='/artists/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'simit', password => 'asdf', password_repeat => 'asdf' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/3/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/3:simit/', 'resource has been created');
    like($content, '/simit created/', 'check create success notification');
}

# DELETE
{
    my $path ='/artists/1/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    unlike($content, '/>davewood<\/a>/', 'resource has been deleted');
    like($content, '/davewood deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

# EDIT
{
    my $path ='/artists/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'foobar' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/foobar/', 'resource has been edited');
    like($content, '/foobar updated/', 'check edit success notification');
}

# for nested resources
# CREATE
{
    my $path ='/artists/2/albums/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'I Brake Together' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/albums/2/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/2:I Brake Together/', 'resource has been created');
    like($content, '/I Brake Together created/', 'check create success notification');
}

# EDIT
{
    my $path ='/artists/2/albums/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'Es gibt Reis, Baby' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/albums/2/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/2:Es gibt Reis, Baby/', 'resource has been edited');
    like($content, '/Es gibt Reis, Baby updated/', 'check edit success notification');
}

# DELETE
{
    my $path ='/artists/2/albums/2/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/albums/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    unlike($content, '/show">Es gibt Reis, Baby/', 'resource has been deleted');
    like($content, '/Es gibt Reis, Baby deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

done_testing;

t/05_redirect_mode_show_parent.t  view on Meta::CPAN

        $controller->redirect_mode('show_parent');
    }
}

# check redirection for redirect_mode = 'list'
# CREATE
{
    my $path ='/artists/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'simit', password => 'asdf', password_repeat => 'asdf' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/show">simit/', 'resource has been created');
    like($content, '/simit created/', 'check create success notification');
}

# DELETE
{
    my $path ='/artists/1/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    unlike($content, '/show">davewood/', 'resource has been deleted');
    like($content, '/davewood deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

# EDIT
{
    my $path ='/artists/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'foobar' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/show">foobar/', 'resource has been edited');
    like($content, '/foobar updated/', 'check edit success notification');
}

# for nested resources
# CREATE
{
    my $path ='/artists/2/albums/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'I Brake Together' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/I Brake Together created/', 'check create success notification');
}

# EDIT
{
    my $path ='/artists/2/albums/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'Es gibt Reis, Baby' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/Es gibt Reis, Baby updated/', 'check edit success notification');
}

# DELETE
{
    my $path ='/artists/2/albums/2/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/2/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/Es gibt Reis, Baby deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

done_testing;

t/06_redirect_mode_parent_list.t  view on Meta::CPAN

        $controller->redirect_mode('show_parent_list');
    }
}

# check redirection for redirect_mode = 'list'
# CREATE
{
    my $path ='/artists/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'simit', password => 'asdf', password_repeat => 'asdf' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/show">simit/', 'resource has been created');
    like($content, '/simit created/', 'check create success notification');
}

# DELETE
{
    my $path ='/artists/1/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    unlike($content, '/show">davewood/', 'resource has been deleted');
    like($content, '/davewood deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

# EDIT
{
    my $path ='/artists/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'foobar' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/show">foobar/', 'resource has been edited');
    like($content, '/foobar updated/', 'check edit success notification');
}

# for nested resources
# CREATE
{
    my $path ='/artists/2/albums/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'I Brake Together' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/I Brake Together created/', 'check create success notification');
}

# EDIT
{
    my $path ='/artists/2/albums/2/edit';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/method="post"/', "$path content contains 'method=\"post\"'");
    $res = request(POST $path, [ name => 'Es gibt Reis, Baby' ]);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/Es gibt Reis, Baby updated/', 'check edit success notification');
}

# DELETE
{
    my $path ='/artists/2/albums/2/delete';
    my $res = request(POST $path);
    ok($res->is_redirect, "$path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/Es gibt Reis, Baby deleted/', 'check delete success notification');
    ok(request(POST $path)->code == 404, "Already deleted $path returns HTTP 404");
}

done_testing;

t/07_sortable.t  view on Meta::CPAN

# move_next
{
    my $path ='/artists/1/move_next';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, Referer => '/artists/list');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/davewood moved next/', 'check move_next success notification');
    like($content, '/flipper<\/a>.*davewood/s', 'resource has been moved to next position');
}

# move_previous
{
    my $path ='/artists/1/move_previous';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, Referer => '/artists/list');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/davewood moved previous/', 'check move_previous success notification');
    like($content, '/davewood<\/a>.*flipper/s', 'resource has been moved to previous position');
}

# failing move_to because request parameter with new position is missing
{
    my ($path, $res, $content);
    $path ='/artists/1/move_to';
    $res = request(POST $path, Referer => '/artists/list');
    $content = $res->content;

t/07_sortable.t  view on Meta::CPAN

# move_to
{
    my $path ='/artists/1/move_to?pos=2';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, Referer => '/artists/list');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/davewood moved./', 'check move_to success notification');
    like($content, '/flipper<\/a>.*davewood/s', 'resource has been moved to position 2');
}

# nested resources
# move_next
{
    my $path ='/artists/1/albums/1/songs/1/move_next';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, Referer => '/artists/1/albums/1/songs/list');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/1/albums/1/songs/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/smack my bitch up moved next/', 'check move_next success notification');
    like($content, '/hit me baby one more time<\/a>.*smack my bitch up/s', 'resource has been moved to next position');
}

# move_previous
{
    my $path ='/artists/1/albums/1/songs/1/move_previous';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, Referer => '/artists/1/albums/1/songs/list');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/1/albums/1/songs/list', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/smack my bitch up moved previous/', 'check move_previous success notification');
    like($content, '/smack my bitch up<\/a>.*hit me baby one more time/s', 'resource has been moved to previous position');
}

# Nested resource
# redirect_mode = 'show_parent'
{
    my $path ='/artists/1/albums/1/artworks/1/move_next';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, , Referer => '/artists/1/albums/1/show');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/1/albums/1/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/album coverfrontside moved next/', 'check move_next success notification');
    like($content, '/coverbackside.*<strong>album coverfrontside<\/strong>/s', 'child resource coverfrontside listed after coverbackside on parent page');
}

# Nested resource
# redirect_mode = 'show'
{
    my $path ='/artists/1/albums/1/lyrics/1/move_next';
    my $res = request($path);
    ok($res->is_error, "GET $path returns HTTP 404");
    $res = request(POST $path, Referer => '/artists/1/albums/1/lyrics/1/show');
    ok($res->is_redirect, "POST $path returns HTTP 302");
    my $uri = URI->new($res->header('location'));
    is($uri->path, '/artists/1/albums/1/lyrics/1/show', 'redirect location is correct');
    my $cookie = $res->header('Set-Cookie');
    my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
    like($content, '/lyric1 moved next/', 'check move_next success notification');
}

done_testing;

t/09_form.t  view on Meta::CPAN

my $schema = $c->model('DB')->schema;

ok(defined $schema, 'got a schema');
lives_ok(sub { $schema->deploy }, 'deploy schema');

# CREATE
{
    my $path ='/artists/create';
    my $res = request($path);
    ok($res->is_success, "$path returns HTTP 200");
    like($res->decoded_content, '/my_custom_field_label/s', q/added field with label 'my_custom_field_label' via $c->stash->{form_attrs_process}/);
    like($res->decoded_content, '/my_custom_name_label/s', q/label of field 'name' changed via $c->stash->{form_attrs_process}/);
}

done_testing;



( run in 0.328 second using v1.01-cache-2.11-cpan-26ccb49234f )