Browse files

[fix] fixes follow not working in 0.4

* send exception if you try to use follow in 0.4
  • Loading branch information...
1 parent ab717bf commit 97f67efeeae858fcacadb08b2ccefddba30a7101 @dscape committed May 14, 2012
Showing with 26 additions and 4 deletions.
  1. +20 −1 nano.js
  2. +6 −3 tests/db/follow.js
View
21 nano.js
@@ -19,10 +19,12 @@ var request = require('request')
, qs = require('querystring')
, u = require('url')
, errs = require('errs')
- , follow = require('follow')
+ , follow
, nano
;
+try { follow = require('follow'); } catch (err) {}
+
function isEmpty(object) {
for(var property in object) {
if(object.hasOwnProperty(property)) return false; }
@@ -424,6 +426,23 @@ module.exports = exports = nano = function database_module(cfg) {
params = params || {};
params.db = u.resolve(cfg.url, db_name);
+ if(!follow) {
+ var stream = errs.handle(
+ { "note" : "follow is only supported on node 0.6+"
+ , "scope" : "follow"
+ , "errid" : "no_soup_for_you"
+ }, callback);
+ // streaming mode will call unexisting follow stream
+ stream.follow = function () {
+ return errs.handle(
+ { "note" : "follow is only supported on node 0.6+"
+ , "scope" : "follow"
+ , "errid" : "no_soup_for_you"
+ }, callback);
+ };
+ return stream;
+ }
+
if(typeof callback === "function") {
return follow(params, callback);
} else {
View
9 tests/db/follow.js
@@ -8,6 +8,7 @@ var specify = require('specify')
var mock = nock(helpers.couch, "db/follow")
, db = nano.use("db_follow")
+ , feed
;
specify("db_follow:setup", timeout, function (assert) {
@@ -29,9 +30,8 @@ if(!process.env.NOCK) {
// please run tests with local couchdb
specify("db_follow:stream", timeout, function (assert) {
assert.expect(2);
- var feed = db.follow({since: 2})
- , i = 2
- ;
+ feed = db.follow({since: 3});
+ var i = 3;
feed.on('change', function (change) {
assert.ok(change, "Change existed");
assert.equal(change.seq, i+1, "Seq is set correctly");
@@ -52,6 +52,9 @@ if(!process.env.NOCK) {
}
specify("db_follow:teardown", timeout, function (assert) {
+ if (feed && typeof feed.stop === "function") {
+ feed.stop();
+ }
nano.db.destroy("db_follow", function (err) {
assert.equal(err, undefined, "Failed to destroy database");
assert.ok(mock.isDone(), "Some mocks didn't run");

0 comments on commit 97f67ef

Please sign in to comment.