From b11a9ad951b05d8aa328d5a82f351e44c6b6ce1d Mon Sep 17 00:00:00 2001 From: Petr Janda Date: Fri, 13 Jan 2012 19:43:23 +0100 Subject: [PATCH] add from param to couch repository --- lib/repository/couchRepository.js | 4 ++-- spec/repository/couchRepositorySpec.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/repository/couchRepository.js b/lib/repository/couchRepository.js index 2d1a168..4d149f6 100644 --- a/lib/repository/couchRepository.js +++ b/lib/repository/couchRepository.js @@ -71,12 +71,12 @@ CouchRepository.prototype.getEventsByAggregate = function(aggregateId, callback) * @param {Function} Callback to be triggered. Has to accept array of events. * @return null */ -CouchRepository.prototype.getEventsByName = function(type, callback) { +CouchRepository.prototype.getEventsByName = function(type, from, callback) { var self = this; // Load function itself called once or multiple times. var load = function(type, callback) { - var startKey = '["' + type + '",0]', + var startKey = '["' + type + '",' + from + ']', endKey = '["' + type + '",9999999999999]', params = '?startkey=' + startKey + '&endkey=' + endKey; diff --git a/spec/repository/couchRepositorySpec.js b/spec/repository/couchRepositorySpec.js index ad3083d..819f723 100644 --- a/spec/repository/couchRepositorySpec.js +++ b/spec/repository/couchRepositorySpec.js @@ -91,17 +91,17 @@ describe('CouchRepository', function() { }) it('should call request', function() { - couchdb.getEventsByName('foo', function() {}); + couchdb.getEventsByName('foo', 1000, function() {}); expect(couchdb.request).toHaveBeenCalledWith({ method: 'GET', - path: '/cqrs/_design/cqrs/_view/name?startkey=["foo",0]&endkey=["foo",9999999999999]' + path: '/cqrs/_design/cqrs/_view/name?startkey=["foo",1000]&endkey=["foo",9999999999999]' }, jasmine.any(Function)); }) describe('with event list', function() { it('should call request for each event', function() { - couchdb.getEventsByName(['foo', 'bar'], function() {}); + couchdb.getEventsByName(['foo', 'bar'], 0, function() {}); expect(couchdb.request).toHaveBeenCalledWith({ method: 'GET', @@ -118,7 +118,7 @@ describe('CouchRepository', function() { var foo = {f: function() {}} spyOn(foo, 'f'); - couchdb.getEventsByName(['foo', 'bar'], foo.f); + couchdb.getEventsByName(['foo', 'bar'], 0, foo.f); expect(foo.f).toHaveBeenCalled(); expect(foo.f.callCount).toEqual(1); @@ -130,7 +130,7 @@ describe('CouchRepository', function() { var f = function() {} spyOn(couchdb, 'parseEvents'); - couchdb.getEventsByName('foo', f); + couchdb.getEventsByName('foo', 0, f); expect(couchdb.parseEvents).toHaveBeenCalledWith('{"rows": [{"_id":1, "_ref":1, "value": {"foo": "bar"}}]}', f); })