[Catalyst-commits] r9148 - in
Catalyst-Controller-DBIC-API/1.001/trunk:
lib/Catalyst/Controller/DBIC/API t/rest t/rpc
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Fri Jan 30 14:39:05 GMT 2009
Author: lukes
Date: 2009-01-30 14:39:05 +0000 (Fri, 30 Jan 2009)
New Revision: 9148
Modified:
Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
Catalyst-Controller-DBIC-API/1.001/trunk/t/rest/list.t
Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t
Log:
failing test from abraxxa and fix for it
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-01-30 10:42:34 UTC (rev 9147)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-01-30 14:39:05 UTC (rev 9148)
@@ -79,6 +79,15 @@
my $join = {};
my %search_params = map { ($base) ? join('.', $base, $_) : $_ => $params->{$_} } grep { exists $params->{$_} } $source->columns;
foreach my $rel ($source->relationships) {
+ # if column and relationship have the same name, go with the relationship
+ # so long as the value is a reference, otherwise go with the column
+ if (my $val = $search_params{$rel}) {
+ if (ref $val) {
+ delete $search_params{$rel};
+ } else {
+ next;
+ }
+ }
if (exists $params->{$rel}) {
my $rel_params;
($rel_params, $join->{$rel}) = $self->_format_search({ params => $params->{$rel}, source => $source->related_source($rel), base => $rel });
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/t/rest/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/t/rest/list.t 2009-01-30 10:42:34 UTC (rev 9147)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/t/rest/list.t 2009-01-30 14:39:05 UTC (rev 9148)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More tests => 15;
+use Test::More tests => 13;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -29,7 +29,6 @@
}, 'Accept' => 'text/x-json' );
$mech->request($req);
cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
-
my @expected_response = map { { $_->get_columns } } $schema->resultset('Artist')->all;
my $response = JSON::Syck::Load( $mech->content);
is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct message returned' );
@@ -49,18 +48,6 @@
{
my $uri = URI->new( $artist_list_url );
- $uri->query_form({ 'search.artistid' => 1 });
- my $req = GET( $uri, 'Accept' => 'text/x-json' );
- $mech->request($req);
- cmp_ok( $mech->status, '==', 200, 'attempt with basic search okay' );
-
- my @expected_response = map { { $_->get_columns } } $schema->resultset('Artist')->search({ artistid => 1 })->all;
- my $response = JSON::Syck::Load( $mech->content);
- is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned' );
-}
-
-{
- my $uri = URI->new( $artist_list_url );
$uri->query_form({ 'search.name.LIKE' => '%waul%' });
my $req = GET( $uri, 'Accept' => 'text/x-json' );
$mech->request($req);
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t 2009-01-30 10:42:34 UTC (rev 9147)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t 2009-01-30 14:39:05 UTC (rev 9148)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More tests => 19;
+use Test::More qw(no_plan);
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -21,6 +21,7 @@
my $artist_list_url = "$base/api/rpc/artist/list";
my $producer_list_url = "$base/api/rpc/producer/list";
my $track_list_url = "$base/api/rpc/track/list";
+my $cd_list_url = "$base/api/rpc/cd/list";
# test open request
{
@@ -49,18 +50,6 @@
{
my $uri = URI->new( $artist_list_url );
- $uri->query_form({ 'search.artistid' => 1 });
- my $req = GET( $uri, 'Accept' => 'text/x-json' );
- $mech->request($req);
- cmp_ok( $mech->status, '==', 200, 'attempt with basic search okay' );
-
- my @expected_response = map { { $_->get_columns } } $schema->resultset('Artist')->search({ artistid => 1 })->all;
- my $response = JSON::Syck::Load( $mech->content);
- is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned' );
-}
-
-{
- my $uri = URI->new( $artist_list_url );
$uri->query_form({ 'search.name.LIKE' => '%waul%' });
my $req = GET( $uri, 'Accept' => 'text/x-json' );
$mech->request($req);
@@ -135,3 +124,29 @@
# use Data::Dumper; warn Dumper($response, \@expected_response);
is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned when everything overridden in query' );
}
+
+{
+ my $uri = URI->new( $cd_list_url );
+ $uri->query_form({ 'search.artist.name' => 'Caterwauler McCrae' });
+ my $req = GET( $uri, 'Accept' => 'text/x-json' );
+ $mech->request($req);
+ if (cmp_ok( $mech->status, '==', 200, 'search on rel with same name column request okay' )) {
+ my @expected_response = map { { $_->get_columns } } $schema->resultset('CD')->search({'me.artist' => 1})->all;
+ my $response = JSON::Syck::Load( $mech->content);
+ #use Data::Dumper; warn Dumper($response, \@expected_response);
+ is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for search on rel with same name column' );
+ }
+}
+
+{
+ my $uri = URI->new( $cd_list_url );
+ $uri->query_form({ 'search.artist' => 1 });
+ my $req = GET( $uri, 'Accept' => 'text/x-json' );
+ $mech->request($req);
+ cmp_ok( $mech->status, '==', 200, 'search on column with same name rel request okay' );
+
+ my @expected_response = map { { $_->get_columns } } $schema->resultset('CD')->search({'me.artist' => 1})->all;
+ my $response = JSON::Syck::Load( $mech->content);
+ #use Data::Dumper; warn Dumper($response, \@expected_response);
+ is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for search on column with same name rel' );
+}
More information about the Catalyst-commits
mailing list