Merge branch 'cngarrison-test-fix'
Samuel Kaufman [Wed, 20 Sep 2017 21:07:58 +0000 (21:07 +0000)]
Changes
Makefile.PL
dist.ini
lib/DBIx/Class/Fixtures.pm
t/20-virtual-column.t [new file with mode: 0644]
t/lib/DBICTest/Schema3.pm [new file with mode: 0644]
t/var/configs/virtual-columns.json [new file with mode: 0644]

diff --git a/Changes b/Changes
index e4dc63e..1f3239b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for DBIx-Class-Fixtures
 
 {{$NEXT}}
 
+1.001037  2017-09-20 20:42:03+00:00 UTC
+
+- ignore virtual columns in dump_object
+
 1.001036  2016-03-21 14:59:55+00:00 UTC
 
 - releasing as stable
@@ -102,7 +106,7 @@ Revision history for DBIx-Class-Fixtures
 
 1.001013
 - fixed functionality in last release by more deeply cloning parameters, which
-  prevents bad things when parameters get deleted in the wrong places.  Also 
+  prevents bad things when parameters get deleted in the wrong places.  Also
   be sure we clear state properly after a dump.
 
 1.001012
@@ -111,8 +115,8 @@ Revision history for DBIx-Class-Fixtures
   to make it easier when you need to dump all the fixtures programatically.
 - Added method 'dump_config_sets' to let you dump more than one set at a time
   more easily
-- Added method 'dump_all_config_sets' which helps automate dumping all your 
-  current config sets to a directory.  
+- Added method 'dump_all_config_sets' which helps automate dumping all your
+  current config sets to a directory.
 
 1.001011
 - Added an excludes resultsource option to the ->dump({all=>1,...}) feature
index ce3c5d5..c5d5f42 100644 (file)
@@ -1,4 +1,4 @@
-# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.037.
+# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.008.
 use strict;
 use warnings;
 
@@ -13,13 +13,13 @@ my %WriteMakefileArgs = (
     "DBIx::Class::InflateColumn::FS" => "0.01007",
     "Devel::Confess" => 0,
     "ExtUtils::MakeMaker" => "6.59",
+    "Test::Fatal" => 0,
     "Test::More" => "0.98"
   },
   "CONFIGURE_REQUIRES" => {
     "ExtUtils::MakeMaker" => "6.59"
   },
   "DISTNAME" => "DBIx-Class-Fixtures",
-  "EXE_FILES" => [],
   "LICENSE" => "perl",
   "MIN_PERL_VERSION" => "5.006001",
   "NAME" => "DBIx::Class::Fixtures",
@@ -41,17 +41,18 @@ my %WriteMakefileArgs = (
     "JSON::Syck" => "1.27",
     "MIME::Base64" => 0,
     "Path::Class" => "0.32",
-    "Scalar::Util" => "1.27",
-    "Test::Compile::Internal" => 0,
-    "Test::TempDir::Tiny" => 0
+    "Scalar::Util" => "1.27"
   },
   "TEST_REQUIRES" => {
+    "File::Path" => 0,
     "File::Spec" => 0,
     "IO::Handle" => 0,
     "IPC::Open3" => 0,
-    "Test::More" => "0.98"
+    "Test::Compile::Internal" => 0,
+    "Test::More" => "0.98",
+    "Test::TempDir::Tiny" => 0
   },
-  "VERSION" => "1.001036",
+  "VERSION" => "1.001037",
   "test" => {
     "TESTS" => "t/*.t"
   }
