Permalink
Browse files

create nano instance on constructor

  • Loading branch information...
petrjanda committed Apr 26, 2012
1 parent 0027a28 commit 3a955c17e4973ebed6220835e46b4e60eb7d10c3
Showing with 10 additions and 14 deletions.
  1. +6 −3 lib/util/couchdb.js
  2. +4 −11 spec/util/couchdbSpec.js
View
@@ -1,13 +1,16 @@
-var http = require('http');
+var http = require('http'),
+ nano = require('nano');
module.exports = CouchDb = function(database, options) {
- options = options || {}
-
+ options = options || {};
+
this.database = database || 'cqrs';
this.options = {
host: options.host || 'localhost',
port: options.port || 5984
};
+
+ this._db = nano('http://' + this.options.host + ':' + this.options.port + '/' + database);
}
/*
View
@@ -1,4 +1,5 @@
var http = require('http'),
+ nano = require('nano'),
jasmine = require('jasmine-node'),
CouchDb = require('../../lib/util/couchdb'),
EventEmitter = require('events').EventEmitter;
@@ -11,18 +12,10 @@ describe('couchdb', function() {
})
describe('constructor', function() {
-
- it('should store database name', function() {
- expect(couchdb.database).toEqual('cqrs');
- })
-
- it('host should be default to localhost', function() {
- expect(couchdb.options.host).toEqual('localhost');
+ it('should create nano instance with given attributes', function() {
+ expect(couchdb._db.config.url).toEqual('http://localhost:5984');
+ expect(couchdb._db.config.db).toEqual('cqrs');
})
-
- it('port should be default to localhost', function() {
- expect(couchdb.options.port).toEqual(5984);
- })
})
describe('createDocument', function() {

0 comments on commit 3a955c1

Please sign in to comment.