Browse files

use proper uuid method

  • Loading branch information...
1 parent a0c9903 commit 123a23de2d75893fddcb8d2475554b57feeb1b52 @petrjanda committed Apr 27, 2012
View
6 lib/repository/couchRepository.js
@@ -30,15 +30,17 @@ utils.singleton(CouchRepository);
* @return null
*/
CouchRepository.prototype.storeEvent = function(aggregateId, name, attrs, callback) {
+ var time = utils.uuid();
+
var event = {
aggregateId: aggregateId,
name: name,
type: 'event',
- time: new Date().getTime(),
+ time: time,
attrs: attrs
};
- this.createDocument(JSON.stringify(event), function() {
+ this.createDocument(time, JSON.stringify(event), function() {
if(callback) {
callback(event);
}
View
6 lib/storage/couchStorage.js
@@ -24,11 +24,13 @@ utils.singleton(CouchStorage);
* @param {View} View instance, to be snapshoted.
*/
CouchStorage.prototype.storeView = function(view) {
- this.createDocument(JSON.stringify({
+ var time = utils.uuid();
+
+ this.createDocument(time, JSON.stringify({
viewId: view.uid,
type: 'view',
lastEvent: view.lastEvent,
- time: new Date().getTime(),
+ time: time,
data: view.data
}));
}
View
7 spec/repository/couchRepositorySpec.js
@@ -1,4 +1,5 @@
var http = require('http'),
+ utils = require('../../lib/utils'),
jasmine = require('jasmine-node'),
CouchDb = require('../../lib/repository/couchRepository'),
EventEmitter = require('events').EventEmitter;
@@ -44,11 +45,11 @@ describe('CouchRepository', function() {
describe('storeEvent', function() {
it('should call create document', function() {
spyOn(couchdb, 'createDocument');
- spyOn(Date.prototype, 'getTime').andCallFake(function() { return 123456; })
+ spyOn(utils, 'uuid').andCallFake(function() { return 123456; })
couchdb.storeEvent(1, 'user:created', {foo: 'bar'});
- expect(couchdb.createDocument).toHaveBeenCalledWith(JSON.stringify({
+ expect(couchdb.createDocument).toHaveBeenCalledWith(123456, JSON.stringify({
aggregateId: 1,
name: 'user:created',
type: 'event',
@@ -59,7 +60,7 @@ describe('CouchRepository', function() {
it('should trigger callback if specified', function() {
var foo = {f: function() {}}
- spyOn(couchdb, 'createDocument').andCallFake(function(data, callback) { callback() })
+ spyOn(couchdb, 'createDocument').andCallFake(function(id, data, callback) { callback() })
spyOn(foo, 'f');
couchdb.storeEvent(1, 'user:created', {foo: 'bar'}, foo.f);
View
5 spec/storage/couchStorageSpec.js
@@ -1,4 +1,5 @@
var CouchStorage = require('../../lib/storage/couchStorage'),
+ utils = require('../../lib/utils'),
jasmine = require('jasmine-node');
describe('CouchStorage', function() {
@@ -58,11 +59,11 @@ describe('CouchStorage', function() {
it('should call createDocument', function() {
var view = {uid: 1, lastEvent: 12, data: 'foo'};
spyOn(couchStorage, 'createDocument');
- spyOn(Date.prototype, 'getTime').andCallFake(function() { return 123456; })
+ spyOn(utils, 'uuid').andReturn(123456);
couchStorage.storeView(view);
- expect(couchStorage.createDocument).toHaveBeenCalledWith('{"viewId":1,"type":"view","lastEvent":12,"time":123456,"data":"foo"}');
+ expect(couchStorage.createDocument).toHaveBeenCalledWith(123456, '{"viewId":1,"type":"view","lastEvent":12,"time":123456,"data":"foo"}');
})
})

0 comments on commit 123a23d

Please sign in to comment.