@@ -73,6 +74,7 @@ my %FallbackPrereqs = (
   "Devel::Confess" => 0,
   "ExtUtils::MakeMaker" => "6.59",
   "File::Copy::Recursive" => "0.38",
+  "File::Path" => 0,
   "File::Spec" => 0,
   "File::Temp" => "0.2304",
   "Hash::Merge" => "0.1",
@@ -84,6 +86,7 @@ my %FallbackPrereqs = (
   "Path::Class" => "0.32",
   "Scalar::Util" => "1.27",
   "Test::Compile::Internal" => 0,
+  "Test::Fatal" => 0,
   "Test::More" => "0.98",
   "Test::TempDir::Tiny" => 0
 );
index 2d17c3e..5ddd5c6 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -64,6 +64,7 @@ DBIx::Class::InflateColumn::FS = 0.01007
 ExtUtils::MakeMaker = 6.59
 Test::More = 0.98
 Devel::Confess = 0
+Test::Fatal = 0
 
 [Prereqs]
 Class::Accessor::Grouped = 0.1001
@@ -84,6 +85,9 @@ MIME::Base64 = 0
 Path::Class = 0.32
 Scalar::Util = 1.27
 perl = 5.6.1
-Test::Compile::Internal = 0
 IO::All = 0.85
-Test::TempDir::Tiny=0
+
+[Prereqs / TestRequires]
+Test::TempDir::Tiny = 0
+File::Path = 0
+Test::Compile::Internal = 0
index 65806ed..376ce4a 100644 (file)
@@ -23,7 +23,7 @@ our $namespace_counter = 0;
 __PACKAGE__->mk_group_accessors( 'simple' => qw/config_dir
     _inherited_attributes debug schema_class dumped_objects config_attrs/);
 
-our $VERSION = '1.001036';
+our $VERSION = '1.001037';
 
 $VERSION = eval $VERSION;
 
@@ -557,7 +557,8 @@ or
  $fixtures->dump({
    all => 1, # just dump everything that's in the schema
    schema => $source_dbic_schema,
-   directory => '/home/me/app/fixtures' # output directory
+   directory => '/home/me/app/fixtures', # output directory
+   #excludes => [ qw/Foo MyView/ ], # optionally exclude certain sources
  });
 
 In this case objects will be dumped to subdirectories in the specified
@@ -567,9 +568,14 @@ directory. For example:
  /home/me/app/fixtures/artist/3.fix
  /home/me/app/fixtures/producer/5.fix
 
-schema and directory are required attributes. also, one of config or all must
+C<schema> and C<directory> are required attributes. also, one of C<config> or C<all> must
 be specified.
 
+The optional parameter C<excludes> takes an array ref of source names and can be
+used to exclude those sources when dumping the whole schema. This is useful if
+you have views in there, since those do not need fixtures and will currently result
+in an error when they are created and then used with C<populate>.
+
 Lastly, the C<config> parameter can be a Perl HashRef instead of a file name.
 If this form is used your HashRef should conform to the structure rules defined
 for the JSON representations.
@@ -848,7 +854,14 @@ sub dump_object {
   # write file
   unless ($exists) {
     $self->msg('-- dumping ' . "$file", 2);
-    my %ds = $object->get_columns;
+
+    # get_columns will return virtual columns; we just want stored columns.
+    # columns_info keys seems to be the actual storage column names, so we'll
+    # use that.
+    my $col_info = $src->columns_info;
+    my @column_names = keys %$col_info;
+    my %columns = $object->get_columns;
+    my %ds; @ds{@column_names} = @columns{@column_names};
 
     if($set->{external}) {
       foreach my $field (keys %{$set->{external}}) {
diff --git a/t/20-virtual-column.t b/t/20-virtual-column.t
new file mode 100644 (file)
index 0000000..5c6d720
--- /dev/null
@@ -0,0 +1,60 @@
+use strict;
+use warnings;
+
+use DBIx::Class::Fixtures;
+use Test::More;
+use Test::Fatal;
+use File::Path 'rmtree';
+
+use lib qw(t/lib/DBICTest);
+use Schema3;
+use Test::TempDir::Tiny;
+use IO::All;
+
+my $tempdir = tempdir;
+
+(my $schema = Schema3->connect(
+  'DBI:SQLite::memory:','',''))->init_schema;
+
+ok my $row = $schema
+  ->resultset('Person')
+  ->first;
+
+ok $row->get_column('weight_to_height_ratio'),
+    'has virtual column';
+
+my $fixtures = DBIx::Class::Fixtures
+  ->new({
+    config_dir => io->catfile(qw't var configs')->name,
+    debug => 0 });
+
+ok(
+  $fixtures->dump({
+    config => 'virtual-columns.json',
+    schema => $schema,
+    directory => io->catfile($tempdir, 'people')->name }),
+  'fetch dump executed okay');
+
+ok $schema->resultset('Person')->delete;
+
+is exception {
+  $fixtures->populate({
+    no_deploy => 1,
+    schema => $schema,
+    directory => io->catfile($tempdir, 'people')->name
+  })
+}, undef, 'populated';
+
+$row = $schema->resultset('Person')->first;
+
+BAIL_OUT("can't continue without data") unless $row;
+
+ok $row->get_column('weight_to_height_ratio'),
+  'still has virtual column';
+
+done_testing;
+
+END {
+    rmtree io->catfile(qw't var files')->name;
+    rmtree io->catfile($tempdir, 'people')->name;
+}
diff --git a/t/lib/DBICTest/Schema3.pm b/t/lib/DBICTest/Schema3.pm
new file mode 100644 (file)
index 0000000..0150aa9
--- /dev/null
@@ -0,0 +1,71 @@
+package Schema3::Result::Person;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('person');
+
+__PACKAGE__->add_columns(
+  id => {
+       data_type => 'integer',
+       is_auto_increment => 1,
+  },
+  name => {
+    data_type => 'varchar',
+    size => 255,
+  },
+  weight => {
+    datatype => 'float',
+  },
+  height => {
+    datatype => 'float',
+  },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+# Add virtual column
+__PACKAGE__->resultset_attributes({
+  '+select' => [ \'weight/height' ],
+  '+as'     => [ 'weight_to_height_ratio' ],
+});
+
+package Schema3;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->register_class(Person => 'Schema3::Result::Person');
+
+sub load_sql {
+  local $/ = undef;
+  my $sql = <DATA>;
+}
+
+sub init_schema {
+  my $sql = (my $schema = shift)
+    ->load_sql;
+
+  ($schema->storage->dbh->do($_) ||
+   die "Error on SQL: $_\n")
+    for split(/;\n/, $sql);
+}
+
+1;
+
+__DATA__
+CREATE TABLE person (
+  id INTEGER PRIMARY KEY NOT NULL,
+  name varchar(255) NOT NULL,
+  weight FLOAT NOT NULL,
+  height FLOAT NOT NULL
+);
+
+INSERT INTO person (name, weight, height)
+VALUES
+('Fred Flintstone', 220, 5.2),
+('Barney Rubble', 190, 4.8)
diff --git a/t/var/configs/virtual-columns.json b/t/var/configs/virtual-columns.json
new file mode 100644 (file)
index 0000000..a7fd694
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "sets": [{
+               "class": "Person",
+               "quantity": "all",
+       }]
+}