Skip to content

Commit

Permalink
[dist] 1.3.2
Browse files Browse the repository at this point in the history
minor api change to add support to pass path as a string with no options
  • Loading branch information
dscape committed Feb 17, 2012
1 parent 0ad8b89 commit 0000c1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions nano.js
Expand Up @@ -67,7 +67,8 @@ module.exports = exports = nano = function database_module(cfg) {
* @error {request:socket} problem connecting to couchdb * @error {request:socket} problem connecting to couchdb
* @error {couch:*} an error proxied from couchdb * @error {couch:*} an error proxied from couchdb
* *
* @param {opts:object} request options; e.g. {db: "test", method: "GET"} * @param {opts:object|string} request options;
* e.g. {db: "test", method: "GET"}
* {opts.db:string} database name * {opts.db:string} database name
* {opts.method:string:optional} http method, defaults to "GET" * {opts.method:string:optional} http method, defaults to "GET"
* {opts.path:string:optional} a full path, override `doc` and `att` * {opts.path:string:optional} a full path, override `doc` and `att`
Expand All @@ -79,21 +80,22 @@ module.exports = exports = nano = function database_module(cfg) {
* @param {callback:function:optional} function to call back * @param {callback:function:optional} function to call back
*/ */
function relax(opts,callback) { function relax(opts,callback) {
if(typeof opts === 'string') { opts = {path: opts}; }
var log = logging(); var log = logging();
var headers = { "content-type": "application/json" var headers = { "content-type": "application/json"
, "accept" : "application/json" , "accept" : "application/json"
} }
, req = { method : (opts.method || "GET") , req = { method : (opts.method || "GET")
, headers: headers , headers: headers
, uri : cfg.url + "/" + opts.db } , uri : cfg.url }
, params = opts.params , params = opts.params
, status_code , status_code
, parsed , parsed
, rh , rh
; ;


if (opts.jar) { req.jar = opts.jar; } if (opts.jar) { req.jar = opts.jar; }

if(opts.db) { req.uri += "/" + opts.db; }
if(opts.path) { req.uri += "/" + opts.path; } if(opts.path) { req.uri += "/" + opts.path; }
else if(opts.doc) { else if(opts.doc) {
if(!/^_design/.test(opts.doc)) { if(!/^_design/.test(opts.doc)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
, "description" : "minimalistic couchdb driver for node.js" , "description" : "minimalistic couchdb driver for node.js"
, "homepage" : "http://github.com/dscape/nano" , "homepage" : "http://github.com/dscape/nano"
, "repository" : "git://github.com/dscape/nano" , "repository" : "git://github.com/dscape/nano"
, "version" : "1.3.1" , "version" : "1.3.2"
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" , "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"
, "contributors" : , "contributors" :
[ "Thiago Arrais <thiago.arrais@gmail.com> (http://thiagoarrais.com)" [ "Thiago Arrais <thiago.arrais@gmail.com> (http://thiagoarrais.com)"
Expand Down
8 changes: 8 additions & 0 deletions tests/shared/cfg.js
Expand Up @@ -7,6 +7,8 @@ var ensure = require('ensure')
; ;


couch = nock(cfg.url) couch = nock(cfg.url)
.get('/')
.reply(200, '{"couchdb":"Welcome","version":"1.1.0"}', {})
.get('/acb') .get('/acb')
.reply(404, "{\"error\":\"not_found\",\"reason\":\"no_db_file\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', .reply(404, "{\"error\":\"not_found\",\"reason\":\"no_db_file\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
date: 'Fri, 02 Dec 2011 02:53:14 GMT', date: 'Fri, 02 Dec 2011 02:53:14 GMT',
Expand All @@ -32,6 +34,12 @@ var ensure = require('ensure')
'content-length': '44', 'content-length': '44',
'cache-control': 'must-revalidate' }); 'cache-control': 'must-revalidate' });


tests.root = function (callback) { nano(cfg.url).dinosaur('', callback); };
tests.root_ok = function (e,b) {
this.t.ok(b.version);
this.t.equal(b.version, "1.1.0");
};

tests.url = function (callback) { callback(null,nano('http://someurl.com')); }; tests.url = function (callback) { callback(null,nano('http://someurl.com')); };
tests.url_ok = function (_,n) { this.t.equal(n.config.url, "http://someurl.com"); }; tests.url_ok = function (_,n) { this.t.equal(n.config.url, "http://someurl.com"); };


Expand Down

0 comments on commit 0000c1e

Please sign in to comment.