$self->_image_symlink_from($user, $type),
$self->_image_symlink_target($type, $level),
);
- my $dir = File::Spec->catpath((File::Spec->splitpath($target))[0,1]);
+ my $dir = File::Spec->catpath((File::Spec->splitpath($from))[0,1]);
mkpath($dir);
symlink($target, $from)
or confess "Couldn't symlink ${from} to ${target}: $!";
method _write_symlinks_for (IronMunger::Monger $monger) {
foreach my $type (@types) {
- foreach my $name (map $monger->$_, qw(name nick)) {
+ foreach my $name (
+ map $monger->$_,
+ grep $monger->${\"has_$_"},
+ qw(name nick)
+ ) {
$self->_write_image_symlink($name, $type, $monger->level);
}
}
use warnings;
use Test::More qw(no_plan);
use IO::All;
-use File::Temp qw(tempdir);
+use File::Temp ();
+
+sub tempdir {
+ if ($ENV{UNCLEAN_TEMP}) {
+ my $dir = File::Temp::tempdir;
+ warn $dir;
+ return $dir;
+ }
+ return File::Temp::tempdir(CLEANUP => 1);
+}
BEGIN { use_ok aliased => 'IronMunger::StatsSaver'; }
BEGIN { use_ok aliased => 'IronMunger::Monger'; }
is($monger->level, 'paper', 'mst sucks');
-my $dir = tempdir(CLEANUP => 1);
+my $dir = tempdir;
$saver = StatsSaver->new(dir => $dir);
$saver->_write_symlinks_for($monger);
-my @links = sort map $_->readlink, grep -l, io($dir)->all_files;
+my $bdir = io("${dir}/badges");
+
+my $mbdir = io("${dir}/mybadge");
+
+my %found_links;
+do {
+ my @l = $mbdir->all_links(2);
+ @found_links{@l} = (1) x scalar @l;
+};
+
+foreach my $gender (qw(male female)) {
+ my $desc = "${gender} symlink";
+ my $l = io("${mbdir}/${gender}/mst.png");
+ ok($l->is_link, "${desc} exists");
+ is(
+ $l->readlink, "${bdir}/${gender}/paper.png",
+ "${desc} points to right target",
+ );
+ ok(delete $found_links{$l}, "${desc} in link list");
+}
-warn join("\n", @links);
+ok(!(keys %found_links), 'all links accounted for');