vulcan 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vulcan/cli.rb +20 -10
- data/lib/vulcan/version.rb +1 -1
- data/server/Procfile +1 -1
- data/server/bin/web +10 -0
- data/server/lib/cloudant.coffee +20 -0
- data/server/lib/logger.coffee +17 -0
- data/server/lib/on.coffee +10 -0
- data/server/lib/spawner.coffee +65 -0
- data/server/node_modules/coffee-script/CNAME +1 -0
- data/server/node_modules/coffee-script/LICENSE +22 -0
- data/server/node_modules/coffee-script/README +51 -0
- data/server/node_modules/coffee-script/Rakefile +78 -0
- data/server/node_modules/coffee-script/bin/cake +7 -0
- data/server/node_modules/coffee-script/bin/coffee +7 -0
- data/server/node_modules/coffee-script/extras/jsl.conf +44 -0
- data/server/node_modules/coffee-script/lib/coffee-script/browser.js +92 -0
- data/server/node_modules/coffee-script/lib/coffee-script/cake.js +111 -0
- data/server/node_modules/coffee-script/lib/coffee-script/coffee-script.js +167 -0
- data/server/node_modules/coffee-script/lib/coffee-script/command.js +500 -0
- data/server/node_modules/coffee-script/lib/coffee-script/grammar.js +606 -0
- data/server/node_modules/coffee-script/lib/coffee-script/helpers.js +77 -0
- data/server/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
- data/server/node_modules/coffee-script/lib/coffee-script/lexer.js +788 -0
- data/server/node_modules/coffee-script/lib/coffee-script/nodes.js +2986 -0
- data/server/node_modules/coffee-script/lib/coffee-script/optparse.js +138 -0
- data/server/node_modules/coffee-script/lib/coffee-script/parser.js +683 -0
- data/server/node_modules/coffee-script/lib/coffee-script/repl.js +261 -0
- data/server/node_modules/coffee-script/lib/coffee-script/rewriter.js +349 -0
- data/server/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
- data/server/node_modules/coffee-script/package.json +55 -0
- data/server/node_modules/connect-form/History.md +0 -6
- data/server/node_modules/connect-form/lib/connect-form.js +2 -4
- data/server/node_modules/connect-form/node_modules/formidable/Readme.md +64 -36
- data/server/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js +5 -1
- data/server/node_modules/connect-form/node_modules/formidable/package.json +20 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/common.js +5 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/file/funkyfilename.txt +1 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/js/special-chars-in-filename.js +1 -1
- data/server/node_modules/connect-form/node_modules/formidable/test/{slow → integration}/test-fixtures.js +38 -33
- data/server/node_modules/connect-form/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/run.js +1 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/unit/test-incoming-form.js +63 -0
- data/server/node_modules/connect-form/package.json +27 -5
- data/server/node_modules/cradle/README.md +10 -10
- data/server/node_modules/cradle/lib/cradle.js +117 -523
- data/server/node_modules/cradle/lib/cradle/database/attachments.js +120 -0
- data/server/node_modules/cradle/lib/cradle/database/changes.js +56 -0
- data/server/node_modules/cradle/lib/cradle/database/documents.js +215 -0
- data/server/node_modules/cradle/lib/cradle/database/index.js +65 -0
- data/server/node_modules/cradle/lib/cradle/database/views.js +125 -0
- data/server/node_modules/cradle/node_modules/follow/LICENSE +202 -0
- data/server/node_modules/cradle/node_modules/follow/README.md +164 -0
- data/server/node_modules/cradle/node_modules/follow/Rakefile +54 -0
- data/server/node_modules/cradle/node_modules/follow/api.js +35 -0
- data/server/node_modules/cradle/node_modules/follow/browser/eventemitter2.js +453 -0
- data/server/node_modules/cradle/node_modules/follow/browser/export.js +78 -0
- data/server/node_modules/cradle/node_modules/follow/browser/index.html +14 -0
- data/server/node_modules/cradle/node_modules/follow/browser/jquery-1.6.1.min.js +18 -0
- data/server/node_modules/cradle/node_modules/follow/browser/log4js.js +46 -0
- data/server/node_modules/cradle/node_modules/follow/browser/main.js +92 -0
- data/server/node_modules/cradle/node_modules/follow/browser/querystring.js +28 -0
- data/server/node_modules/cradle/node_modules/follow/browser/request.jquery.js +237 -0
- data/server/node_modules/cradle/node_modules/follow/browser/require.js +33 -0
- data/server/node_modules/cradle/node_modules/follow/browser/util.js +28 -0
- data/server/node_modules/cradle/node_modules/follow/cli.js +101 -0
- data/server/node_modules/cradle/node_modules/follow/lib/feed.js +556 -0
- data/server/node_modules/cradle/node_modules/follow/lib/index.js +66 -0
- data/server/node_modules/cradle/node_modules/follow/lib/stream.js +305 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/LICENSE +55 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/README.md +285 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/main.js +618 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/mimetypes.js +146 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js +34 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/package.json +42 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/googledoodle.png +0 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/run.sh +6 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/server.js +57 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-body.js +90 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookie.js +29 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookiejar.js +90 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-errors.js +30 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-oauth.js +109 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-pipes.js +167 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-proxy.js +39 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-timeout.js +87 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/uuid.js +19 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/index.js +55 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/jar.js +72 -0
- data/server/node_modules/cradle/node_modules/follow/package.json +45 -0
- data/server/node_modules/cradle/node_modules/follow/test/couch.js +153 -0
- data/server/node_modules/cradle/node_modules/follow/test/follow.js +136 -0
- data/server/node_modules/cradle/node_modules/follow/test/issues.js +178 -0
- data/server/node_modules/cradle/node_modules/follow/test/issues/10.js +24 -0
- data/server/node_modules/cradle/node_modules/follow/test/stream.js +493 -0
- data/server/node_modules/cradle/node_modules/request/LICENSE +55 -0
- data/server/node_modules/cradle/node_modules/request/README.md +287 -0
- data/server/node_modules/cradle/node_modules/request/forever.js +103 -0
- data/server/node_modules/cradle/node_modules/request/main.js +913 -0
- data/server/node_modules/cradle/node_modules/request/mimetypes.js +152 -0
- data/server/node_modules/cradle/node_modules/request/oauth.js +34 -0
- data/server/node_modules/cradle/node_modules/request/package.json +42 -0
- data/server/node_modules/cradle/node_modules/request/tests/googledoodle.png +0 -0
- data/server/node_modules/cradle/node_modules/request/tests/run.js +38 -0
- data/server/node_modules/cradle/node_modules/request/tests/server.js +82 -0
- data/server/node_modules/cradle/node_modules/request/tests/squid.conf +77 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.cnf +20 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crl +0 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crt +17 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.csr +13 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.key +18 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.srl +1 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.cnf +19 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.crt +16 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.csr +11 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.js +28 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.key +9 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/npm-ca.crt +16 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/test.crt +15 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/test.key +15 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-body.js +95 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-cookie.js +29 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-cookiejar.js +90 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-defaults.js +68 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-errors.js +37 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-headers.js +52 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-httpModule.js +94 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-https-strict.js +97 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-https.js +86 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-oauth.js +117 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-params.js +92 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-pipes.js +202 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-proxy.js +39 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-qs.js +28 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-redirect.js +154 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-timeout.js +87 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-toJSON.js +14 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-tunnel.js +61 -0
- data/server/node_modules/cradle/node_modules/request/tunnel.js +229 -0
- data/server/node_modules/cradle/node_modules/request/uuid.js +19 -0
- data/server/node_modules/cradle/node_modules/request/vendor/cookie/index.js +65 -0
- data/server/node_modules/cradle/node_modules/request/vendor/cookie/jar.js +72 -0
- data/server/node_modules/cradle/node_modules/vargs/package.json +33 -10
- data/server/node_modules/cradle/package.json +50 -12
- data/server/node_modules/cradle/test/cache-test.js +1 -4
- data/server/node_modules/cradle/test/connection-test.js +179 -0
- data/server/node_modules/cradle/test/database-attachment-test.js +344 -0
- data/server/node_modules/cradle/test/database-cache-test.js +132 -0
- data/server/node_modules/cradle/test/database-test.js +219 -0
- data/server/node_modules/cradle/test/database-view-test.js +141 -0
- data/server/node_modules/cradle/test/fixtures/databases.json +28 -1
- data/server/node_modules/cradle/test/helpers/seed.js +14 -5
- data/server/node_modules/cradle/test/response-test.js +1 -1
- data/server/node_modules/express/History.md +16 -0
- data/server/node_modules/express/bin/express +7 -6
- data/server/node_modules/express/lib-cov/application.js +510 -0
- data/server/node_modules/express/lib-cov/express.js +65 -0
- data/server/node_modules/express/lib-cov/middleware.js +54 -0
- data/server/node_modules/express/lib-cov/request.js +225 -0
- data/server/node_modules/express/lib-cov/response.js +611 -0
- data/server/node_modules/express/lib-cov/router/collection.js +40 -0
- data/server/node_modules/express/lib-cov/router/index.js +515 -0
- data/server/node_modules/express/lib-cov/router/methods.js +9 -0
- data/server/node_modules/express/lib-cov/router/route.js +68 -0
- data/server/node_modules/express/lib-cov/utils.js +151 -0
- data/server/node_modules/express/lib-cov/view.js +81 -0
- data/server/node_modules/express/lib/express.js +1 -1
- data/server/node_modules/express/lib/http.js +1 -2
- data/server/node_modules/express/lib/request.js +2 -2
- data/server/node_modules/express/lib/router/methods.js +10 -1
- data/server/node_modules/express/node_modules/connect/lib/connect.js +1 -1
- data/server/node_modules/express/node_modules/connect/lib/http.js +3 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/limit.js +0 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/session.js +1 -2
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md +42 -25
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js +1 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/package.json +14 -3
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
- data/server/node_modules/express/node_modules/connect/package.json +35 -7
- data/server/node_modules/express/node_modules/mime/package.json +30 -8
- data/server/node_modules/express/node_modules/mkdirp/README.markdown +35 -2
- data/server/node_modules/express/node_modules/mkdirp/examples/pow.js +1 -1
- data/server/node_modules/express/node_modules/mkdirp/index.js +72 -13
- data/server/node_modules/express/node_modules/mkdirp/package.json +39 -21
- data/server/node_modules/express/node_modules/mkdirp/test/chmod.js +38 -0
- data/server/node_modules/express/node_modules/mkdirp/test/clobber.js +37 -0
- data/server/node_modules/express/node_modules/mkdirp/test/perm.js +32 -0
- data/server/node_modules/express/node_modules/mkdirp/test/perm_sync.js +39 -0
- data/server/node_modules/express/node_modules/mkdirp/test/sync.js +27 -0
- data/server/node_modules/express/node_modules/mkdirp/test/umask.js +28 -0
- data/server/node_modules/express/node_modules/mkdirp/test/umask_sync.js +27 -0
- data/server/node_modules/express/node_modules/qs/History.md +10 -0
- data/server/node_modules/express/node_modules/qs/Readme.md +9 -2
- data/server/node_modules/express/node_modules/qs/examples.js +3 -0
- data/server/node_modules/express/node_modules/qs/lib/querystring.js +8 -6
- data/server/node_modules/express/node_modules/qs/package.json +26 -8
- data/server/node_modules/express/node_modules/qs/test/parse.js +13 -1
- data/server/node_modules/express/node_modules/qs/test/stringify.js +45 -37
- data/server/node_modules/express/package.json +55 -16
- data/server/node_modules/express/test.js +41 -0
- data/server/node_modules/knox/package.json +26 -4
- data/server/node_modules/node-uuid/package.json +40 -11
- data/server/node_modules/node-uuid/test/test.js +1 -1
- data/server/node_modules/nodemon/README.md +120 -0
- data/server/node_modules/nodemon/nodemon.js +518 -0
- data/server/node_modules/nodemon/nodemonignore.example +11 -0
- data/server/node_modules/nodemon/package.json +49 -0
- data/server/node_modules/restler/README.md +144 -94
- data/server/node_modules/restler/lib/multipartform.js +2 -0
- data/server/node_modules/restler/lib/restler.js +218 -61
- data/server/node_modules/restler/package.json +35 -8
- data/server/node_modules/restler/test/all.js +6 -1
- data/server/node_modules/restler/test/restler.js +624 -118
- data/server/package.json +14 -10
- data/server/web.coffee +64 -0
- data/server/web.js +15 -3
- metadata +170 -57
- data/server/index.js +0 -14
- data/server/node_modules/connect-form/LICENSE +0 -22
- data/server/node_modules/connect-form/index.js +0 -100
- data/server/node_modules/connect-form/node_modules/formidable/test/fast/test-incoming-form.js +0 -45
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/cradle/Makefile +0 -10
- data/server/node_modules/cradle/test/cradle-test.js +0 -650
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/express/node_modules/connect/test.js +0 -52
- data/server/node_modules/express/testing/foo/app.js +0 -35
- data/server/node_modules/express/testing/foo/package.json +0 -9
- data/server/node_modules/express/testing/foo/public/stylesheets/style.css +0 -8
- data/server/node_modules/express/testing/foo/routes/index.js +0 -10
- data/server/node_modules/express/testing/foo/views/index.jade +0 -2
- data/server/node_modules/express/testing/foo/views/layout.jade +0 -6
- data/server/node_modules/express/testing/index.js +0 -43
- data/server/node_modules/express/testing/public/test.txt +0 -2971
- data/server/node_modules/express/testing/views/page.html +0 -1
- data/server/node_modules/express/testing/views/page.jade +0 -3
- data/server/node_modules/express/testing/views/test.md +0 -1
- data/server/node_modules/express/testing/views/user/index.jade +0 -1
- data/server/node_modules/express/testing/views/user/list.jade +0 -1
- data/server/node_modules/knox/lib/knox/mime/index.js +0 -308
- data/server/node_modules/knox/lib/knox/mime/test.js +0 -59
- data/server/node_modules/node-uuid/test/benchmark-native +0 -0
- data/server/node_modules/on/index.js +0 -13
- data/server/node_modules/restler/test/test_helper.js +0 -163
- data/server/node_modules/spawner/index.js +0 -106
@@ -0,0 +1,72 @@
|
|
1
|
+
/*!
|
2
|
+
* Tobi - CookieJar
|
3
|
+
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
4
|
+
* MIT Licensed
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Module dependencies.
|
9
|
+
*/
|
10
|
+
|
11
|
+
var url = require('url');
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Initialize a new `CookieJar`.
|
15
|
+
*
|
16
|
+
* @api private
|
17
|
+
*/
|
18
|
+
|
19
|
+
var CookieJar = exports = module.exports = function CookieJar() {
|
20
|
+
this.cookies = [];
|
21
|
+
};
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Add the given `cookie` to the jar.
|
25
|
+
*
|
26
|
+
* @param {Cookie} cookie
|
27
|
+
* @api private
|
28
|
+
*/
|
29
|
+
|
30
|
+
CookieJar.prototype.add = function(cookie){
|
31
|
+
this.cookies = this.cookies.filter(function(c){
|
32
|
+
// Avoid duplication (same path, same name)
|
33
|
+
return !(c.name == cookie.name && c.path == cookie.path);
|
34
|
+
});
|
35
|
+
this.cookies.push(cookie);
|
36
|
+
};
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Get cookies for the given `req`.
|
40
|
+
*
|
41
|
+
* @param {IncomingRequest} req
|
42
|
+
* @return {Array}
|
43
|
+
* @api private
|
44
|
+
*/
|
45
|
+
|
46
|
+
CookieJar.prototype.get = function(req){
|
47
|
+
var path = url.parse(req.url).pathname
|
48
|
+
, now = new Date
|
49
|
+
, specificity = {};
|
50
|
+
return this.cookies.filter(function(cookie){
|
51
|
+
if (0 == path.indexOf(cookie.path) && now < cookie.expires
|
52
|
+
&& cookie.path.length > (specificity[cookie.name] || 0))
|
53
|
+
return specificity[cookie.name] = cookie.path.length;
|
54
|
+
});
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Return Cookie string for the given `req`.
|
59
|
+
*
|
60
|
+
* @param {IncomingRequest} req
|
61
|
+
* @return {String}
|
62
|
+
* @api private
|
63
|
+
*/
|
64
|
+
|
65
|
+
CookieJar.prototype.cookieString = function(req){
|
66
|
+
var cookies = this.get(req);
|
67
|
+
if (cookies.length) {
|
68
|
+
return cookies.map(function(cookie){
|
69
|
+
return cookie.name + '=' + cookie.value;
|
70
|
+
}).join('; ');
|
71
|
+
}
|
72
|
+
};
|
@@ -1,12 +1,35 @@
|
|
1
1
|
{
|
2
|
-
"name"
|
3
|
-
"description"
|
4
|
-
"url"
|
5
|
-
"keywords"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
"
|
10
|
-
|
11
|
-
|
2
|
+
"name": "vargs",
|
3
|
+
"description": "practical variable argument handling",
|
4
|
+
"url": "http://github.com/cloudhead/vargs",
|
5
|
+
"keywords": [
|
6
|
+
"argument",
|
7
|
+
"arguments"
|
8
|
+
],
|
9
|
+
"author": {
|
10
|
+
"name": "Alexis Sellier",
|
11
|
+
"email": "self@cloudhead.net"
|
12
|
+
},
|
13
|
+
"contributors": [],
|
14
|
+
"version": "0.1.0",
|
15
|
+
"main": "./lib/vargs",
|
16
|
+
"directories": {
|
17
|
+
"lib": "./lib"
|
18
|
+
},
|
19
|
+
"engines": {
|
20
|
+
"node": ">=0.1.93"
|
21
|
+
},
|
22
|
+
"_npmUser": {
|
23
|
+
"name": "ddollar",
|
24
|
+
"email": "ddollar@gmail.com"
|
25
|
+
},
|
26
|
+
"_id": "vargs@0.1.0",
|
27
|
+
"dependencies": {},
|
28
|
+
"devDependencies": {},
|
29
|
+
"optionalDependencies": {},
|
30
|
+
"_engineSupported": true,
|
31
|
+
"_npmVersion": "1.1.21",
|
32
|
+
"_nodeVersion": "v0.6.17",
|
33
|
+
"_defaultsLoaded": true,
|
34
|
+
"_from": "vargs@0.1.0"
|
12
35
|
}
|
@@ -1,14 +1,52 @@
|
|
1
1
|
{
|
2
|
-
"name"
|
3
|
-
"
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
"
|
12
|
-
|
13
|
-
|
2
|
+
"name": "cradle",
|
3
|
+
"version": "0.6.3",
|
4
|
+
"description": "the high-level, caching, CouchDB library",
|
5
|
+
"url": "http://cloudhead.io/cradle",
|
6
|
+
"keywords": [
|
7
|
+
"couchdb",
|
8
|
+
"database",
|
9
|
+
"couch"
|
10
|
+
],
|
11
|
+
"author": {
|
12
|
+
"name": "Alexis Sellier",
|
13
|
+
"email": "self@cloudhead.net"
|
14
|
+
},
|
15
|
+
"contributors": [
|
16
|
+
{
|
17
|
+
"name": "Charlie Robbins",
|
18
|
+
"email": "charlie@nodejitsu.com"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"name": "Maciej Malecki",
|
22
|
+
"email": "maciej@nodejitsu.com"
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"main": "./lib/cradle",
|
26
|
+
"dependencies": {
|
27
|
+
"follow": "0.7.x",
|
28
|
+
"request": "2.x.x",
|
29
|
+
"vargs": "0.1.0"
|
30
|
+
},
|
31
|
+
"devDependencies": {
|
32
|
+
"async": "~0.1.x",
|
33
|
+
"vows": "0.6.x"
|
34
|
+
},
|
35
|
+
"scripts": {
|
36
|
+
"test": "node test/helpers/seed.js && vows --spec"
|
37
|
+
},
|
38
|
+
"engines": {
|
39
|
+
"node": ">=0.6.0"
|
40
|
+
},
|
41
|
+
"_npmUser": {
|
42
|
+
"name": "ddollar",
|
43
|
+
"email": "ddollar@gmail.com"
|
44
|
+
},
|
45
|
+
"_id": "cradle@0.6.3",
|
46
|
+
"optionalDependencies": {},
|
47
|
+
"_engineSupported": true,
|
48
|
+
"_npmVersion": "1.1.21",
|
49
|
+
"_nodeVersion": "v0.6.17",
|
50
|
+
"_defaultsLoaded": true,
|
51
|
+
"_from": "cradle@0.6.x"
|
14
52
|
}
|
@@ -5,17 +5,15 @@ var path = require('path'),
|
|
5
5
|
|
6
6
|
var cradle = require('../lib/cradle');
|
7
7
|
|
8
|
-
vows.describe('cradle/
|
8
|
+
vows.describe('cradle/cache').addBatch({
|
9
9
|
'A cradle.Connection instance with a *cacheSize* specified': {
|
10
10
|
topic: new(cradle.Connection)({ cache: true, cacheSize: 16 }),
|
11
|
-
|
12
11
|
'should set the database cache size appropriately': function (topic) {
|
13
12
|
assert.equal (topic.database('random').cache.size, 16);
|
14
13
|
}
|
15
14
|
},
|
16
15
|
'A cradle.Cache instance with a *cacheSize* of `8`': {
|
17
16
|
topic: new(cradle.Cache)({ cache: true, cacheSize: 8 }),
|
18
|
-
|
19
17
|
'should be able to store 8 keys': function (topic) {
|
20
18
|
for (var i = 0; i < 8; i++) { topic.save(i.toString(), {}) }
|
21
19
|
assert.lengthOf (Object.keys(topic.store), 8);
|
@@ -76,7 +74,6 @@ vows.describe('cradle/Cache').addBatch({
|
|
76
74
|
},
|
77
75
|
'A cradle.Cache instance with a *cacheSize* of *1024*': {
|
78
76
|
topic: new(cradle.Cache)({ cache: true, cacheSize: 1024 }),
|
79
|
-
|
80
77
|
'setting 4096 keys': {
|
81
78
|
topic: function (cache) {
|
82
79
|
var that = this;
|
@@ -0,0 +1,179 @@
|
|
1
|
+
var path = require('path'),
|
2
|
+
assert = require('assert'),
|
3
|
+
events = require('events'),
|
4
|
+
http = require('http'),
|
5
|
+
fs = require('fs'),
|
6
|
+
vows = require('vows');
|
7
|
+
|
8
|
+
function status(code) {
|
9
|
+
return function (e, res) {
|
10
|
+
assert.ok(res || e);
|
11
|
+
assert.equal((res || e).headers.status || (res || e).status, code);
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
var cradle = require('../lib/cradle');
|
16
|
+
|
17
|
+
vows.describe('cradle/connection').addBatch({
|
18
|
+
"Default connection settings": {
|
19
|
+
topic: function () {
|
20
|
+
cradle.setup({
|
21
|
+
host: "http://cloudhead.io",
|
22
|
+
port: 4242,
|
23
|
+
milk: 'white'
|
24
|
+
});
|
25
|
+
return new(cradle.Connection);
|
26
|
+
},
|
27
|
+
"should be carried on to new Connections": function (c) {
|
28
|
+
assert.equal(c.host, "cloudhead.io");
|
29
|
+
assert.equal(c.protocol, "http");
|
30
|
+
assert.equal(c.port, 4242);
|
31
|
+
assert.equal(c.options.milk, 'white');
|
32
|
+
assert.equal(c.options.cache, true);
|
33
|
+
},
|
34
|
+
"with just a {} passed to a new Connection object": {
|
35
|
+
topic: function () { return new(cradle.Connection)({milk: 'green'}) },
|
36
|
+
"should override the defaults": function (c) {
|
37
|
+
assert.equal(c.options.milk, 'green');
|
38
|
+
assert.equal(c.port, 4242);
|
39
|
+
}
|
40
|
+
},
|
41
|
+
"with a host and port passed to Connection": {
|
42
|
+
topic: function () { return new(cradle.Connection)("255.255.0.0", 9696) },
|
43
|
+
"should override the defaults": function (c) {
|
44
|
+
assert.equal(c.host, '255.255.0.0');
|
45
|
+
assert.equal(c.port, 9696);
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"with a host, port and options passed to Connection": {
|
49
|
+
topic: function () { return new(cradle.Connection)("4.4.4.4", 911, {raw: true}) },
|
50
|
+
"should override the defaults": function (c) {
|
51
|
+
assert.equal(c.host, '4.4.4.4');
|
52
|
+
assert.equal(c.port, 911);
|
53
|
+
assert.equal(c.options.raw, true);
|
54
|
+
}
|
55
|
+
},
|
56
|
+
"with a host and port and protocol passed to Connection": {
|
57
|
+
topic: function () { return new(cradle.Connection)("http://4.4.4.4", 911, {raw: true, secure: true}) },
|
58
|
+
"should override the defaults": function (c) {
|
59
|
+
assert.equal(c.host, '4.4.4.4');
|
60
|
+
assert.equal(c.port, 911);
|
61
|
+
assert.equal(c.options.raw, true);
|
62
|
+
assert.equal(c.options.secure, true);
|
63
|
+
}
|
64
|
+
},
|
65
|
+
"with a host and port passed as an object to Connection": {
|
66
|
+
topic: function () { return new(cradle.Connection)({ host: "https://4.4.4.4", port: 911, raw: true }) },
|
67
|
+
"should override the defaults": function (c) {
|
68
|
+
assert.equal(c.options.secure, true);
|
69
|
+
assert.equal(c.host, '4.4.4.4');
|
70
|
+
assert.equal(c.port, 911);
|
71
|
+
assert.equal(c.options.raw, true);
|
72
|
+
}
|
73
|
+
},
|
74
|
+
"with a the 'https' protocol": {
|
75
|
+
topic: function () { return new(cradle.Connection)("https://couch.io", 5984) },
|
76
|
+
"should set 'secure' to `true`": function (c) {
|
77
|
+
assert.equal(c.protocol, 'https');
|
78
|
+
assert.equal(c.options.secure, true);
|
79
|
+
assert.equal(c.host, 'couch.io');
|
80
|
+
assert.equal(c.port, 5984);
|
81
|
+
}
|
82
|
+
},
|
83
|
+
"with the port as part of the URL": {
|
84
|
+
topic: function () { return new(cradle.Connection)("https://couch.io:418") },
|
85
|
+
"should read the port from the URL": function (c) {
|
86
|
+
assert.equal(c.protocol, 'https');
|
87
|
+
assert.equal(c.options.secure, true);
|
88
|
+
assert.equal(c.host, 'couch.io');
|
89
|
+
assert.equal(c.port, 418);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}).addBatch({
|
94
|
+
"Connection": {
|
95
|
+
topic: function () {
|
96
|
+
return new(cradle.Connection)('127.0.0.1', 5984, {cache: false});
|
97
|
+
},
|
98
|
+
"getting server info": {
|
99
|
+
topic: function (c) { c.info(this.callback) },
|
100
|
+
|
101
|
+
"returns a 200": status(200),
|
102
|
+
"returns the version number": function (info) {
|
103
|
+
assert.ok(info);
|
104
|
+
assert.match(info.version, /\d+\.\d+\.\d+/);
|
105
|
+
}
|
106
|
+
},
|
107
|
+
"uuids()": {
|
108
|
+
"with count": {
|
109
|
+
topic: function (c) { c.uuids(42, this.callback) },
|
110
|
+
|
111
|
+
"returns a 200": status(200),
|
112
|
+
"returns an array of UUIDs": function (uuids) {
|
113
|
+
assert.isArray(uuids);
|
114
|
+
assert.lengthOf(uuids, 42);
|
115
|
+
}
|
116
|
+
},
|
117
|
+
"without count": {
|
118
|
+
topic: function (c) { c.uuids(this.callback) },
|
119
|
+
|
120
|
+
"returns a 200": status(200),
|
121
|
+
"returns an array of UUIDs": function (uuids) {
|
122
|
+
assert.isArray(uuids);
|
123
|
+
assert.lengthOf(uuids, 1);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
},
|
127
|
+
"getting the list of databases": {
|
128
|
+
topic: function (c) {
|
129
|
+
c.databases(this.callback);
|
130
|
+
},
|
131
|
+
"should contain the 'rabbits' and 'pigs' databases": function (dbs) {
|
132
|
+
assert.isArray(dbs);
|
133
|
+
assert.include(dbs, 'rabbits');
|
134
|
+
assert.include(dbs, 'pigs');
|
135
|
+
}
|
136
|
+
},
|
137
|
+
}
|
138
|
+
}).addBatch({
|
139
|
+
"Connection": {
|
140
|
+
topic: function () {
|
141
|
+
return new(cradle.Connection)('127.0.0.1', 5984, {cache: false});
|
142
|
+
},
|
143
|
+
"create()": {
|
144
|
+
"with no / in the name": {
|
145
|
+
topic: function (c) {
|
146
|
+
c.database('badgers').create(this.callback);
|
147
|
+
},
|
148
|
+
"returns a 201": status(201),
|
149
|
+
"creates a database": {
|
150
|
+
topic: function (res, c) { c.database('badgers').exists(this.callback) },
|
151
|
+
"it exists": function (res) { assert.ok(res) }
|
152
|
+
}
|
153
|
+
},
|
154
|
+
"with a / in the name": {
|
155
|
+
topic: function (c) {
|
156
|
+
c.database('madeup/ewoks').create(this.callback);
|
157
|
+
},
|
158
|
+
"returns a 201": status(201),
|
159
|
+
"creates a database": {
|
160
|
+
topic: function (res, c) { c.database('madeup/ewoks').exists(this.callback) },
|
161
|
+
"it exists": function (res) { assert.ok(res) }
|
162
|
+
}
|
163
|
+
|
164
|
+
}
|
165
|
+
},
|
166
|
+
"destroy()": {
|
167
|
+
topic: function (c) {
|
168
|
+
c.database('rabbits').destroy(this.callback);
|
169
|
+
},
|
170
|
+
"returns a 200": status(200),
|
171
|
+
"destroys a database": {
|
172
|
+
topic: function (res, c) {
|
173
|
+
c.database('rabbits').exists(this.callback);
|
174
|
+
},
|
175
|
+
"it doesn't exist anymore": function (res) { assert.ok(! res) }
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}).export(module);
|
@@ -0,0 +1,344 @@
|
|
1
|
+
var path = require('path'),
|
2
|
+
assert = require('assert'),
|
3
|
+
events = require('events'),
|
4
|
+
http = require('http'),
|
5
|
+
fs = require('fs'),
|
6
|
+
vows = require('vows');
|
7
|
+
|
8
|
+
function status(code) {
|
9
|
+
return function (e, res, body) {
|
10
|
+
assert.ok(res || e);
|
11
|
+
assert.equal((res || e).headers.status || (res || e).statusCode, code);
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
function mixin(target) {
|
16
|
+
var objs = Array.prototype.slice.call(arguments, 1);
|
17
|
+
objs.forEach(function (o) {
|
18
|
+
for (var attr in o) { target[attr] = o[attr] }
|
19
|
+
});
|
20
|
+
return target;
|
21
|
+
}
|
22
|
+
|
23
|
+
var cradle = require('../lib/cradle');
|
24
|
+
|
25
|
+
vows.describe('cradle/database/attachments').addBatch({
|
26
|
+
"Database with cache": {
|
27
|
+
topic: function () {
|
28
|
+
return new(cradle.Connection)('127.0.0.1', 5984, { cache: true }).database('pigs');
|
29
|
+
},
|
30
|
+
"saveAttachment()": {
|
31
|
+
"updates the cache": {
|
32
|
+
topic: function (db) {
|
33
|
+
var that = this;
|
34
|
+
db.save({ _id: 'attachment-cacher' }, function (e, res) {
|
35
|
+
db.saveAttachment({
|
36
|
+
id: res.id,
|
37
|
+
rev: res.rev
|
38
|
+
}, {
|
39
|
+
name: 'cached/foo.txt',
|
40
|
+
'Content-Type': 'text/plain',
|
41
|
+
body: 'Foo!'
|
42
|
+
}, function () {
|
43
|
+
that.callback(null, db.cache.get(res.id));
|
44
|
+
});
|
45
|
+
});
|
46
|
+
},
|
47
|
+
"with the revision": function (cached) {
|
48
|
+
assert.match(cached._rev, /^2-/);
|
49
|
+
},
|
50
|
+
"with the _attachments": function (cached) {
|
51
|
+
assert.ok(cached._attachments);
|
52
|
+
assert.ok(cached._attachments['cached/foo.txt']);
|
53
|
+
assert.equal(cached._attachments['cached/foo.txt'].stub, true);
|
54
|
+
},
|
55
|
+
"and is valid enough to re-save": {
|
56
|
+
topic: function (cached, db) {
|
57
|
+
var that = this
|
58
|
+
db.save(mixin({ foo: 'bar' }, cached), function (e,res) {
|
59
|
+
db.cache.purge(cached._id);
|
60
|
+
db.get(cached._id, that.callback);
|
61
|
+
});
|
62
|
+
},
|
63
|
+
"has the attachment": function (res) {
|
64
|
+
var att = res._attachments['cached/foo.txt'];
|
65
|
+
assert.equal(att.stub, true);
|
66
|
+
assert.equal(att.content_type, 'text/plain');
|
67
|
+
assert.equal(att.length, 4);
|
68
|
+
assert.equal(att.revpos, 2);
|
69
|
+
},
|
70
|
+
"and actually updated the rev": function (res) {
|
71
|
+
assert.match(res._rev, /^3-/);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
},
|
75
|
+
"pulls the revision from the cache if not given": {
|
76
|
+
topic: function (db) {
|
77
|
+
var callback = this.callback;
|
78
|
+
db.save({ _id: 'attachment-saving-pulls-rev-from-cache' }, function (e, res) {
|
79
|
+
db.saveAttachment(res.id, {
|
80
|
+
name: 'foo.txt',
|
81
|
+
contentType: 'text/plain',
|
82
|
+
body: 'Foo!'
|
83
|
+
}, callback);
|
84
|
+
});
|
85
|
+
},
|
86
|
+
"and saves successfully": status(201)
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}).addBatch({
|
91
|
+
"Database with no cache": {
|
92
|
+
topic: function () {
|
93
|
+
return new(cradle.Connection)('127.0.0.1', 5984, {cache: false}).database('pigs');
|
94
|
+
},
|
95
|
+
"putting an attachment": {
|
96
|
+
"to an existing document": {
|
97
|
+
"with given data": {
|
98
|
+
topic: function (db) {
|
99
|
+
var that = this;
|
100
|
+
db.save({_id: 'complete-attachment'}, function (e, res) {
|
101
|
+
db.saveAttachment({
|
102
|
+
id: res.id,
|
103
|
+
rev: res.rev
|
104
|
+
}, {
|
105
|
+
name: 'foo.txt',
|
106
|
+
'content-type': 'text/plain',
|
107
|
+
body: 'Foo!'
|
108
|
+
}, that.callback);
|
109
|
+
});
|
110
|
+
},
|
111
|
+
"returns a 201": status(201),
|
112
|
+
"returns the revision": function (res) {
|
113
|
+
assert.ok(res.rev);
|
114
|
+
assert.match(res.rev, /^2/);
|
115
|
+
},
|
116
|
+
},
|
117
|
+
"when piping": {
|
118
|
+
topic: function (db) {
|
119
|
+
var callback = this.callback, filestream;
|
120
|
+
db.save({ _id: 'piped-attachment' }, function (e, res) {
|
121
|
+
var stream = db.saveAttachment({
|
122
|
+
id: res.id,
|
123
|
+
rev: res.rev
|
124
|
+
}, {
|
125
|
+
name: 'foo.txt',
|
126
|
+
contentType: 'text/plain'
|
127
|
+
}, callback);
|
128
|
+
|
129
|
+
fs.createReadStream(__dirname + "/../README.md").pipe(stream);
|
130
|
+
});
|
131
|
+
},
|
132
|
+
"returns a 201": status(201),
|
133
|
+
"returns the revision": function (res) {
|
134
|
+
assert.ok(res.rev);
|
135
|
+
assert.match(res.rev, /^2/);
|
136
|
+
}
|
137
|
+
},
|
138
|
+
"with incorrect revision": {
|
139
|
+
topic: function (db) {
|
140
|
+
var callback = this.callback, oldRev;
|
141
|
+
db.save({ _id: 'attachment-incorrect-revision' }, function (e, res) {
|
142
|
+
oldRev = res.rev;
|
143
|
+
db.save({_id: 'attachment-incorrect-revision', _rev:res.rev}, function (e, res) {
|
144
|
+
db.saveAttachment({
|
145
|
+
id: res.id,
|
146
|
+
rev: oldRev
|
147
|
+
}, {
|
148
|
+
name: 'foo.txt',
|
149
|
+
contentType: 'text/plain',
|
150
|
+
body: 'Foo!'
|
151
|
+
}, callback);
|
152
|
+
});
|
153
|
+
});
|
154
|
+
},
|
155
|
+
"returns a 409": status(409)
|
156
|
+
}
|
157
|
+
},
|
158
|
+
"to a non-existing document": {
|
159
|
+
topic: function (db) {
|
160
|
+
db.saveAttachment('standalone-attachment', {
|
161
|
+
name: 'foo.txt',
|
162
|
+
contentType: 'text/plain',
|
163
|
+
body: 'Foo!'
|
164
|
+
}, this.callback);
|
165
|
+
},
|
166
|
+
"returns a 201": status(201),
|
167
|
+
"returns the revision": function (res) {
|
168
|
+
assert.ok(res.rev);
|
169
|
+
assert.match(res.rev, /^1-/);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
},
|
173
|
+
"getting an attachment": {
|
174
|
+
"when it exists": {
|
175
|
+
topic: function (db) {
|
176
|
+
var that = this, doc = {
|
177
|
+
_id: 'attachment-getter',
|
178
|
+
_attachments: {
|
179
|
+
"foo.txt": {
|
180
|
+
content_type: "text/plain",
|
181
|
+
data: "aGVsbG8gd29ybGQ="
|
182
|
+
}
|
183
|
+
}
|
184
|
+
};
|
185
|
+
|
186
|
+
db.save(doc, function (e, res) {
|
187
|
+
db.getAttachment('attachment-getter', 'foo.txt', that.callback);
|
188
|
+
});
|
189
|
+
},
|
190
|
+
"returns a 200": status(200),
|
191
|
+
"returns the right mime-type in the header": function (err, res, body) {
|
192
|
+
assert.equal(res.headers['content-type'], 'text/plain');
|
193
|
+
},
|
194
|
+
"returns the attachment in the body": function (err, res, body) {
|
195
|
+
assert.equal(body, "hello world");
|
196
|
+
}
|
197
|
+
},
|
198
|
+
"when not found": {
|
199
|
+
topic: function (db) {
|
200
|
+
var that = this;
|
201
|
+
db.save({ _id: 'attachment-not-found' }, function (e, res) {
|
202
|
+
db.getAttachment('attachment-not-found', 'foo.txt', that.callback);
|
203
|
+
});
|
204
|
+
},
|
205
|
+
"returns a 404": status(404)
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}).addBatch({
|
210
|
+
"Database with no cache": {
|
211
|
+
topic: function () {
|
212
|
+
return new(cradle.Connection)('127.0.0.1', 5984, {cache: false}).database('pigs');
|
213
|
+
},
|
214
|
+
"saving an attachment with ETag": {
|
215
|
+
topic: function (db) {
|
216
|
+
var id = 'attachment-incorrect-revision',
|
217
|
+
that = this;
|
218
|
+
|
219
|
+
db.head('attachment-incorrect-revision', function (err, _doc) {
|
220
|
+
db.saveAttachment({
|
221
|
+
id: id,
|
222
|
+
rev: _doc.etag,
|
223
|
+
}, {
|
224
|
+
name: 'etag-foo.txt',
|
225
|
+
contentType: 'text/plain',
|
226
|
+
body: 'FOOO!!'
|
227
|
+
}, that.callback);
|
228
|
+
});
|
229
|
+
},
|
230
|
+
"returns a 201": status(201),
|
231
|
+
"returns the revision": function (res) {
|
232
|
+
assert.ok(res.rev);
|
233
|
+
assert.match(res.rev, /^3/);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}).addBatch({
|
238
|
+
"Database with no cache": {
|
239
|
+
topic: function () {
|
240
|
+
return new(cradle.Connection)('127.0.0.1', 5984, {cache: false}).database('pigs');
|
241
|
+
},
|
242
|
+
"getting an attachment with .pipe()": {
|
243
|
+
"when it exists": {
|
244
|
+
topic: function (db) {
|
245
|
+
var stream = db.getAttachment('piped-attachment', 'foo.txt', this.callback);
|
246
|
+
stream.pipe(fs.createWriteStream(path.join(__dirname, 'fixtures', 'README.md')));
|
247
|
+
},
|
248
|
+
"returns a 200": status(200),
|
249
|
+
"returns the right mime-type in the header": function (err, res, body) {
|
250
|
+
assert.equal(res.headers['content-type'], 'text/plain');
|
251
|
+
},
|
252
|
+
"should write the correct attachment to disk": function (err, res, body) {
|
253
|
+
assert.isNull(err);
|
254
|
+
|
255
|
+
assert.equal(
|
256
|
+
fs.readFileSync(path.join(__dirname, '..', 'README.md'), 'utf8'),
|
257
|
+
fs.readFileSync(path.join(__dirname, 'fixtures', 'README.md'), 'utf8')
|
258
|
+
);
|
259
|
+
}
|
260
|
+
},
|
261
|
+
"when not found": {
|
262
|
+
topic: function (db) {
|
263
|
+
var stream = db.getAttachment('attachment-not-found', 'foo.txt');
|
264
|
+
stream.pipe(fs.createWriteStream(path.join(__dirname, 'fixtures', 'not-found.txt')));
|
265
|
+
|
266
|
+
stream.on('end', this.callback);
|
267
|
+
},
|
268
|
+
"should write the error to disk": function () {
|
269
|
+
var result = JSON.parse(
|
270
|
+
fs.readFileSync(path.join(__dirname, 'fixtures', 'not-found.txt'), 'utf8')
|
271
|
+
);
|
272
|
+
|
273
|
+
assert.equal(result.reason, 'Document is missing attachment');
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}).addBatch({
|
279
|
+
"Database with no cache": {
|
280
|
+
topic: function () {
|
281
|
+
return new(cradle.Connection)('127.0.0.1', 5984, { cache: false }).database('pigs');
|
282
|
+
},
|
283
|
+
"removeAttachment()": {
|
284
|
+
"when it exists": {
|
285
|
+
topic: function (db) {
|
286
|
+
var that = this;
|
287
|
+
db.get('attachment-getter', function (err, doc) {
|
288
|
+
db.removeAttachment(doc, 'foo.txt', that.callback);
|
289
|
+
});
|
290
|
+
},
|
291
|
+
"should remove the attachment": function (err, res) {
|
292
|
+
assert.isNull(err);
|
293
|
+
assert.ok(res.ok);
|
294
|
+
}
|
295
|
+
},
|
296
|
+
"when the document doesnt exist": {
|
297
|
+
topic: function (db) {
|
298
|
+
db.removeAttachment({
|
299
|
+
id: 'YUNOEXIST',
|
300
|
+
rev: '2-6bb732ce2ecc7ac85567b444b10590b4'
|
301
|
+
}, 'foo.txt', this.callback.bind(this, null));
|
302
|
+
},
|
303
|
+
"should respond with the correct error": function (_, err) {
|
304
|
+
assert.isObject(err);
|
305
|
+
assert.equal(err.headers.status, 500);
|
306
|
+
assert.equal(err.error, '{not_found,missing}');
|
307
|
+
}
|
308
|
+
}
|
309
|
+
}
|
310
|
+
}
|
311
|
+
}).addBatch({
|
312
|
+
"Database with cache": {
|
313
|
+
topic: function () {
|
314
|
+
return new(cradle.Connection)('127.0.0.1', 5984, { cache: true }).database('pigs');
|
315
|
+
},
|
316
|
+
"removeAttachment()": {
|
317
|
+
"when it exists": {
|
318
|
+
topic: function (db) {
|
319
|
+
var that = this;
|
320
|
+
db.get('attachment-cacher', function (err, doc) {
|
321
|
+
db.removeAttachment(doc._id, 'cached/foo.txt', that.callback);
|
322
|
+
});
|
323
|
+
},
|
324
|
+
"should remove the attachment": function (err, res) {
|
325
|
+
assert.isNull(err);
|
326
|
+
assert.ok(res.ok);
|
327
|
+
}
|
328
|
+
},
|
329
|
+
"when the document doesnt exist": {
|
330
|
+
topic: function (db) {
|
331
|
+
db.removeAttachment({
|
332
|
+
id: 'YUNOEXIST',
|
333
|
+
rev: '2-6bb732ce2ecc7ac85567b444b10590b4'
|
334
|
+
}, 'foo.txt', this.callback.bind(this, null));
|
335
|
+
},
|
336
|
+
"should respond with the correct error": function (_, err) {
|
337
|
+
assert.isObject(err);
|
338
|
+
assert.equal(err.headers.status, 500);
|
339
|
+
assert.equal(err.error, '{not_found,missing}');
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}).export(module);
|