Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic to allow developers to utilize full request API. #299

Merged
merged 2 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ Cradle's API builds right on top of Node's asynch API. Every asynch method takes
new(cradle.Connection)('http://living-room.couch', 5984, {
cache: true,
raw: false,
forceSave: true
forceSave: true,
request: {
//Pass through configuration to `request` library for all requests on this connection.
}
});
```

Expand Down
3 changes: 2 additions & 1 deletion lib/cradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ cradle.Connection.prototype.rawRequest = function (options, callback) {
options.agent = this.agent;
options.uri = this._url(options.path);
delete options.path;

options = cradle.merge(this.options.request, options);

return request(options, callback || function () { });
};

Expand Down
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
"version": "0.7.0",
"description": "the high-level, caching, CouchDB library",
"url": "http://cloudhead.io/cradle",
"keywords": ["couchdb", "database", "couch"],
"keywords": [
"couchdb",
"database",
"couch"
],
"author": "Alexis Sellier <self@cloudhead.net>",
"contributors": [
{ "name": "Charlie Robbins", "email": "charlie@nodejitsu.com" },
{ "name": "Maciej Malecki", "email": "maciej@nodejitsu.com" }
{
"name": "Charlie Robbins",
"email": "charlie@nodejitsu.com"
},
{
"name": "Maciej Malecki",
"email": "maciej@nodejitsu.com"
}
],
"main": "./lib/cradle",
"dependencies": {
Expand All @@ -17,6 +27,8 @@
},
"devDependencies": {
"async": "~0.9.0",
"proxyquire": "^1.7.3",
"sinon": "^1.17.2",
"vows": "0.8.x"
},
"scripts": {
Expand Down
28 changes: 28 additions & 0 deletions test/raw-request-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var path = require('path'),
assert = require('assert'),
events = require('events'),
vows = require('vows'),
sinon = require('sinon'),
proxyquire = require('proxyquire');

var reqSpy = sinon.spy();
var cradle = proxyquire('../lib/cradle', {
request: reqSpy
});

vows.describe('cradle/raw-request').addBatch({
'Options specified in "request" are passed directly to request library': {
topic: new(cradle.Connection)({ request: { someOption: 'filler' }}),
'should pass through values to "request"': function(topic) {
var args;
var opts = {
moreOptions: 'moreFiller',
path: 'path'
};
topic.rawRequest(opts);
args = reqSpy.getCall(0).args[0];
assert(args.moreOptions, 'moreFiller');
assert(args.someOption, 'filler');
}
}
}).export(module);