From: Peter Rabbitson Date: Sun, 2 Nov 2008 16:55:31 +0000 (+0000) Subject: Test prompted by discussion about tasty stuff X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cda5e0825360a15f97520dae86864b68ac90d5f5;p=dbsrgits%2FDBIx-Class-Historic.git Test prompted by discussion about tasty stuff --- diff --git a/t/88result_set_column.t b/t/88result_set_column.t index a039cc1..52221f9 100644 --- a/t/88result_set_column.t +++ b/t/88result_set_column.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 11; +plan tests => 14; my $cd; my $rs = $cd = $schema->resultset("CD")->search({}); @@ -50,3 +50,11 @@ ok(defined($psrs->get_column('addedtitle')), '+select/+as title'); my $rsc = $rs->get_column('year'); is( $rsc->{_parent_resultset}->{attrs}->{prefetch}, undef, 'prefetch wiped' ); } + +# test sum() +is ($schema->resultset('BooksInLibrary')->get_column ('price')->sum, 125, 'Sum of a resultset works correctly'); + +# test sum over search_related +my $owner = $schema->resultset('Owners')->find ({ name => 'Newton' }); +ok ($owner->books->count > 1, 'Owner Newton has multiple books'); +is ($owner->search_related ('books')->get_column ('price')->sum, 60, 'Correctly calculated price of all owned books'); diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 2b6312c..e4b9b76 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -315,10 +315,10 @@ sub populate_schema { ]); $schema->populate('BooksInLibrary', [ - [ qw/id owner title source/ ], - [ 1, 1, "Programming Perl", "Library" ], - [ 2, 1, "Dynamical Systems", "Library" ], - [ 3, 2, "Best Recipe Cookbook", "Library" ], + [ qw/id owner title source price/ ], + [ 1, 1, "Programming Perl", "Library", 23 ], + [ 2, 1, "Dynamical Systems", "Library", 37 ], + [ 3, 2, "Best Recipe Cookbook", "Library", 65 ], ]); } diff --git a/t/lib/DBICTest/Schema/BooksInLibrary.pm b/t/lib/DBICTest/Schema/BooksInLibrary.pm index ba6f94d..6c2d6aa 100644 --- a/t/lib/DBICTest/Schema/BooksInLibrary.pm +++ b/t/lib/DBICTest/Schema/BooksInLibrary.pm @@ -20,6 +20,10 @@ __PACKAGE__->add_columns( data_type => 'varchar', size => '100', }, + 'price' => { + data_type => 'integer', + is_nullable => 1, + }, ); __PACKAGE__->set_primary_key('id'); diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 4caf314..350398c 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,6 +1,6 @@ -- -- Created by SQL::Translator::Producer::SQLite --- Created on Fri Oct 24 21:31:55 2008 +-- Created on Sun Nov 2 15:27:04 2008 -- BEGIN TRANSACTION; @@ -44,7 +44,8 @@ CREATE TABLE books ( id INTEGER PRIMARY KEY NOT NULL, source varchar(100) NOT NULL, owner integer NOT NULL, - title varchar(100) NOT NULL + title varchar(100) NOT NULL, + price integer );