I wrote: > I think there are some problems in test t/cdbi-t/15-accessor-new.t ... > I also think there's a problem with find_or_create() and accessor_for(). > For starters there're no tests! But I haven't yet got a set of tests for > which I understand the results and which agree with the failure I'm > seeing in my application. They're similar to the one for search() I'll > post some tests when I have them.
OK. I've attached a patch to t/cdbi-t/15-accessor.t that does several things: (1) Fixes the way the arguments are built so the sheep argument is correct in the tests. (2) Adds explicit tests for the number of sheep so we can be sure which database record is actually returned. (3) Adds tests for find_or_create() with modified accessor names. (4) Fixes the test for search() to report all errors I still don't fully understand what's going on in the output below but I think they are genuine test failures. I'd appreciate it if somebody else could run the tests to make sure the results are not some artefact of my test environment. I also attached a copy of the modified test script so you don't even have to apply the patch first :) I don't know what the DestroyWarning at the end is all about. Thanks, Dave 1..75 ok 1 - Modified accessor - with column name ok 2 - The object isa Film ok 3 - sheep bursting violently ok 4 - No errors ok 5 - Modified accessor - with accessor ok 6 - The object isa Film ok 7 - sheep bursting violently ok 8 - No errors DBIx::Class::CDBICompat::Retrieve::find_or_create(): Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single at ../15-accessor-new.t line 80 ok 9 - find_or_create Modified accessor - find with column name ok 10 - The object isa Film ok 11 - sheep bursting violently ok 12 - No errors DBIx::Class::CDBICompat::Retrieve::find_or_create(): Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single at ../15-accessor-new.t line 90 ok 13 - find_or_create Modified accessor - find with accessor ok 14 - The object isa Film ok 15 - sheep bursting violently ok 16 - No errors DBIx::Class::CDBICompat::Retrieve::find_or_create(): Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single at ../15-accessor-new.t line 100 ok 17 - find_or_create Modified accessor - create with column name ok 18 - The object isa Film not ok 19 - sheep bursting violently # Failed test 'sheep bursting violently' # at ../15-accessor-new.t line 103. # got: '1' # expected: '3' ok 20 - No errors DBIx::Class::CDBICompat::Retrieve::find_or_create(): Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single at ../15-accessor-new.t line 110 ok 21 - find_or_create Modified accessor - create with accessor ok 22 - The object isa Film not ok 23 - sheep bursting violently # Failed test 'sheep bursting violently' # at ../15-accessor-new.t line 113. # got: '1' # expected: '4' ok 24 - No errors not ok 25 - No errors # Failed test 'No errors' # at ../15-accessor-new.t line 121. # got: 'DBIx::Class::CDBICompat::Relationships::search(): DBI Exception: DBD::SQLite::db prepare_cached failed: no such column: sheep(1) at dbdimp.c line 271 [for Statement "SELECT me.title FROM Movies me WHERE ( sheep = ? )"] at ../15-accessor-new.t line 118 # ' # expected: '' ok 26 - Modified mutator - with mutator ok 27 - The object isa Film ok 28 - No errors ok 29 - Modified mutator - with column name ok 30 - The object isa Film ok 31 - No errors ok 32 - Modified mutator - with accessor ok 33 - The object isa Film ok 34 - No errors ok 35 ok 36 - no hasa film ok 37 - hasa movie ok 38 - The object isa Film ok 39 - - Bad Taste ok 40 - No errors ok 41 - Can't locate object method "film" via package "Actor" at ../15-accessor-new.t line 173. # ok 42 - 'main' cannot alter the value of 'film' on objects of class 'Actor' at ../15-accessor-new.t line 176 # ok 43 - Set movie through hasa ok 44 - hasa movie ok 45 - The object isa Film ok 46 - - Another Film ok 47 - No problem ok 48 - a custom accessor without a custom mutator is setable ok 49 - nonpersistent is a column ok 50 - - but it's not real ok 51 - Title set OK ok 52 - As is non persistent value ok 53 - Re-retrieve film ok 54 - Title still OK ok 55 - Non persistent value gone ok 56 - Can set it ok 57 - And it's there again ok 58 - Commit the film ok 59 - And it's still there ok 60 - Actor has no specific essential columns ok 61 - nonpersistent is a column ok 62 - - but it's not real ok 63 - no problems retrieving actors ok 64 - The object isa Actor ok 65 - Can update Naked ok 66 - Make Naked read only ok 67 - Can't update Naked any more ok 68 - But can still update Secrets and Lies ok 69 - And can still create new films isa Film ok 70 - Make all Films read only ok 71 - Still can't update Naked ok 72 - And can't update S&L any more ok 73 - And can't delete 4 Days in July ok 74 - Or create new films # Looks like you planned 75 tests but only ran 74. # Looks like you failed 3 tests of 74 run. Film Film=HASH(0x8a15f2c) destroyed without saving changes to rating at blib/lib/DBIx/Class/CDBICompat/DestroyWarning.pm line 12 during global destruction.
--- t/cdbi-t/15-accessor.t 2008-11-17 02:48:57.000000000 +0000
+++ ../15-accessor-new.t 2008-11-19 14:15:49.000000000 +0000
@@ -8,7 +8,7 @@
next;
}
eval "use DBD::SQLite";
- plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 55);
+ plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 75);
}
INIT {
@@ -57,18 +57,60 @@
};
eval {
- my $data = $data;
+ my $data = { %$data };
$data->{NumExplodingSheep} = 1;
ok my $bt = Film->create($data), "Modified accessor - with column name";
isa_ok $bt, "Film";
+ is $bt->sheep, 1, 'sheep bursting violently';
};
is $@, '', "No errors";
eval {
- my $data = $data;
- $data->{sheep} = 1;
+ my $data = { %$data };
+ $data->{sheep} = 2;
ok my $bt = Film->create($data), "Modified accessor - with accessor";
isa_ok $bt, "Film";
+ is $bt->sheep, 2, 'sheep bursting violently';
+};
+is $@, '', "No errors";
+
+eval {
+ my $data = { %$data };
+ $data->{NumExplodingSheep} = 1;
+ ok my $bt = Film->find_or_create($data),
+ "find_or_create Modified accessor - find with column name";
+ isa_ok $bt, "Film";
+ is $bt->sheep, 1, 'sheep bursting violently';
+};
+is $@, '', "No errors";
+
+eval {
+ my $data = { %$data };
+ $data->{sheep} = 1;
+ ok my $bt = Film->find_or_create($data),
+ "find_or_create Modified accessor - find with accessor";
+ isa_ok $bt, "Film";
+ is $bt->sheep, 1, 'sheep bursting violently';
+};
+is $@, '', "No errors";
+
+eval {
+ my $data = { %$data };
+ $data->{NumExplodingSheep} = 3;
+ ok my $bt = Film->find_or_create($data),
+ "find_or_create Modified accessor - create with column name";
+ isa_ok $bt, "Film";
+ is $bt->sheep, 3, 'sheep bursting violently';
+};
+is $@, '', "No errors";
+
+eval {
+ my $data = { %$data };
+ $data->{sheep} = 4;
+ ok my $bt = Film->find_or_create($data),
+ "find_or_create Modified accessor - create with accessor";
+ isa_ok $bt, "Film";
+ is $bt->sheep, 4, 'sheep bursting violently';
};
is $@, '', "No errors";
@@ -76,6 +118,7 @@
my @film = Film->search({ sheep => 1 });
is @film, 2, "Can search with modified accessor";
};
+is $@, '', "No errors";
{
15-accessor-new.t
Description: Troff document
_______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/[email protected]
