Skip to content

Instantly share code, notes, and snippets.

@phreax
Created April 5, 2011 18:37
Show Gist options
  • Save phreax/904207 to your computer and use it in GitHub Desktop.
Save phreax/904207 to your computer and use it in GitHub Desktop.
specification of changes middleware
var vows = require('vows');
var assert = require('assert');
var app = require('app'),
db = app.db;
var inter = inter;
var http = require('http');
var sys = require('sys');
var _ = require('underscore');
var request = require('request');
var path = require('path');
var fs = require('fs');
var createDocuments = function(names,docstate) {
// Fixtures
var documents = {
'invoice': {title: 'Invoice #1', type: 'document', tags: ['invoice'], state: docstate},
'letter': {title: 'Letter #1', type: 'document', tags: ['letter'], state: docstate},
'letter2': {title: 'Letter #2', type: 'document', tags: ['letter'], state: docstate}
}
return function() {
var docs = names.map(function(name) { return documents[name] });
db.save(docs, _.bind(function(e, res) {
var expected = names.map(function(name, i) {
return {
id: res[i].id,
key: null,
value: _.extend({_id: res[i].id, _rev: res[i].rev}, docs[i])
}
});
this.callback(e, expected);
}, this));
}
}
var suite = vows.describe('subject');
suite.addBatch({
'Adding documents with state new': {
topic: createDocuments(['invoice','letter'],'new'),
'pull new documents': {
topic: pullNewDocs(),
'Should be invoice and letter':
},
topic: createDocuments(['letter2'],'new'),
'receive new changes' {
topic: getChanges(),
'Should be letter2':
}
}
'When connection is resetted': {
topic: resetConnection(),
'pull new documents': {
topic: pullNewDocs(),
'Should be invoice and letter and letter2':
},
'receive new changes' {
topic: getChanges(),
'Should be letter2':
}
},
'Updating documents': {
topic: updateDocuments(['letter2'],'processing'),
'pull new documents': {
topic: pullNewDocs(),
'Should be letter2':
},
'receive changes': {
topic: getChanges(),
'Should still be letter2':
}
},
'Update last document': {
topic: updateDocuments['letter2'],'processing'),
'pull new documents': {
topic: pullNewDocs(),
'Should be be nothing':
},
'receive changes': {
topic: getChanges(),
'should be nothing':
}
},
'Resetting connection with new docs': {
topic: createDocuments(['invoice','letter'],'new'),
'pull new documents': {
topic: pullNewDocs(),
'Should be invoice and letter':
},
topic: createDocuments(['letter2'],'new'),
'receive new changes' {
topic: getChanges(),
'Should be letter2':
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment