[Catalyst-commits] r9292 - in
Catalyst-Controller-DBIC-API/1.001/branches/json_search: .
lib/Catalyst/Controller/DBIC/API t/rpc
abraxxa at dev.catalyst.perl.org
abraxxa at dev.catalyst.perl.org
Fri Feb 13 16:09:59 GMT 2009
Author: abraxxa
Date: 2009-02-13 16:09:59 +0000 (Fri, 13 Feb 2009)
New Revision: 9292
Modified:
Catalyst-Controller-DBIC-API/1.001/branches/json_search/Changes
Catalyst-Controller-DBIC-API/1.001/branches/json_search/Makefile.PL
Catalyst-Controller-DBIC-API/1.001/branches/json_search/lib/Catalyst/Controller/DBIC/API/Base.pm
Catalyst-Controller-DBIC-API/1.001/branches/json_search/t/rpc/list.t
Log:
Removed duplicate tests in t/rpc/list.t and t/rest/list.t
Fixed searches on columns which have a rel with the same name and vice versa + tests
Added search by json + test
Modified: Catalyst-Controller-DBIC-API/1.001/branches/json_search/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/json_search/Changes 2009-02-13 15:58:50 UTC (rev 9291)
+++ Catalyst-Controller-DBIC-API/1.001/branches/json_search/Changes 2009-02-13 16:09:59 UTC (rev 9292)
@@ -1,5 +1,10 @@
Revision history for Catalyst-Controller-DBIC-API
+1.00199_01
+- Removed duplicate tests in t/rpc/list.t and t/rest/list.t
+- Fixed searches on columns which have a rel with the same name
+ and vice versa + tests
+- Added search by json + test
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/json_search/Makefile.PL
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/json_search/Makefile.PL 2009-02-13 15:58:50 UTC (rev 9291)
+++ Catalyst-Controller-DBIC-API/1.001/branches/json_search/Makefile.PL 2009-02-13 16:09:59 UTC (rev 9292)
@@ -8,6 +8,7 @@
requires 'Catalyst::Runtime' => 5.7010;
requires 'Catalyst::Action::REST' => 0.60;
requires 'CGI::Expand' => 2.02;
+requires 'JSON::Any' => 1.19;
build_requires 'Test::More' => 0.7;
build_requires 'Catalyst::Model::DBIC::Schema' => 0.20;
Modified: Catalyst-Controller-DBIC-API/1.001/branches/json_search/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/json_search/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-02-13 15:58:50 UTC (rev 9291)
+++ Catalyst-Controller-DBIC-API/1.001/branches/json_search/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-02-13 16:09:59 UTC (rev 9292)
@@ -6,6 +6,7 @@
use base qw/Catalyst::Controller CGI::Expand/;
use DBIx::Class::ResultClass::HashRefInflator;
+use JSON::Any;
__PACKAGE__->mk_accessors(qw(
class create_requires update_requires update_allows $self->rs_stash_key create_allows list_count list_returns list_grouped_by list_ordered_by rs_stash_key object_stash_key setup_list_method
@@ -55,8 +56,16 @@
my $source = $c->stash->{$self->rs_stash_key}->result_source;
my ($params, $join);
- ($params, $join) = $self->_format_search({ params => $req_params->{search}, source => $source }) if ($req_params->{search});
my $args = {};
+ if (exists $req_params->{search}
+ && ref $req_params->{search} eq 'HASH'
+ ) {
+ ($params, $join) = $self->_format_search({ params => $req_params->{search}, source => $source }) if ($req_params->{search});
+ }
+ # assume json if search wasn't expanded by expand_hash
+ else {
+ $params = exists $c->req->params->{search} ? JSON::Any->from_json($c->req->params->{search}) : undef;
+ }
$args->{group_by} = $req_params->{list_grouped_by} || ((scalar(@{$self->list_grouped_by})) ? $self->list_grouped_by : undef);
$args->{order_by} = $req_params->{list_ordered_by} || ((scalar(@{$self->list_ordered_by})) ? $self->list_ordered_by : undef);
$args->{rows} = $req_params->{list_count} || $self->list_count;
Modified: Catalyst-Controller-DBIC-API/1.001/branches/json_search/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/json_search/t/rpc/list.t 2009-02-13 15:58:50 UTC (rev 9291)
+++ Catalyst-Controller-DBIC-API/1.001/branches/json_search/t/rpc/list.t 2009-02-13 16:09:59 UTC (rev 9292)
@@ -61,6 +61,18 @@
}
{
+ 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);
+ cmp_ok( $mech->status, '==', 200, 'attempt with basic search okay' );
+
+ my @expected_response = map { { $_->get_columns } } $schema->resultset('Artist')->search({ name => { LIKE => '%waul%' }})->all;
+ my $response = JSON::Syck::Load( $mech->content);
+ is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for complex query' );
+}
+
+{
my $uri = URI->new( $producer_list_url );
my $req = GET( $uri, 'Accept' => 'text/x-json' );
$mech->request($req);
More information about the Catalyst-commits
mailing list