removed perl 5.6.0 requirement from test files
[catagits/Catalyst-Controller-DBIC-API.git] / t / rest / delete.t
CommitLineData
d2739840 1use strict;
2use warnings;
3
4use lib 't/lib';
5
6my $base = 'http://localhost';
7my $content_type = [ 'Content-Type', 'application/x-www-form-urlencoded' ];
8
9use RestTest;
10use DBICTest;
a1f71064 11use Test::More;
d2739840 12use Test::WWW::Mechanize::Catalyst 'RestTest';
a1f71064 13use HTTP::Request::Common qw/ DELETE /;
0b0bf911 14use JSON;
15
16my $json = JSON->new->utf8;
d2739840 17
18my $mech = Test::WWW::Mechanize::Catalyst->new;
0b0bf911 19ok( my $schema = DBICTest->init_schema(), 'got schema' );
d2739840 20
0b0bf911 21my $track = $schema->resultset('Track')->first;
d2739840 22my %original_cols = $track->get_columns;
23
0b0bf911 24my $track_url = "$base/api/rest/track/";
a1f71064 25my $track_delete_url = $track_url . $track->id;
d2739840 26
27{
0b0bf911 28 my $req = HTTP::Request->new( DELETE => $track_delete_url );
29 $req->content_type('text/x-json');
30 $mech->request($req);
31 cmp_ok( $mech->status, '==', 200, 'Attempt to delete track ok' );
d2739840 32
0b0bf911 33 my $deleted_track = $schema->resultset('Track')->find( $track->id );
34 is( $deleted_track, undef, 'track deleted' );
d2739840 35}
36
37{
0b0bf911 38 my $req = HTTP::Request->new( DELETE => $track_delete_url );
39 $req->content_type('text/x-json');
40 $mech->request($req);
41 cmp_ok( $mech->status, '==', 400, 'Attempt to delete again caught' );
d2739840 42}
a1f71064 43
44{
0b0bf911 45 my $track_cnt = $schema->resultset('Track')->count;
46 my $tracks_rs =
47 $schema->resultset('Track')
48 ->search( undef, { select => ['trackid'], as => ['id'], rows => 3 } );
49 $tracks_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
50 my $test_data = $json->encode( { list => [ $tracks_rs->all ] } );
51 my $req = DELETE( $track_url, Content => $test_data );
52 $req->content_type('text/x-json');
53 $mech->request($req);
54 cmp_ok( $mech->status, '==', 200, 'Attempt to delete three tracks ok' );
55
56 is( $schema->resultset('Track')->count + 3,
57 $track_cnt, 'Three tracks deleted' );
a1f71064 58}
59
60done_testing();