Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed test_server.js and removed kids() and namedKids() functionality…

… from UriUtil.
  • Loading branch information...
commit d9e329929d61d89dc13572ffedc89ff0222d170b 1 parent 79556a5
Gregg Caines authored
6 lib/ContextHelpers/Body.js
View
@@ -5,10 +5,10 @@
The onBody function takes a callback in the form
function(err, body){ ...
where error is an error that may have occurred and body
- is the entire body of the request.
+ is the entire body of the request.
- onBody is useful when you don't care about streaming the
- body and would rather just wait to get the whole thing to
+ onBody is useful when you don't care about streaming the
+ body and would rather just wait to get the whole thing to
do any processiong.
*/
30 lib/UriUtil.js
View
@@ -15,6 +15,10 @@ UriUtil.prototype.absolute = function(path){
if (path[0] == '/'){
path = path.substring(1);
}
+ var parsed = nodeUrl.parse(path);
+ if (!!parsed.protocol){ // if it's already absolute, just return it
+ return path;
+ }
return this._protocol + "://" + this._host + '/' + path;
};
@@ -64,14 +68,10 @@ UriUtil.prototype.pathJoin = function(){
};
UriUtil.prototype.links = function(){
- var kids = this.namedKids();
var links = {};
- _.each(kids, function(v, k){
- links[k] = { href : v};
- });
- links.self = {href : this.absolute(this._self)};
+ links.self = {href : this.self()};
try {
- links.parent = {href : this.absolute(this.parent())};
+ links.parent = {href : this.parent()};
} catch (ex){
if (ex.name != 'NoParentUrl'){
throw ex;
@@ -82,21 +82,7 @@ UriUtil.prototype.links = function(){
UriUtil.prototype.parent = function(inUrl){
var url = inUrl || this._self;
- return this._router.getParentUrl(url);
-};
-
-UriUtil.prototype.namedKids = function(inUrl){
- var url = inUrl || this._self;
- var kids = this._router.getNamedChildUrls(url);
- var that = this;
- _.each(kids, function(v, k){
- kids[k] = that.absolute(v);
- });
- return kids;
-};
-UriUtil.prototype.kids = function(inUrl){
- var url = inUrl || this._self;
- return this._router.getChildUrls(url);
+ return this.absolute(this._router.getParentUrl(url));
};
UriUtil.prototype.parse = function(inUrl){
@@ -143,8 +129,6 @@ UriUtil.prototype.help = function(){
retval = _.extend(retval, {links : this.links()});
retval = _.extend(retval, {parse : this.parse()});
retval = _.extend(retval, {query : this.query()});
- retval = _.extend(retval, {kids : this.kids()});
- retval = _.extend(retval, {namedKids : this.namedKids()});
return retval;
};
2  package.json
View
@@ -19,7 +19,7 @@
"dependencies": {
"underscore" : "1.3.3",
"reaper" : "0.2.3",
- "oneone" : "0.3.0"
+ "oneone" : "0.3.1"
},
"devDependencies" : {
"mockery" : "1.1.2",
0  resources/_index.js → resources/index.js
View
File renamed without changes
71 test/UriUtil.js
View
@@ -69,14 +69,9 @@ describe('UriUtil', function(){
});
});
describe('#links', function(){
- it ("returns parent, self, and child links", function(){
- var calledNamedChildUrls = false;
+ it ("returns parent and self links", function(){
var calledParentUrls = false;
var router = {
- getNamedChildUrls : function(url){
- calledNamedChildUrls = true;
- return {"somechild" : "child" + url};
- },
getParentUrl : function(url){
calledParentUrls = true;
return "parent" + url;
@@ -84,77 +79,23 @@ describe('UriUtil', function(){
};
var u = new UriUtil(router, '[path]');
u.links().should.eql({self : {href : 'http://localhost/[path]'},
- parent : {href :'http://localhost/parent[path]'},
- somechild : {href : 'http://localhost/child[path]'}
+ parent : {href :'http://localhost/parent[path]'}
});
- calledNamedChildUrls.should.equal(true);
calledParentUrls.should.equal(true);
});
- it ("returns self, and child links if parent doesn't exist", function(){
- var calledNamedChildUrls = false;
+ it ("returns self if parent doesn't exist", function(){
var calledParentUrls = false;
var router = {
- getNamedChildUrls : function(url){
- calledNamedChildUrls = true;
- return {"somechild" : "child" + url};
- },
getParentUrl : function(url){
calledParentUrls = true;
throw {name : 'NoParentUrl'};
}
};
var u = new UriUtil(router, '[path]');
- u.links().should.eql({self : {href : 'http://localhost/[path]'},
- somechild : {href : 'http://localhost/child[path]'}});
- calledNamedChildUrls.should.equal(true);
+ u.links().should.eql({self : {href : 'http://localhost/[path]'}});
calledParentUrls.should.equal(true);
});
});
- describe('#kids', function(){
- it ("calls the router's getChildUrls with the current url", function(){
- var called = false;
- var router = { getChildUrls : function(url){
- called = true;
- return url;
- } };
- var u = new UriUtil(router, '[path]');
- u.kids().should.equal('[path]');
- called.should.equal(true);
- });
- it ("calls the router's getChildUrls with the input url", function(){
- var called = false;
- var router = { getChildUrls : function(url){
- called = true;
- return url;
- } };
- var u = new UriUtil(router, '[path]');
- u.kids('input').should.equal('input');
- called.should.equal(true);
- });
- });
- describe('#namedKids', function(){
- it ("calls the router's getNamedChildUrls with the current url", function(){
- var called = false;
- var router = { getNamedChildUrls : function(url){
- called = true;
- return {somename : url};
- } };
- var u = new UriUtil(router, '[path]', 'https', 'somesite.com');
- u.namedKids().somename.should.equal('https://somesite.com/[path]');
- called.should.equal(true);
- });
-
- it ("calls the router's getNamedChildUrls with the input url", function(){
- var called = false;
- var router = { getNamedChildUrls : function(url){
- called = true;
- return {someurl : url};
- } };
- var u = new UriUtil(router, '[path]', 'https', 'somesite.com');
- u.namedKids('input').someurl.should.equal('https://somesite.com/input');
- called.should.equal(true);
- });
- });
describe('#get', function(){
it ("returns the current url if there are no parameters", function(){
var router = {};
@@ -234,7 +175,7 @@ describe('UriUtil', function(){
return "[parent of " + str + "]";
} };
var u = new UriUtil(router, '[path]');
- u.parent().should.equal("[parent of [path]]");
+ u.parent().should.equal("http://localhost/[parent of [path]]");
called.should.equal(true);
});
it ("calls the router's getParentUrl() with a passed url", function(){
@@ -244,7 +185,7 @@ describe('UriUtil', function(){
return "[parent of " + str + "]";
} };
var u = new UriUtil(router, '[path]');
- u.parent('[other path]').should.equal("[parent of [other path]]");
+ u.parent('[other path]').should.equal("http://localhost/[parent of [other path]]");
called.should.equal(true);
});
});
2  test/test_fixtures/resources/artist.js
View
@@ -10,7 +10,7 @@ exports.handler = {
GET : function($){
var out = { artist : [] };
_.each(artists, function(v, k){
- var self = $.uri.get('artist*', {'artist' : k});
+ var self = $.uri.absolute('/api/artist/' + k);
var item = _.extend({ _links : { self : {href : self } }}, v);
out.artist.push(item);
});
7 test/test_fixtures/resources/index.js
View
@@ -4,7 +4,12 @@ exports.handler = {
GET : function($){
$.repr({
- _links: $.uri.links()
+ _links: {
+ artists : $.uri.absolute('/api/artist'),
+ happy : $.uri.absolute('/api/happy'),
+ many : $.uri.absolute('/api/many'),
+ qstring : $.uri.absolute('/api/qstring')
+ }
});
}
2  test/test_fixtures/resources/many.js
View
@@ -1,6 +1,6 @@
exports.handler = {
GET : function($){
- $.repr({"items" : [{"hello" : "collectors", "links" : '/many/1234'}]});
+ $.repr({"items" : [{"hello" : "collectors", "links" : $.uri.absolute('/api/many/1234')}]});
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.