Permalink
Browse files

huh

  • Loading branch information...
benvanstaveren committed Apr 7, 2012
1 parent 0e70bea commit 5705a705c5193db14d3f911f517acb6803b2ab88
Showing with 80 additions and 0 deletions.
  1. +80 −0 t/01-functional.t
View
@@ -0,0 +1,80 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+# Disable IPv6, epoll and kqueue
+BEGIN { $ENV{MOJO_NO_IPV6} = $ENV{MOJO_POLL} = 1 }
+
+use Test::More;
+
+if(!$ENV{TEST_MONGODB}) {
+ plan skip_all => 'Please set the TEST_MONGODB variable to a MongoDB connection string (host:port) in order to test';
+} else {
+ plan tests => 21;
+}
+
+# testing code starts here
+use Mojolicious::Lite;
+use Test::Mojo;
+
+my ($host, $port) = split(/:/, $ENV{TEST_MONGODB});
+$host ||= 'localhost';
+$port ||= 27017;
+
+my $dbname = 'mojolicious_plugin_mongodb_test_' . $$;
+my $dbname2 = 'mojolicious_plugin_mongodb_test_2' . $$;
+
+plugin 'mongodb', {
+ 'host' => $host,
+ 'port' => $port,
+ 'database' => $dbname,
+ 'helper' => 'foo',
+ };
+
+get '/connection' => sub {
+ my $self = shift;
+ $self->render(text => ref($self->app->mongodb_connection));
+};
+
+get '/getdb' => sub {
+ my $self = shift;
+ $self->render(text => $self->foo($dbname)->name);
+};
+
+get '/getotherdb' => sub {
+ my $self = shift;
+ $self->render(text => $self->foo($dbname2)->name);
+};
+
+get '/lastdb' => sub {
+ my $self = shift;
+ $self->render(text => $self->foo->name);
+};
+
+get '/db-get-collection/:cname' => sub {
+ my $self = shift;
+ my $cname = $self->stash('cname');
+ $self->render(text => $self->foo->get_collection($cname)->name);
+};
+
+get '/db-coll/:cname' => sub {
+ my $self = shift;
+ my $cname = $self->stash('cname');
+ $self->render(text => $self->coll($cname)->name);
+};
+
+get '/db-coll-full/:cname' => sub {
+ my $self = shift;
+ my $cname = $self->stash('cname');
+ $self->render(text => $self->coll($cname, $dbname2)->full_name);
+};
+
+my $t = Test::Mojo->new;
+
+$t->get_ok('/connection')->status_is(200)->content_is('MongoDB::Connection');
+$t->get_ok('/getdb')->status_is(200)->content_is($dbname);
+$t->get_ok('/getotherdb')->status_is(200)->content_is($dbname2);
+$t->get_ok('/lastdb')->status_is(200)->content_is($dbname2);
+$t->get_ok('/db-get-collection/test1')->status_is(200)->content_is('test1');
+$t->get_ok('/db-coll/test1')->status_is(200)->content_is('test1');
+$t->get_ok('/db-coll-full/test1')->status_is(200)->content_is("$dbname2.test1");

0 comments on commit 5705a70

Please sign in to comment.