From: Charlie Garrison Date: Wed, 19 Oct 2016 02:43:42 +0000 (+1100) Subject: Added failing tests for `external`, fix for tests X-Git-Tag: v1.001038~2^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3d4debec185c87acba106e27e0b4ab6ded4bc041;p=dbsrgits%2FDBIx-Class-Fixtures.git Added failing tests for `external`, fix for tests If config follows has_many to dump a set, the set’s config is not used, so attrs such as `external` are not honoured. Even using `rules` does not solve the problem. Using unsorted `sets` array to specify dump order solves the problem. Signed-off-by: Charlie Garrison --- diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index c979849..5c5dc04 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -644,7 +644,7 @@ sub dump { $tmp_output_dir->file('_config_set')->print( Dumper $config ); $config->{rules} ||= {}; - my @sources = sort { $a->{class} cmp $b->{class} } @{delete $config->{sets}}; + my @sources = @{delete $config->{sets}}; while ( my ($k,$v) = each %{ $config->{rules} } ) { if ( my $source = eval { $schema->source($k) } ) { diff --git a/t/18-extra.t b/t/18-extra.t index 75528d5..7af4518 100644 --- a/t/18-extra.t +++ b/t/18-extra.t @@ -18,7 +18,8 @@ open(my $fh, '<', io->catfile(qw't 18-extra.t')->name) || ok my $row = $schema ->resultset('Photo') ->create({ - photographer=>'john', + album=> {name=>'masterpiece'}, + photographer=> {name=>'john'}, file=>$fh, }); @@ -42,6 +43,8 @@ ok my $key = $schema->resultset('Photo')->first->file; ok -e $key, 'File Created'; ok $schema->resultset('Photo')->delete; +ok $schema->resultset('Photographer')->delete; +ok $schema->resultset('Album')->delete; ok ! -e $key, 'File Deleted'; diff --git a/t/lib/ExtraTest/Schema.pm b/t/lib/ExtraTest/Schema.pm index e43643b..5484f9e 100644 --- a/t/lib/ExtraTest/Schema.pm +++ b/t/lib/ExtraTest/Schema.pm @@ -1,3 +1,52 @@ +package ExtraTest::Schema::Result::Album; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table('album'); +__PACKAGE__->add_columns( + 'albumid' => { + data_type => 'integer', + is_auto_increment => 1, + }, + 'name' => { + data_type => 'varchar', + size => 100, + is_nullable => 1, + }, +); +__PACKAGE__->set_primary_key('albumid'); + +__PACKAGE__->has_many( + photos => 'ExtraTest::Schema::Result::Photo' +); + +1; + +package ExtraTest::Schema::Result::Photographer; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table('photographer'); +__PACKAGE__->add_columns( + 'photographerid' => { + data_type => 'integer', + is_auto_increment => 1, + }, + 'name' => { + data_type => 'varchar', + size => 100, + is_nullable => 1, + }, +); +__PACKAGE__->set_primary_key('photographerid'); + +__PACKAGE__->has_many( + photos => 'ExtraTest::Schema::Result::Photo' +); + +1; + + package ExtraTest::Schema::Result::Photo; use strict; @@ -13,9 +62,11 @@ __PACKAGE__->add_columns( data_type => 'integer', is_auto_increment => 1, }, + album => { + data_type => 'integer', + }, photographer => { - data_type => 'varchar', - size => 40, + data_type => 'integer', }, file => { data_type => 'varchar', @@ -26,6 +77,9 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key('photo_id'); +__PACKAGE__->belongs_to( photographer => 'ExtraTest::Schema::Result::Photographer' ); +__PACKAGE__->belongs_to( album => 'ExtraTest::Schema::Result::Album' ); + package ExtraTest::Schema; use strict; @@ -34,6 +88,10 @@ use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->register_class( + Album => 'ExtraTest::Schema::Result::Album'); +__PACKAGE__->register_class( + Photographer => 'ExtraTest::Schema::Result::Photographer'); +__PACKAGE__->register_class( Photo => 'ExtraTest::Schema::Result::Photo'); sub load_sql { @@ -53,9 +111,18 @@ sub init_schema { 1; __DATA__ +CREATE TABLE album ( + albumid INTEGER PRIMARY KEY NOT NULL, + name varchar(100) NOT NULL +); +CREATE TABLE photographer ( + photographerid INTEGER PRIMARY KEY NOT NULL, + name varchar(100) NOT NULL +); CREATE TABLE photo ( photo_id INTEGER PRIMARY KEY NOT NULL, - photographer varchar(40) NOT NULL, + album INTEGER NOT NULL, + photographer INTEGER NOT NULL, file varchar(255) NOT NULL ) diff --git a/t/var/configs/extra.json b/t/var/configs/extra.json index 53408c3..beb6083 100644 --- a/t/var/configs/extra.json +++ b/t/var/configs/extra.json @@ -8,5 +8,17 @@ "args": {"path":"__ATTR(photo_dir)__"} } } + },{ + "class": "Album", + "quantity": "all", + "fetch" : [ + { + "quantity" : "all", + "rel" : "photos" + } + ] + },{ + "class": "Photographer", + "quantity": "all" }] }