Merge in object_split functionality
[catagits/Catalyst-Controller-DBIC-API.git] / t / rest / delete.t
1 use 5.6.0;
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7
8 my $base = 'http://localhost';
9 my $content_type = [ 'Content-Type', 'application/x-www-form-urlencoded' ];
10
11 use RestTest;
12 use DBICTest;
13 use Test::More tests => 4;
14 use Test::WWW::Mechanize::Catalyst 'RestTest';
15 use HTTP::Request::Common;
16
17 my $mech = Test::WWW::Mechanize::Catalyst->new;
18 ok(my $schema = DBICTest->init_schema(), 'got schema');
19
20 my $track = $schema->resultset('Track')->first;
21 my %original_cols = $track->get_columns;
22
23 my $track_delete_url = "$base/api/rest/track/" . $track->id;
24
25 {
26   my $req = HTTP::Request->new( DELETE => $track_delete_url );
27   $req->content_type('text/x-json');
28   $mech->request($req);
29   cmp_ok( $mech->status, '==', 200, 'Attempt to delete track ok' );
30
31   my $deleted_track = $schema->resultset('Track')->find($track->id);
32   is($deleted_track, undef, 'track deleted');
33 }
34
35 {
36   my $req = HTTP::Request->new( DELETE => $track_delete_url );
37   $req->content_type('text/x-json');
38   $mech->request($req);
39   cmp_ok( $mech->status, '==', 400, 'Attempt to delete again caught' );
40 }