Permalink
Browse files

refactor create function

  • Loading branch information...
1 parent 3a955c1 commit a925b0f4d3022e9bf2668a4cf1e21c5330a095cd @petrjanda committed Apr 26, 2012
Showing with 4 additions and 9 deletions.
  1. +1 −5 lib/util/couchdb.js
  2. +3 −4 spec/util/couchdbSpec.js
View
@@ -41,11 +41,7 @@ CouchDb.prototype.createDocument = function(data, callback) {
var self = this;
this.getUuid(function(uuid) {
- self.request({
- method: 'PUT',
- path: self._documentPath(uuid),
- data: data
- }, callback);
+ self._db.insert(data, uuid, callback);
});
}
View
@@ -21,17 +21,16 @@ describe('couchdb', function() {
describe('createDocument', function() {
it('should call proper request', function() {
var callback = function() {},
- data = JSON.stringify({ foo: 'bar' }),
- options = { path: '/cqrs/1234', method: 'PUT', data: data };
+ data = JSON.stringify({ foo: 'bar' });
- spyOn(couchdb, 'request');
+ spyOn(couchdb._db, 'insert');
spyOn(couchdb, 'getUuid').andCallFake(function(callback) {
callback('1234');
})
couchdb.createDocument(data, callback);
- expect(couchdb.request).toHaveBeenCalledWith(options, callback);
+ expect(couchdb._db.insert).toHaveBeenCalledWith(data, '1234', callback);
})
})

0 comments on commit a925b0f

Please sign in to comment.