[Catalyst-commits] r6828 - in trunk/Catalyst-Model-File: lib/Catalyst/Model t t/lib/TestApp t/lib/TestApp/Controller

ash at dev.catalyst.perl.org ash at dev.catalyst.perl.org
Sun Sep 2 18:31:22 GMT 2007


Author: ash
Date: 2007-09-02 18:31:22 +0100 (Sun, 02 Sep 2007)
New Revision: 6828

Added:
   trunk/Catalyst-Model-File/t/06live.t
   trunk/Catalyst-Model-File/t/lib/TestApp/Controller/
   trunk/Catalyst-Model-File/t/lib/TestApp/Controller/Root.pm
Modified:
   trunk/Catalyst-Model-File/lib/Catalyst/Model/File.pm
   trunk/Catalyst-Model-File/t/04basic.t
Log:
Fix mode param to list, and todo test for not needing to do cd('/') every time

Modified: trunk/Catalyst-Model-File/lib/Catalyst/Model/File.pm
===================================================================
--- trunk/Catalyst-Model-File/lib/Catalyst/Model/File.pm	2007-09-01 09:46:36 UTC (rev 6827)
+++ trunk/Catalyst-Model-File/lib/Catalyst/Model/File.pm	2007-09-02 17:31:22 UTC (rev 6828)
@@ -59,6 +59,7 @@
     return $self;
 }
 
+
 =head2 list
 
 Returns a list of files (and/or directories) found under the current working 
@@ -78,7 +79,6 @@
 =cut
 
 sub list {
-    $DB::single = 1;
     my ($self, %opt) = @_;
     my @files;
     $opt{mode} ||= 'files';
@@ -101,11 +101,10 @@
 
     return @files if $opt{dir} && $opt{file};
 
-    my $meth = $opt{dir} ? 'is_dir' : 'is_file';
+    return $opt{dir} ?
+      grep { $_->is_dir } @files :
+      grep { !$_->is_dir } @files;
 
-    return map { $_->relative($self->{_dir}) } 
-        grep { $_->is_dir && $opt{dir} || !$_->is_dir && $opt{file}
-        } @files;
 }
 
 =head2 change_dir
@@ -120,7 +119,6 @@
 
 
 sub change_dir {
-    $DB::single = 1;
     my $self = shift;
 
     my $dir = shift;

Modified: trunk/Catalyst-Model-File/t/04basic.t
===================================================================
--- trunk/Catalyst-Model-File/t/04basic.t	2007-09-01 09:46:36 UTC (rev 6827)
+++ trunk/Catalyst-Model-File/t/04basic.t	2007-09-02 17:31:22 UTC (rev 6828)
@@ -3,7 +3,7 @@
 
 use Test::More;
 
-plan tests => 12;
+plan tests => 14;
 
 use FindBin;
 use lib "$FindBin::Bin/lib";
@@ -31,12 +31,12 @@
 
 my $model = TestApp->model('File');
 
-ok($model);
+ok($model, 'Model ok');
 
-is_deeply(\@files, [ $model->list], 'List matches');
+is_deeply([ sort $model->list], \@files, 'List matches');
 
 for my $file (@files) {
-    is($file, $model->slurp($file), 'slurp okay');
+    is($model->slurp($file), $file, 'slurp okay');
 }
 
 # Slurp/Splat tests
@@ -49,8 +49,8 @@
     my (@lines) = <FILE>;
     close FILE;
     is_deeply([$string], \@lines, 'splat works');
- 
-    is($string, $model->slurp($file), 'slurp works');
+
+    is($model->slurp($file), $string, 'slurp works');
 }
 
 # Subdir test
@@ -59,17 +59,35 @@
     $model->splat($file, $file);
 
     my $file_obj = $model->file($file);
-    
 
     ok($file_obj->stat, 'File in sub directory created');
-    is($file, $file_obj->slurp, "contents are right");
+    is($file_obj->slurp, $file, "File contents are right");
 }
 
-is_deeply([
-    Path::Class::file('file3'),
-    Path::Class::file('foo1'),
-    Path::Class::file('foo2'),
-    Path::Class::dir('sub'),
-,], [sort $model->list(recurse => 0, mode => 'both')], "List without recurse is right");
+ at files = (Path::Class::file('file3'),
+          Path::Class::file('foo1'),
+          Path::Class::file('foo2'));
+my @dirs = (Path::Class::dir('sub'));
+my @both = (@files, @dirs);
 
+$model->cd('/');
+# mode => 'both' test
+{
+    my @result = sort $model->list(recurse => 0, mode => 'both');
+    is_deeply(\@result, \@both, 'List of dirs & files matches');
+}
+
+# mode => 'dir' test
+{
+    my @result = sort $model->list(recurse => 0, mode => 'dirs');
+    is_deeply(\@result, \@dirs, 'List of dirs matches');
+}
+
+# mode => 'file' test
+{
+    my @result = sort $model->list(recurse => 0, mode => 'files');
+    is_deeply(\@result, \@files, 'List of files matches');
+}
+
+
 $model->{root_dir}->rmtree;

Added: trunk/Catalyst-Model-File/t/06live.t
===================================================================
--- trunk/Catalyst-Model-File/t/06live.t	                        (rev 0)
+++ trunk/Catalyst-Model-File/t/06live.t	2007-09-02 17:31:22 UTC (rev 6828)
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 2;
+
+BEGIN
+{
+  $ENV{MODEL_FILE_DIR} = $FindBin::Bin . '/store';
+    require Path::Class;
+    Path::Class::dir($ENV{MODEL_FILE_DIR})->rmtree;
+}
+
+use Catalyst::Test 'TestApp';
+use Data::Dumper;
+
+my $res = request('http://localhost/cd');
+is $res->content, '/foo';
+sleep 2;
+local $TODO = "work out how to fix this";
+$res = request('http://localhost/pwd');
+is $res->content, '/';

Added: trunk/Catalyst-Model-File/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-Model-File/t/lib/TestApp/Controller/Root.pm	                        (rev 0)
+++ trunk/Catalyst-Model-File/t/lib/TestApp/Controller/Root.pm	2007-09-02 17:31:22 UTC (rev 6828)
@@ -0,0 +1,20 @@
+package TestApp::Controller::Root;
+
+use strict;
+use warnings;
+
+use base 'Catalyst::Controller';
+
+__PACKAGE__->config(namespace => '');
+
+
+sub cd : Global { 
+  my ($self, $c) = @_;
+  $c->model('File')->cd('foo');
+  $c->res->body( $c->model('File')->pwd );
+}
+
+sub pwd : Global { 
+  my ($self, $c) = @_;
+  $c->res->body( $c->model('File')->pwd );
+}




More information about the Catalyst-commits mailing list