Skip to content

Commit

Permalink
add from param to couch repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Janda committed Jan 13, 2012
1 parent e695e86 commit b11a9ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/repository/couchRepository.js
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions spec/repository/couchRepositorySpec.js
Expand Up @@ -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',
Expand All @@ -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);
Expand All @@ -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);
})
Expand Down

0 comments on commit b11a9ad

Please sign in to comment.