[Catalyst-commits] r9129 - in
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch: .
lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API
t/lib/RestTest/Controller/API/REST t/rest t/rpc t/var
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Tue Jan 27 23:26:12 GMT 2009
Author: lukes
Date: 2009-01-27 23:26:12 +0000 (Tue, 27 Jan 2009)
New Revision: 9129
Modified:
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/Changes
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API.pm
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/lib/RestTest/Controller/API/REST/Artist.pm
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t
Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/var/DBIxClass.db
Log:
patch applied
Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/Changes 2009-01-27 23:24:58 UTC (rev 9128)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/Changes 2009-01-27 23:26:12 UTC (rev 9129)
@@ -1,5 +1,9 @@
Revision history for Catalyst-Controller-DBIC-API
+1.00199_01
+- Removed duplicate tests in t/rpc/list.t and t/rest/list.t
+- Added tests for searches on columns which have a rel with the same name
+ and vice versa
1.001000
- Added setup_list_method configuration flag (jshirley)
- Added support for setting config params in stash
Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-01-27 23:24:58 UTC (rev 9128)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-01-27 23:26:12 UTC (rev 9129)
@@ -45,6 +45,7 @@
sub generate_dbic_search_args :Private {
my ($self, $c) = @_;
+ # FIXME: expand_hash isn't called although it should have been
my $req_params = (grep { ref $_ } values %{$c->req->params}) ? $c->req->params : $self->expand_hash($c->req->params);
if ( my $a = $self->setup_list_method ) {
@@ -74,18 +75,32 @@
my ($self, $p) = @_;
my $params = $p->{params};
my $source = $p->{source};
- my $base = $p->{base};
+ my $base = $p->{base} || 'me';
my $join = {};
+ # FIXME: detect params which might belong to a column and relationship
+ # with the same name
+ my %search_params = map { ($base) ? join('.', $base, $_) : $_ => $params->{$_} } grep {
+ exists $params->{$_}
+ # this check breaks so called 'complex searches'(column.LIKE=%foo%)
+ # in the test suite but makes sure that searches on a rel aren't
+ # added as column search params
+ && not ref $params->{$_}
+ } $source->columns;
+
+
my %search_params = map { ($base) ? join('.', $base, $_) : $_ => $params->{$_} } grep { exists $params->{$_} } $source->columns;
foreach my $rel ($source->relationships) {
- if (exists $params->{$rel}) {
+ next if grep { warn $_; $rel eq $_ } $source->columns;
+ # fixes a search on a column which has a relationship with the same name
+ if (exists $params->{$rel} && ref $params->{$rel}) {
my $rel_params;
($rel_params, $join->{$rel}) = $self->_format_search({ params => $params->{$rel}, source => $source->related_source($rel), base => $rel });
%search_params = ( %search_params, %{$rel_params} );
}
}
+ use Data::Dumper; warn Dumper(\%search_params);
return (\%search_params, $join);
}
@@ -166,7 +181,7 @@
my %requires_map = map { $_ => 1 } @{($object->in_storage) ? [] : $c->stash->{create_requires} || $self->create_requires};
my %allows_map = map { (ref $_) ? %{$_} : ($_ => 1) } (keys %requires_map, @{($object->in_storage) ? ($c->stash->{update_allows} || $self->update_allows) : ($c->stash->{create_allows} || $self->create_allows)});
-# use Data::Dumper; warn Dumper($params, \%requires_map, \%allows_map);
+ use Data::Dumper; warn Dumper($params, \%requires_map, \%allows_map);
foreach my $key (keys %allows_map) {
# check value defined if key required
my $allowed_fields = $allows_map{$key};
Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API.pm 2009-01-27 23:24:58 UTC (rev 9128)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API.pm 2009-01-27 23:26:12 UTC (rev 9129)
@@ -9,7 +9,7 @@
=cut
-our $VERSION = '1.001000';
+our $VERSION = '1.00199_01';
=head1 NAME
Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/lib/RestTest/Controller/API/REST/Artist.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/lib/RestTest/Controller/API/REST/Artist.pm 2009-01-27 23:24:58 UTC (rev 9128)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/lib/RestTest/Controller/API/REST/Artist.pm 2009-01-27 23:26:12 UTC (rev 9129)
@@ -10,7 +10,8 @@
class => 'RestTestDB::Artist',
create_requires => ['name'],
create_allows => ['name'],
- update_allows => ['name']
+ update_allows => ['name'],
+ default => 'text/xml',
);
1;
Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t 2009-01-27 23:24:58 UTC (rev 9128)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t 2009-01-27 23:26:12 UTC (rev 9129)
@@ -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,12 +29,12 @@
}, 'Accept' => 'text/x-json' );
$mech->request($req);
cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
-
+ warn $mech->content;exit;
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' );
}
-
+exit;
{
my $uri = URI->new( $artist_list_url );
$uri->query_form({ 'search.artistid' => 1 });
@@ -49,18 +49,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/branches/abraxxa_patch/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t 2009-01-27 23:24:58 UTC (rev 9128)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t 2009-01-27 23:26:12 UTC (rev 9129)
@@ -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' );
+}
Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/var/DBIxClass.db
===================================================================
(Binary files differ)
More information about the Catalyst-commits
mailing list