Permalink
Browse files

get rid of uuid

  • Loading branch information...
1 parent a925b0f commit a0c9903e5c55241db6b214fb8837ac9df74a8370 @petrjanda committed Apr 26, 2012
Showing with 10 additions and 65 deletions.
  1. +4 −27 lib/util/couchdb.js
  2. +1 −1 spec/repository/couchRepositorySpec.js
  3. +5 −37 spec/util/couchdbSpec.js
View
@@ -14,42 +14,19 @@ module.exports = CouchDb = function(database, options) {
}
/*
- * UUIDs are random numbers that have such a low collision probability that
- * everybody can make thousands of UUIDs a minute for millions of years without
- * ever creating a duplicate.
- *
- * @param {Function} Function to be called when uuid is received.
- */
-CouchDb.prototype.getUuid = function(callback) {
- this.request({
- method: 'GET',
- path: '/_uuids'
- }, function(data) {
- callback(JSON.parse(data).uuids[0]);
- });
-}
-
-/*
* Documents are CouchDB’s central data structure. The idea behind a document
* is, unsurprisingly, that of a real-world document—a sheet of paper such as
* an invoice, a recipe, or a business card.
*
* @param {String} Document content.
* @param {Function} Function to be called when document is created.
*/
-CouchDb.prototype.createDocument = function(data, callback) {
- var self = this;
-
- this.getUuid(function(uuid) {
- self._db.insert(data, uuid, callback);
- });
+CouchDb.prototype.createDocument = function(id, data, callback) {
+ this._db.insert(data, id, callback);
}
-CouchDb.prototype.deleteDocument = function(id, callback) {
- this.request({
- method: 'DELETE',
- path: this._documentPath(id)
- }, callback);
+CouchDb.prototype.deleteDocument = function(id, rev, callback) {
+ this._db.destroy(id, rev, callback);
}
CouchDb.prototype._documentPath = function(id) {
@@ -13,7 +13,7 @@ describe('CouchRepository', function() {
describe('instance', function() {
it('should get instance of couchdb', function() {
var couchdb = CouchDb.getInstance()
- expect(typeof couchdb.request).toEqual('function');
+ expect(typeof couchdb._db).toEqual('object');
})
it('should return just one instance', function() {
View
@@ -24,54 +24,22 @@ describe('couchdb', function() {
data = JSON.stringify({ foo: 'bar' });
spyOn(couchdb._db, 'insert');
- spyOn(couchdb, 'getUuid').andCallFake(function(callback) {
- callback('1234');
- })
- couchdb.createDocument(data, callback);
+ couchdb.createDocument('1234', data, callback);
expect(couchdb._db.insert).toHaveBeenCalledWith(data, '1234', callback);
})
})
describe('deleteDocument', function() {
it('should call proper request', function() {
- var callback = function() {},
- options = { path: '/cqrs/1234', method: 'DELETE'};
+ var callback = function() {};
- spyOn(couchdb, 'request');
+ spyOn(couchdb._db, 'destroy');
- couchdb.deleteDocument(1234, callback);
-
- expect(couchdb.request).toHaveBeenCalledWith(options, callback);
- })
- })
-
- describe('getUuid', function() {
- it('should call proper request', function() {
- var options = {
- path: '/_uuids',
- method: 'GET',
- };
- spyOn(couchdb, 'request');
-
- couchdb.getUuid(function() {});
-
- expect(couchdb.request).toHaveBeenCalledWith(options, jasmine.any(Function));
- })
-
- it('it should parse value and call callback', function() {
- var foo = { callback: function() {} },
- couchdbRequest = couchdb.request;
-
- couchdb.request = function(options, callback) {
- callback('{"uuids":["a45287db79779654689b4df73a00087a"]}');
- }
- spyOn(foo, 'callback');
-
- couchdb.getUuid(foo.callback);
+ couchdb.deleteDocument(1234, 12345, callback);
- expect(foo.callback).toHaveBeenCalledWith('a45287db79779654689b4df73a00087a');
+ expect(couchdb._db.destroy).toHaveBeenCalledWith(1234, 12345, callback);
})
})

0 comments on commit a0c9903

Please sign in to comment.