Skip to content

Instantly share code, notes, and snippets.

@dpetrov
Created October 13, 2011 16:18
Show Gist options
  • Save dpetrov/1284673 to your computer and use it in GitHub Desktop.
Save dpetrov/1284673 to your computer and use it in GitHub Desktop.
that pass all tests
diff --git a/lib/MetaCPAN/Web/Controller/Module.pm b/lib/MetaCPAN/Web/Controller/Module.pm
index 0ef1d03..9831aff 100644
--- a/lib/MetaCPAN/Web/Controller/Module.pm
+++ b/lib/MetaCPAN/Web/Controller/Module.pm
@@ -13,7 +13,7 @@ sub index : PathPart('module') : Chained('/') : Args {
: $c->model('API::Module')->get(@module)->recv;
$c->detach('/not_found') unless ( $data->{name} );
- my $pod = $c->model('API')->request( '/pod/' . join( '/', @module ) );
+ my $pod = $c->model('API')->request( '/pod/' . join( '/', (@module > 1 ? uc shift @module : ()), @module ) );
my $release
= $c->model('API::Release')->get( $data->{author}, $data->{release} );
my $author = $c->model('API::Author')->get( $data->{author} );
diff --git a/lib/MetaCPAN/Web/Model/API/File.pm b/lib/MetaCPAN/Web/Model/API/File.pm
index eaa4d1f..cada94a 100644
--- a/lib/MetaCPAN/Web/Model/API/File.pm
+++ b/lib/MetaCPAN/Web/Model/API/File.pm
@@ -4,12 +4,12 @@ extends 'MetaCPAN::Web::Model::API';
sub get {
my ( $self, @path ) = @_;
- $self->request( '/file/' . join( '/', @path ) );
+ $self->request( '/file/' . join( '/', uc shift @path, @path ) );
}
sub source {
my ( $self, @path ) = @_;
- $self->request( '/source/' . join( '/', @path ), undef, { raw => 1 } );
+ $self->request( '/source/' . join( '/', uc shift @path, @path ), undef, { raw => 1 } );
}
sub dir {
@@ -23,7 +23,7 @@ sub dir {
filter => {
and => [
{ term => { 'file.level' => scalar @path } },
- { term => { 'file.author' => $author } },
+ { term => { 'file.author' => uc $author } },
{ term => { 'file.release' => $release } },
{ prefix => {
'file.path' => join( '/', @path, undef )
diff --git a/t/controller/module.t b/t/controller/module.t
index 27147a1..6bcd286 100644
--- a/t/controller/module.t
+++ b/t/controller/module.t
@@ -21,6 +21,15 @@ test_psgi app, sub {
ok( $res = $cb->( GET $this ), "GET $this" );
is($latest, $res->content, 'content of both urls is exactly the same');
+ # module info with lc author name
+ if ( my ($author) = $this =~ m{^/module/(.*?)/} ) {
+ $this =~ s/$author/lc($author)/e;
+
+ ok( $res = $cb->( GET $this ), "GET $this" );
+ is( $res->code, 200, 'code 200' );
+ is($latest, $res->content, 'content of both urls is exactly the same');
+ }
+
# Moose has ratings, but not all dists do (so be careful what we're testing with)
$tx->like(
'//div[@class="search-bar"]//div[starts-with(@class, "rating-")]/following-sibling::a',
diff --git a/t/controller/release.t b/t/controller/release.t
index 376e71f..34fddd2 100644
--- a/t/controller/release.t
+++ b/t/controller/release.t
@@ -34,6 +34,20 @@ test_psgi app, sub {
'content of both urls is exactly the same'
);
+ # release info with lc author name
+ if ( my ($author) = $this =~ m{^/release/(.*?)/} ) {
+ $this =~ s/$author/lc($author)/e;
+
+ ok( $res = $cb->( GET $this ), "GET $this" );
+ is( $res->code, 200, 'code 200' );
+ my $tx_latest = tx($res);
+ is(
+ $latest,
+ $tx_latest->find_value('//div[@class="content"]'),
+ 'content of both urls is exactly the same'
+ );
+ }
+
$tx->like(
'//select[@name="release"]/option[@value][1]',
qr/\(\d{4}-\d{2}-\d{2}\)$/,
@rwstauner
Copy link

Tests are always a good thing to have ;-)
The only thing I would add would be comments:
tomorrow somebody might look at this and wonder why we're uppercasing the the first item of @module or @path (not realizing that it's the author).
A simple comment above those lines could save time/effort for somebody (even yourself) later.
Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment