@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t --- Koha/REST/Plugin/Objects.pm | 4 ++- t/db_dependent/Koha/REST/Plugin/Objects.t | 36 ++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) --- a/Koha/REST/Plugin/Objects.pm +++ a/Koha/REST/Plugin/Objects.pm @@ -51,6 +51,8 @@ sub register { # Extract reserved params my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args); + # Look for embeds + my $embed = $c->stash('koha.embed'); # Merge sorting into query attributes $c->dbic_merge_sorting( @@ -87,7 +89,7 @@ sub register { }); } - return $objects->to_api; + return $objects->to_api({ embed => $embed }); } ); } --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ a/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -16,6 +16,8 @@ # along with Koha; if not, see . use Modern::Perl; + +use Koha::Acquisition::Orders; use Koha::Cities; # Dummy app for testing the plugin @@ -34,24 +36,30 @@ get '/cities' => sub { $c->render( status => 200, json => $cities ); }; +get '/orders' => sub { + my $c = shift; + $c->stash('koha.embed', ( { fund => {} } ) ); + $c->validation->output($c->req->params->to_hash); + my $orders = $c->objects->search(Koha::Acquisition::Orders->new); + $c->render( status => 200, json => $orders ); +}; + # The tests -use Test::More tests => 2; +use Test::More tests => 3; use Test::Mojo; use t::lib::TestBuilder; use Koha::Database; -my $schema = Koha::Database->new()->schema(); - +my $t = Test::Mojo->new; +my $schema = Koha::Database->new()->schema(); my $builder = t::lib::TestBuilder->new; subtest 'objects.search helper' => sub { plan tests => 34; - my $t = Test::Mojo->new; - $schema->storage->txn_begin; # Remove existing cities to have more control on the search restuls @@ -128,8 +136,6 @@ subtest 'objects.search helper, sorting on mapped column' => sub { plan tests => 14; - my $t = Test::Mojo->new; - $schema->storage->txn_begin; # Have complete control over the existing cities to ease testing @@ -155,4 +161,18 @@ subtest 'objects.search helper, sorting on mapped column' => sub { ->json_is('/1/name' => 'A'); $schema->storage->txn_rollback; -} +}; + +subtest 'objects.search helper, embed' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $order = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); + + $t->get_ok('/orders?order_id=' . $order->ordernumber) + ->json_is('/0',$order->to_api({ embed => ( { fund => {} } ) })); + + $schema->storage->txn_rollback; +}; --