From: Justin Guenther Date: Mon, 5 Jun 2006 20:04:10 +0000 (+0000) Subject: Added preliminary tests for new helpers X-Git-Tag: v0.07002~75^2~94^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a868fb29b0bb50a7216f770cc9a71d358d67431;p=dbsrgits%2FDBIx-Class.git Added preliminary tests for new helpers --- diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index 8818a69..a88e1b0 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -13,7 +13,9 @@ sub many_to_many { *{"${class}::${meth}"} = sub { my $self = shift; my $attrs = @_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}; - $self->search_related($rel)->search_related($f_rel, @_ > 0 ? @_ : undef, { %{$rel_attrs||{}}, %$attrs }); + $self->search_related($rel)->search_related( + $f_rel, @_ > 0 ? @_ : undef, { %{$rel_attrs||{}}, %$attrs } + ); }; *{"${class}::add_to_${meth}"} = sub { diff --git a/t/66relationship.t b/t/66relationship.t index dce68f7..ac4c2de 100644 --- a/t/66relationship.t +++ b/t/66relationship.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 32; +plan tests => 35; # has_a test my $cd = $schema->resultset("CD")->find(4); @@ -134,6 +134,16 @@ is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' ); is( $cd->producers_sorted->next->name, 'Bob The Builder', 'sorted many_to_many ok' ); is( $cd->producers_sorted(producerid => 3)->next->name, 'Fred The Phenotype', 'sorted many_to_many with search condition ok' ); +# test new many_to_many helpers +$cd = $schema->resultset('CD')->find(2); +my $prod = $schema->resultset('Producer')->find(1); +$cd->add_to_producers($prod); +my $prod_rs = $cd->producers(); +is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($obj) count ok' ); +is( $prod_rs->first->name, 'Matt S Trout', 'many_to_many add_to_$rel($obj) ok' ); +$cd->remove_from_producers($prod); +is( $cd->producers->count, 0, 'many_to_many remove_from_$rel($obj) ok' ); + # test undirected many-to-many relationship (e.g. "related artists") my $undir_maps = $schema->resultset("Artist")->find(1)->artist_undirected_maps; is($undir_maps->count, 1, 'found 1 undirected map for artist 1');