[Bast-commits] r5549 - in DBIx-Class/0.08/trunk: . t
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Fri Feb 20 04:31:50 GMT 2009
Author: matthewt
Date: 2009-02-20 04:31:50 +0000 (Fri, 20 Feb 2009)
New Revision: 5549
Added:
DBIx-Class/0.08/trunk/t/96multi_create_torture.t
Modified:
DBIx-Class/0.08/trunk/
DBIx-Class/0.08/trunk/t/96multi_create.t
Log:
r27529 at agaton (orig r5341): ribasushi | 2009-01-24 18:28:29 +0000
small refactor
Property changes on: DBIx-Class/0.08/trunk
___________________________________________________________________
Name: svk:merge
- 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/resultsetcolumn_custom_columns:5160
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5414
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/trunk:5635
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_trunk:10772
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/belongs_to_null_col_fix:5244
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sqla_1.50_compat:5321
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/subquery:5535
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
+ 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/resultsetcolumn_custom_columns:5160
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5414
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/trunk:5635
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_trunk:10772
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/belongs_to_null_col_fix:5244
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/multi_stuff:5341
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sqla_1.50_compat:5321
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/subquery:5535
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
Modified: DBIx-Class/0.08/trunk/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/trunk/t/96multi_create.t 2009-02-20 04:31:32 UTC (rev 5548)
+++ DBIx-Class/0.08/trunk/t/96multi_create.t 2009-02-20 04:31:50 UTC (rev 5549)
@@ -6,7 +6,7 @@
use lib qw(t/lib);
use DBICTest;
-plan tests => 89;
+plan tests => 70;
my $schema = DBICTest->init_schema();
@@ -475,217 +475,4 @@
is ($m2m_cd->first->producers->first->name, 'Cowboy Neal', 'Correct producer row created');
};
-# and some insane multicreate
-# (should work, despite the fact that no one will probably use it this way)
-
-# first count how many rows do we initially have
-my $counts;
-$counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Genre Producer Tag/;
-
-# do the crazy create
-eval {
- $schema->resultset('CD')->create ({
- artist => {
- name => 'james',
- },
- title => 'Greatest hits 1',
- year => '2012',
- genre => {
- name => '"Greatest" collections',
- },
- tags => [
- { tag => 'A' },
- { tag => 'B' },
- ],
- cd_to_producer => [
- {
- producer => {
- name => 'bob',
- producer_to_cd => [
- {
- cd => {
- artist => {
- name => 'lars',
- cds => [
- {
- title => 'Greatest hits 2',
- year => 2012,
- genre => {
- name => '"Greatest" collections',
- },
- tags => [
- { tag => 'A' },
- { tag => 'B' },
- ],
- # This cd is created via artist so it doesn't know about producers
- cd_to_producer => [
- # if we specify 'bob' here things bomb
- # as the producer attached to Greatest Hits 1 is
- # already created, but not yet inserted.
- # Maybe this can be fixed, but things are hairy
- # enough already.
- #
- #{ producer => { name => 'bob' } },
- { producer => { name => 'paul' } },
- { producer => {
- name => 'flemming',
- producer_to_cd => [
- { cd => {
- artist => {
- name => 'kirk',
- cds => [
- {
- title => 'Greatest hits 3',
- year => 2012,
- genre => {
- name => '"Greatest" collections',
- },
- tags => [
- { tag => 'A' },
- { tag => 'B' },
- ],
- },
- {
- title => 'Greatest hits 4',
- year => 2012,
- genre => {
- name => '"Greatest" collections2',
- },
- tags => [
- { tag => 'A' },
- { tag => 'B' },
- ],
- },
- ],
- },
- title => 'Greatest hits 5',
- year => 2013,
- genre => {
- name => '"Greatest" collections2',
- },
- }},
- ],
- }},
- ],
- },
- ],
- },
- title => 'Greatest hits 6',
- year => 2012,
- genre => {
- name => '"Greatest" collections',
- },
- tags => [
- { tag => 'A' },
- { tag => 'B' },
- ],
- },
- },
- {
- cd => {
- artist => {
- name => 'lars', # should already exist
- # even though the artist 'name' is not uniquely constrained
- # find_or_create will arguably DWIM
- },
- title => 'Greatest hits 7',
- year => 2013,
- },
- },
- ],
- },
- },
- ],
- });
-
- is ($schema->resultset ('Artist')->count, $counts->{Artist} + 3, '3 new artists created');
- is ($schema->resultset ('Genre')->count, $counts->{Genre} + 2, '2 additional genres created');
- is ($schema->resultset ('Producer')->count, $counts->{Producer} + 3, '3 new producer');
- is ($schema->resultset ('CD')->count, $counts->{CD} + 7, '7 new CDs');
- is ($schema->resultset ('Tag')->count, $counts->{Tag} + 10, '10 new Tags');
-
- my $cd_rs = $schema->resultset ('CD')
- ->search ({ title => { -like => 'Greatest hits %' }}, { order_by => 'title'} );
- is ($cd_rs->count, 7, '7 greatest hits created');
-
- my $cds_2012 = $cd_rs->search ({ year => 2012});
- is ($cds_2012->count, 5, '5 CDs created in 2012');
-
- is (
- $cds_2012->search(
- { 'tags.tag' => { -in => [qw/A B/] } },
- { join => 'tags', group_by => 'me.cdid' }
- ),
- 5,
- 'All 10 tags were pairwise distributed between 5 year-2012 CDs'
- );
-
- my $paul_prod = $cd_rs->search (
- { 'producer.name' => 'paul'},
- { join => { cd_to_producer => 'producer' } }
- );
- is ($paul_prod->count, 1, 'Paul had 1 production');
- my $pauls_cd = $paul_prod->single;
- is ($pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer');
- is (
- $pauls_cd->search_related ('cd_to_producer',
- { 'producer.name' => 'flemming'},
- { join => 'producer' }
- )->count,
- 1,
- 'The second producer is flemming',
- );
-
- my $kirk_cds = $cd_rs->search ({ 'artist.name' => 'kirk' }, { join => 'artist' });
- is ($kirk_cds, 3, 'Kirk had 3 CDs');
- is (
- $kirk_cds->search (
- { 'cd_to_producer.cd' => { '!=', undef } },
- { join => 'cd_to_producer' },
- ),
- 1,
- 'Kirk had a producer only on one cd',
- );
-
- my $lars_cds = $cd_rs->search ({ 'artist.name' => 'lars' }, { join => 'artist' });
- is ($lars_cds->count, 3, 'Lars had 3 CDs');
- is (
- $lars_cds->search (
- { 'cd_to_producer.cd' => undef },
- { join => 'cd_to_producer' },
- ),
- 0,
- 'Lars always had a producer',
- );
- is (
- $lars_cds->search_related ('cd_to_producer',
- { 'producer.name' => 'flemming'},
- { join => 'producer' }
- )->count,
- 1,
- 'Lars produced 1 CD with flemming',
- );
- is (
- $lars_cds->search_related ('cd_to_producer',
- { 'producer.name' => 'bob'},
- { join => 'producer' }
- )->count,
- 2,
- 'Lars produced 2 CDs with bob',
- );
-
- my $bob_prod = $cd_rs->search (
- { 'producer.name' => 'bob'},
- { join => { cd_to_producer => 'producer' } }
- );
- is ($bob_prod->count, 3, 'Bob produced a total of 3 CDs');
-
- is (
- $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
- 1,
- "Bob produced james' only CD",
- );
-};
-diag $@ if $@;
-
1;
Added: DBIx-Class/0.08/trunk/t/96multi_create_torture.t
===================================================================
--- DBIx-Class/0.08/trunk/t/96multi_create_torture.t (rev 0)
+++ DBIx-Class/0.08/trunk/t/96multi_create_torture.t 2009-02-20 04:31:50 UTC (rev 5549)
@@ -0,0 +1,226 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 19;
+
+# an insane multicreate
+# (should work, despite the fact that no one will probably use it this way)
+
+my $schema = DBICTest->init_schema();
+
+# first count how many rows do we initially have
+my $counts;
+$counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Genre Producer Tag/;
+
+# do the crazy create
+eval {
+ $schema->resultset('CD')->create ({
+ artist => {
+ name => 'james',
+ },
+ title => 'Greatest hits 1',
+ year => '2012',
+ genre => {
+ name => '"Greatest" collections',
+ },
+ tags => [
+ { tag => 'A' },
+ { tag => 'B' },
+ ],
+ cd_to_producer => [
+ {
+ producer => {
+ name => 'bob',
+ producer_to_cd => [
+ {
+ cd => {
+ artist => {
+ name => 'lars',
+ cds => [
+ {
+ title => 'Greatest hits 2',
+ year => 2012,
+ genre => {
+ name => '"Greatest" collections',
+ },
+ tags => [
+ { tag => 'A' },
+ { tag => 'B' },
+ ],
+ # This cd is created via artist so it doesn't know about producers
+ cd_to_producer => [
+ # if we specify 'bob' here things bomb
+ # as the producer attached to Greatest Hits 1 is
+ # already created, but not yet inserted.
+ # Maybe this can be fixed, but things are hairy
+ # enough already.
+ #
+ #{ producer => { name => 'bob' } },
+ { producer => { name => 'paul' } },
+ { producer => {
+ name => 'flemming',
+ producer_to_cd => [
+ { cd => {
+ artist => {
+ name => 'kirk',
+ cds => [
+ {
+ title => 'Greatest hits 3',
+ year => 2012,
+ genre => {
+ name => '"Greatest" collections',
+ },
+ tags => [
+ { tag => 'A' },
+ { tag => 'B' },
+ ],
+ },
+ {
+ title => 'Greatest hits 4',
+ year => 2012,
+ genre => {
+ name => '"Greatest" collections2',
+ },
+ tags => [
+ { tag => 'A' },
+ { tag => 'B' },
+ ],
+ },
+ ],
+ },
+ title => 'Greatest hits 5',
+ year => 2013,
+ genre => {
+ name => '"Greatest" collections2',
+ },
+ }},
+ ],
+ }},
+ ],
+ },
+ ],
+ },
+ title => 'Greatest hits 6',
+ year => 2012,
+ genre => {
+ name => '"Greatest" collections',
+ },
+ tags => [
+ { tag => 'A' },
+ { tag => 'B' },
+ ],
+ },
+ },
+ {
+ cd => {
+ artist => {
+ name => 'lars', # should already exist
+ # even though the artist 'name' is not uniquely constrained
+ # find_or_create will arguably DWIM
+ },
+ title => 'Greatest hits 7',
+ year => 2013,
+ },
+ },
+ ],
+ },
+ },
+ ],
+ });
+
+ is ($schema->resultset ('Artist')->count, $counts->{Artist} + 3, '3 new artists created');
+ is ($schema->resultset ('Genre')->count, $counts->{Genre} + 2, '2 additional genres created');
+ is ($schema->resultset ('Producer')->count, $counts->{Producer} + 3, '3 new producer');
+ is ($schema->resultset ('CD')->count, $counts->{CD} + 7, '7 new CDs');
+ is ($schema->resultset ('Tag')->count, $counts->{Tag} + 10, '10 new Tags');
+
+ my $cd_rs = $schema->resultset ('CD')
+ ->search ({ title => { -like => 'Greatest hits %' }}, { order_by => 'title'} );
+ is ($cd_rs->count, 7, '7 greatest hits created');
+
+ my $cds_2012 = $cd_rs->search ({ year => 2012});
+ is ($cds_2012->count, 5, '5 CDs created in 2012');
+
+ is (
+ $cds_2012->search(
+ { 'tags.tag' => { -in => [qw/A B/] } },
+ { join => 'tags', group_by => 'me.cdid' }
+ ),
+ 5,
+ 'All 10 tags were pairwise distributed between 5 year-2012 CDs'
+ );
+
+ my $paul_prod = $cd_rs->search (
+ { 'producer.name' => 'paul'},
+ { join => { cd_to_producer => 'producer' } }
+ );
+ is ($paul_prod->count, 1, 'Paul had 1 production');
+ my $pauls_cd = $paul_prod->single;
+ is ($pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer');
+ is (
+ $pauls_cd->search_related ('cd_to_producer',
+ { 'producer.name' => 'flemming'},
+ { join => 'producer' }
+ )->count,
+ 1,
+ 'The second producer is flemming',
+ );
+
+ my $kirk_cds = $cd_rs->search ({ 'artist.name' => 'kirk' }, { join => 'artist' });
+ is ($kirk_cds, 3, 'Kirk had 3 CDs');
+ is (
+ $kirk_cds->search (
+ { 'cd_to_producer.cd' => { '!=', undef } },
+ { join => 'cd_to_producer' },
+ ),
+ 1,
+ 'Kirk had a producer only on one cd',
+ );
+
+ my $lars_cds = $cd_rs->search ({ 'artist.name' => 'lars' }, { join => 'artist' });
+ is ($lars_cds->count, 3, 'Lars had 3 CDs');
+ is (
+ $lars_cds->search (
+ { 'cd_to_producer.cd' => undef },
+ { join => 'cd_to_producer' },
+ ),
+ 0,
+ 'Lars always had a producer',
+ );
+ is (
+ $lars_cds->search_related ('cd_to_producer',
+ { 'producer.name' => 'flemming'},
+ { join => 'producer' }
+ )->count,
+ 1,
+ 'Lars produced 1 CD with flemming',
+ );
+ is (
+ $lars_cds->search_related ('cd_to_producer',
+ { 'producer.name' => 'bob'},
+ { join => 'producer' }
+ )->count,
+ 2,
+ 'Lars produced 2 CDs with bob',
+ );
+
+ my $bob_prod = $cd_rs->search (
+ { 'producer.name' => 'bob'},
+ { join => { cd_to_producer => 'producer' } }
+ );
+ is ($bob_prod->count, 3, 'Bob produced a total of 3 CDs');
+
+ is (
+ $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
+ 1,
+ "Bob produced james' only CD",
+ );
+};
+diag $@ if $@;
+
+1;
More information about the Bast-commits
mailing list