added REST and RPC update_bulk tests
Alexander Hartmaier [Sun, 8 Aug 2010 10:52:46 +0000 (12:52 +0200)]
Changes
t/rest/update.t
t/rpc/update.t

diff --git a/Changes b/Changes
index 02186cd..ff86a72 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@ Revision history for Catalyst-Controller-DBIC-API: {{ $dist->version }}
 
 - Added REST and RPC delete_bulk tests
 - Fixed RPC delete_bulk not working at all
+- Added REST and RPC update_bulk tests
 
 2.002002  2010-08-03 14:40:50 Europe/Vienna
 
index 49f0051..263ba40 100644 (file)
@@ -10,7 +10,7 @@ my $content_type = [ 'Content-Type', 'application/x-www-form-urlencoded' ];
 
 use RestTest;
 use DBICTest;
-use Test::More tests => 16;
+use Test::More;
 use Test::WWW::Mechanize::Catalyst 'RestTest';
 use HTTP::Request::Common;
 use JSON::Any;
@@ -21,7 +21,9 @@ ok(my $schema = DBICTest->init_schema(), 'got schema');
 my $track = $schema->resultset('Track')->first;
 my %original_cols = $track->get_columns;
 
-my $track_update_url = "$base/api/rest/track/" . $track->id;
+my $track_url = "$base/api/rest/track/";
+my $track_update_url = $track_url . $track->id;
+my $tracks_update_url = $track_url;
 
 # test invalid track id caught
 {
@@ -82,3 +84,20 @@ my $track_update_url = "$base/api/rest/track/" . $track->id;
        is($track->title, 'monkey monkey', 'Title changed to "monkey monkey"');
        is($track->cd->year, 2009, 'related row updated');
 }
+
+{
+  # order to get a stable order of rows
+  my $tracks_rs = $schema->resultset('Track')->search(undef, { order_by => 'trackid', rows => 3 });
+  my $test_data = JSON::Any->Dump({ list => [map +{ id => $_->id, title => 'Track ' . $_->id }, $tracks_rs->all] });
+  my $req = PUT( $tracks_update_url, Content => $test_data );
+  $req->content_type('text/x-json');
+  $mech->request($req);
+  cmp_ok( $mech->status, '==', 200, 'Attempt to update three tracks ok' );
+
+  $tracks_rs->reset;
+  while (my $track = $tracks_rs->next) {
+    is($track->title, 'Track ' . $track->id, 'Title changed');
+  }
+}
+
+done_testing();
index dc68881..80d12d1 100644 (file)
@@ -23,6 +23,7 @@ my %original_cols = $track->get_columns;
 
 my $track_update_url = "$base/api/rpc/track/id/" . $track->id . "/update";
 my $any_track_update_url = "$base/api/rpc/any/track/id/" . $track->id . "/update";
+my $tracks_update_url = "$base/api/rpc/track/update";
 
 # test invalid track id caught
 {
@@ -130,4 +131,19 @@ my $any_track_update_url = "$base/api/rpc/any/track/id/" . $track->id . "/update
   is($track->get_column('position'), '14', 'Position changed');
 }
 
+{
+  # order to get a stable order of rows
+  my $tracks_rs = $schema->resultset('Track')->search(undef, { order_by => 'trackid', rows => 3 });
+  my $test_data = JSON::Any->Dump({ list => [map +{ id => $_->id, title => 'Track ' . $_->id }, $tracks_rs->all] });
+  my $req = POST( $tracks_update_url, Content => $test_data );
+  $req->content_type('text/x-json');
+  $mech->request($req);
+  cmp_ok( $mech->status, '==', 200, 'Attempt to update three tracks ok' );
+
+  $tracks_rs->reset;
+  while (my $track = $tracks_rs->next) {
+    is($track->title, 'Track ' . $track->id, 'Title changed');
+  }
+}
+
 done_testing();