X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F72pg.t;h=1f7312ba63e956b48f5e513d8d0fbd6b95a402ac;hb=e46df41a7023dc31ac5eba4bc81c050d7964d3be;hp=f9f61c47d6683d0f85554eb4c71129063e8b7bf8;hpb=a780a0ff7c99dd9b640f8c29ad0466bd0c907bf3;p=dbsrgits%2FDBIx-Class.git diff --git a/t/72pg.t b/t/72pg.t index f9f61c4..1f7312b 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -198,7 +198,7 @@ for my $use_insert_returning ($test_server_supports_insert_returning use strict; use warnings; - use base 'DBIx::Class::Core'; + use base 'DBICTest::BaseResult'; __PACKAGE__->table('dbic_t_schema.array_test'); __PACKAGE__->add_columns(qw/id arrayfield/); @@ -209,43 +209,96 @@ for my $use_insert_returning ($test_server_supports_insert_returning SKIP: { skip "Need DBD::Pg 2.9.2 or newer for array tests", 4 if $DBD::Pg::VERSION < 2.009002; + my $arr_rs = $schema->resultset('ArrayTest'); + lives_ok { - $schema->resultset('ArrayTest')->create({ + $arr_rs->create({ arrayfield => [1, 2], }); } 'inserting arrayref as pg array data'; lives_ok { - $schema->resultset('ArrayTest')->update({ + $arr_rs->update({ arrayfield => [3, 4], }); } 'updating arrayref as pg array data'; - $schema->resultset('ArrayTest')->create({ + $arr_rs->create({ arrayfield => [5, 6], }); - my $afield_rs = $schema->resultset('ArrayTest')->search({ - arrayfield => \[ '= ?' => [arrayfield => [3, 4]] ], #Todo anything less ugly than this? - }); + lives_ok { + $schema->populate('ArrayTest', [ + [ qw/arrayfield/ ], + [ [0,0] ], + ]); + } 'inserting arrayref using void ctx populate'; + + # Search using arrays + lives_ok { + is_deeply ( + $arr_rs->search({ arrayfield => { -value => [3,4] } })->first->arrayfield, + [3,4], + 'Array value matches' + ); + } 'searching by arrayref'; + + lives_ok { + is_deeply ( + $arr_rs->search({ arrayfield => { '=' => { -value => [3,4] }} })->first->arrayfield, + [3,4],, + 'Array value matches explicit equal' + ); + } 'searching by arrayref (explicit equal sign)'; - my $count; lives_ok { - $count = $afield_rs->count - } 'comparing arrayref to pg array data does not blow up'; - is($count, 1, 'comparing arrayref to pg array data gives correct result'); + is_deeply ( + $arr_rs->search({ arrayfield => { '>' => { -value => [3,1] }} })->first->arrayfield, + [3,4], + 'Array value matches greater than' + ); + } 'searching by arrayref (greater than)'; - TODO: { - local $TODO = 'No introspection of scalarref conditions :('; - my $row = $afield_rs->create({}); + lives_ok { + is ( + $arr_rs->search({ arrayfield => { '>' => { -value => [3,7] }} })->count, + 1, + 'Greater than search found [5,6]', + ); + } 'searching by arrayref (greater than)'; + + # Find using arrays + lives_ok { + is_deeply ( + $arr_rs->find({ arrayfield => { -value => [3,4] } })->arrayfield, + [3,4], + 'Array value matches implicit equal' + ); + } 'find by arrayref'; + + lives_ok { + is_deeply ( + $arr_rs->find({ arrayfield => { '=' => { -value => [3,4] }} })->arrayfield, + [3,4], + 'Array value matches explicit equal' + ); + } 'find by arrayref (equal)'; + + # test inferred condition for creation + TODO: for my $cond ( + { -value => [3,4] }, + \[ '= ?' => [arrayfield => [3, 4]] ], + ) { + local $TODO = 'No introspection of complex conditions :('; + my $arr_rs_cond = $arr_rs->search({ arrayfield => $cond }); + + my $row = $arr_rs_cond->create({}); is_deeply ($row->arrayfield, [3,4], 'Array value taken from $rs condition'); $row->discard_changes; is_deeply ($row->arrayfield, [3,4], 'Array value made it to storage'); } } - - ########## Case check BEGIN { @@ -441,8 +494,7 @@ CREATE TABLE dbic_t_schema.track ( position int, title varchar(255), last_updated_on date, - last_updated_at date, - small_dt date + last_updated_at date ) EOS @@ -517,12 +569,12 @@ sub drop_test_schema { for my $stat ( 'DROP SCHEMA dbic_t_schema_5 CASCADE', - 'DROP SEQUENCE public.artist_artistid_seq', + 'DROP SEQUENCE public.artist_artistid_seq CASCADE', 'DROP SCHEMA dbic_t_schema_4 CASCADE', 'DROP SCHEMA dbic_t_schema CASCADE', - 'DROP SEQUENCE pkid1_seq', - 'DROP SEQUENCE pkid2_seq', - 'DROP SEQUENCE nonpkid_seq', + 'DROP SEQUENCE pkid1_seq CASCADE', + 'DROP SEQUENCE pkid2_seq CASCADE', + 'DROP SEQUENCE nonpkid_seq CASCADE', 'DROP SCHEMA dbic_t_schema_2 CASCADE', 'DROP SCHEMA dbic_t_schema_3 CASCADE', ) {