check postspec loading, factor out column order handling to avoid making further...
[engit/Iron-Munger.git] / t / plagger_loader.t
1 use strict;
2 use warnings;
3 use Test::More qw(no_plan);
4 use IO::All;
5
6 BEGIN {
7   use_ok aliased => 'IronMunger::PlaggerLoader';
8 }
9
10 my @names = ('Jess Robinson', 'Justin DeVuyst');
11
12 my @files = ('my_Jess_Robinson.csv', 'my_Justin_DeVuyst.csv');
13
14 ok(my $loader = PlaggerLoader->new(dir => 't/csv'), 'build loader');
15
16 my @target = $loader->_target_files;
17
18 cmp_ok(@target, '==', 2, '2 files in CSV directory');
19
20 is_deeply(
21   [ sort map { ($_->splitpath)[-1] } @target ], \@files,
22   'filenames ok'
23 );
24
25 {
26   my %args = (url => 'http://foo.com', at => '2008-04-06T12:00:00');
27
28   ok(my $post = $loader->_expand_post(\%args), 'Expand post constructs object');
29
30   foreach my $key (sort keys %args) {
31     is($post->$key, $args{$key}, "Attribute ${key} ok");
32   }
33 }
34
35 my @postspecs = map
36   +{
37     url => 'http://jdv79.blogspot.com/2009/05/testable-v007.html',
38     at => $_,
39    }, qw(2009-05-13T02:45:00 2009-05-14T16:00:00);
40
41 my $specs = $loader->_expand_postspecs_from_file(
42               io('t/csv/my_Justin_DeVuyst.csv')
43             );
44
45 is_deeply($specs, \@postspecs, 'Post specs from file ok');