Permalink
Browse files

remove filter and make module export a function instead

  • Loading branch information...
1 parent e22db9f commit fdc48bf6c3515e7ff566af0e73dd6d0e9815c261 @caolan committed Jul 30, 2010
Showing with 26 additions and 26 deletions.
  1. +1 −1 README.md
  2. +8 −8 lib/quip.js
  3. +17 −17 test/test-response.js
View
@@ -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');
}
View
@@ -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 /////
@@ -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();
- };
-};
View
@@ -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({
@@ -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.