Skip to content

Commit

Permalink
remove filter and make module export a function instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolan McMahon committed Jul 30, 2010
1 parent e22db9f commit fdc48bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -48,7 +48,7 @@ As a [Connect](http://github.com/extjs/Connect) filter:
quip = require('quip'),

Connect.createServer(
quip.filter(),
quip(),
function(req, res, next){
res.ok('test');
}
Expand Down
16 changes: 8 additions & 8 deletions lib/quip.js
@@ -1,3 +1,11 @@
// filter for use with Connect
var exports = module.exports = function(){
return function(req, res, next){
exports.update(res);
next();
};
};

exports.update = function(res){

///// default response settings /////
Expand Down Expand Up @@ -104,11 +112,3 @@ exports.update = function(res){
return res;

};

// filter for use with Connect
exports.filter = function(){
return function(req, res, next){
exports.update(res);
next();
};
};
34 changes: 17 additions & 17 deletions test/test-response.js
Expand Up @@ -126,6 +126,22 @@ exports.rss = mimeTypeTest('application/rss+xml', 'rss');
exports.javascript = mimeTypeTest('text/javascript', 'javascript');
exports.json = mimeTypeTest('application/json', 'json');

exports.jsonp = function(test){
test.expect(7);
var res = quip.update({});
res.send = function(data){
test.equals(data, 'mycallback({"some":"data"});');
test.equals(res._status, 200);
test.same(res._headers, {'Content-Type':'text/javascript'});
};
var r = res.jsonp('mycallback', {'some':'data'});
test.equals(r, null); //should not allow further chaining

// status code should be overridden
res.error().jsonp('mycallback', {'some':'data'});
test.done();
};

exports.send = function(test){
test.expect(4);
var res = quip.update({
Expand Down Expand Up @@ -208,26 +224,10 @@ exports.filter = function(test){
quip.update = function(r){
test.equals(r, res);
};
quip.filter()(null, res, function(){
quip()(null, res, function(){
test.ok(true, 'next called');
});

quip.update = _update;
test.done();
};

exports.jsonp = function(test){
test.expect(7);
var res = quip.update({});
res.send = function(data){
test.equals(data, 'mycallback({"some":"data"});');
test.equals(res._status, 200);
test.same(res._headers, {'Content-Type':'text/javascript'});
};
var r = res.jsonp('mycallback', {'some':'data'});
test.equals(r, null); //should not allow further chaining

// status code should be overridden
res.error().jsonp('mycallback', {'some':'data'});
test.done();
};

0 comments on commit fdc48bf

Please sign in to comment.