check postspec loading, factor out column order handling to avoid making further...
Matt S Trout [Sat, 16 May 2009 15:23:32 +0000 (16:23 +0100)]
lib/IronMunger/PlaggerLoader.pm
t/plagger_loader.t

index 08daf15..db50215 100644 (file)
@@ -32,14 +32,20 @@ class IronMunger::PlaggerLoader {
     ];
   }
 
+  method _csv_column_order () {
+    my $x;
+    return map +($_ => $x++), qw(author title url at);
+  }
+
   method _expand_postspecs_from_file(IO::All::File $file) {
     my $csv = Text::CSV_XS->new;
     my $io = $file->open;
     my @post_specs;
+    my %col_order = $self->_csv_column_order;
     while (my $post_raw = $csv->getline($io)) {
       my %post_spec;
-      @post_spec{qw{url at}} = @{$post_raw}[1,2];
-      push(@post_specs, %post_spec);
+      @post_spec{qw{url at}} = @{$post_raw}[@col_order{qw{url at}}];
+      push(@post_specs, \%post_spec);
     }
     return \@post_specs;
   }
index f4b3002..e3bffd4 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 use Test::More qw(no_plan);
-
+use IO::All;
 
 BEGIN {
   use_ok aliased => 'IronMunger::PlaggerLoader';
@@ -31,3 +31,15 @@ is_deeply(
     is($post->$key, $args{$key}, "Attribute ${key} ok");
   }
 }
+
+my @postspecs = map
+  +{
+    url => 'http://jdv79.blogspot.com/2009/05/testable-v007.html',
+    at => $_,
+   }, qw(2009-05-13T02:45:00 2009-05-14T16:00:00);
+
+my $specs = $loader->_expand_postspecs_from_file(
+              io('t/csv/my_Justin_DeVuyst.csv')
+            );
+
+is_deeply($specs, \@postspecs, 'Post specs from file ok');