Skip to content

Commit

Permalink
Fixing hypermedia() by ensuring no link Objects when a collection…
Browse files Browse the repository at this point in the history
… is empty, added a test
  • Loading branch information
avoidwork committed Aug 3, 2014
1 parent ce788db commit ed126f1
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 0.0.10
- Fixing `hypermedia()` by ensuring no `link` Objects when a collection is empty, added a test

## 0.0.9
- Fixing `hypermedia()` URI reconstruction by encoding the query string values, added a test

Expand Down
2 changes: 1 addition & 1 deletion doc/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ <h5>Returns:</h5>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Sun Aug 03 2014 09:18:14 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sun Aug 03 2014 09:31:03 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ <h2>License</h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Sun Aug 03 2014 09:18:14 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sun Aug 03 2014 09:31:03 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
4 changes: 2 additions & 2 deletions doc/module-tenso.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h2>


<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.0.9</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.0.10</li></ul></dd>



Expand Down Expand Up @@ -194,7 +194,7 @@ <h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Sun Aug 03 2014 09:18:14 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sun Aug 03 2014 09:31:03 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/modules.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ <h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Sun Aug 03 2014 09:18:14 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sun Aug 03 2014 09:31:03 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
10 changes: 5 additions & 5 deletions doc/tenso.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ <h1 class="page-title">Source: tenso.js</h1>
* @license BSD-3 &lt;https://raw.github.com/avoidwork/tenso/master/LICENSE>
* @link http://avoidwork.github.io/tenso
* @module tenso
* @version 0.0.9
* @version 0.0.10
*/
( function () {
"use strict";

var TurtleIO = require( "turtle.io" ),
SERVER = "tenso/0.0.9",
SERVER = "tenso/0.0.10",
CONFIG = require( __dirname + "/../config.json" ),
keigai = require( "keigai" ),
util = keigai.util,
Expand All @@ -118,7 +118,7 @@ <h1 class="page-title">Source: tenso.js</h1>
function Tenso () {
this.messages = {};
this.server = new TurtleIO();
this.version = "0.0.9";
this.version = "0.0.10";
}

/**
Expand Down Expand Up @@ -290,7 +290,7 @@ <h1 class="page-title">Source: tenso.js</h1>
rep.data.link.push( {uri: root.replace( "page=0", "page=" + ( page + 1 ) ), rel: "next"} );
}

if ( page !== nth ) {
if ( nth > 0 && page !== nth ) {
rep.data.link.push( {uri: root.replace("page=0", "page=" + nth ), rel: "last"} );
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ <h1 class="page-title">Source: tenso.js</h1>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Sun Aug 03 2014 09:18:14 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sun Aug 03 2014 09:31:03 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
8 changes: 4 additions & 4 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* @license BSD-3 <https://raw.github.com/avoidwork/tenso/master/LICENSE>
* @link http://avoidwork.github.io/tenso
* @module tenso
* @version 0.0.9
* @version 0.0.10
*/
( function () {
"use strict";

var TurtleIO = require( "turtle.io" ),
SERVER = "tenso/0.0.9",
SERVER = "tenso/0.0.10",
CONFIG = require( __dirname + "/../config.json" ),
keigai = require( "keigai" ),
util = keigai.util,
Expand All @@ -29,7 +29,7 @@ var TurtleIO = require( "turtle.io" ),
function Tenso () {
this.messages = {};
this.server = new TurtleIO();
this.version = "0.0.9";
this.version = "0.0.10";
}

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ function hypermedia ( server, req, rep, headers ) {
rep.data.link.push( {uri: root.replace( "page=0", "page=" + ( page + 1 ) ), rel: "next"} );
}

if ( page !== nth ) {
if ( nth > 0 && page !== nth ) {
rep.data.link.push( {uri: root.replace("page=0", "page=" + nth ), rel: "last"} );
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is a REST API facade for node.js, designed to simplify the implementation of APIs.",
"version": "0.0.9",
"version": "0.0.10",
"homepage": "http://avoidwork.github.io/tenso",
"author": {
"name": "Jason Mulligan",
Expand Down
2 changes: 1 addition & 1 deletion src/hypermedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function hypermedia ( server, req, rep, headers ) {
rep.data.link.push( {uri: root.replace( "page=0", "page=" + ( page + 1 ) ), rel: "next"} );
}

if ( page !== nth ) {
if ( nth > 0 && page !== nth ) {
rep.data.link.push( {uri: root.replace("page=0", "page=" + nth ), rel: "last"} );
}
}
Expand Down
1 change: 1 addition & 0 deletions test/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports.get = {
"/": ["/items"],
"/empty": [],
"/items": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
"/something": {"user_id": 123, "title": "This is a title", "body": "Where is my body?", "source_url": "http://source.tld"}
}
16 changes: 16 additions & 0 deletions test/tenso_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ describe("Permissions", function () {
});

describe("Pagination", function () {
describe("GET /empty", function () {
it("returns an empty array", function (done) {
api()
.get("/empty")
.expectStatus(200)
.expectValue("data.link", [])
.expectValue("data.result", [])
.expectValue("error", null)
.expectValue("status", 200)
.end(function(err) {
if (err) throw err;
done();
});
});
});

describe("GET /items", function () {
it("returns page 1/3 of an array of numbers", function (done) {
api()
Expand Down

0 comments on commit ed126f1

Please sign in to comment.