Skip to content
Permalink
Browse files

use configuration file to set the name of the database

  • Loading branch information...
szabgab committed May 28, 2015
1 parent 8f1b462 commit 93b9d6296fe002ba5d8011aa679e411958a6904e
Showing with 12 additions and 1 deletion.
  1. +3 −0 config.yml
  2. +1 −1 lib/D2/Ajax.pm
  3. +8 −0 t/v2.t
@@ -27,3 +27,6 @@ template: "simple"
# start_tag: '<%'
# end_tag: '%>'

app:
mongodb: d2-ajax

@@ -43,7 +43,7 @@ post '/api/v2/item' => sub {
}

my $client = MongoDB::MongoClient->new(host => 'localhost', port => 27017);
my $db = $client->get_database( 'd2-ajax' );
my $db = $client->get_database( config->{app}{mongodb} );
my $items = $db->get_collection('items');
$items->insert({
text => $text,
8 t/v2.t
@@ -11,6 +11,7 @@ use Plack::Test;
use HTTP::Request::Common;
use Test::NoWarnings;
use JSON::MaybeXS qw(decode_json);
use MongoDB ();

subtest v2_greeting => sub {
plan tests => 4;
@@ -51,12 +52,19 @@ subtest v2_items => sub {

my $app = D2::Ajax->to_app;

my $db_name = 'd2-ajax-' . $$ . '-' . time;
D2::Ajax->config->{app}{mongodb} = $db_name;

my $test = Plack::Test->create($app);

my $res = $test->request( POST '/api/v2/item', {text => 'First Thing to do' } );
ok $res->is_success, '[POST /] successful';
is_deeply decode_json($res->content), { ok => 1, text => 'First Thing to do' };
is $res->header('Content-Type'), 'application/json';
is $res->header('Access-Control-Allow-Origin'), '*';

my $client = MongoDB::MongoClient->new(host => 'localhost', port => 27017);
my $db = $client->get_database( $db_name );
$db->drop;
};

0 comments on commit 93b9d62

Please sign in to comment.
You can’t perform that action at this time.