Skip to content

Commit

Permalink
Merge pull request #367 from colinwren/master
Browse files Browse the repository at this point in the history
Add tests for automatic view routing and rendering, and updated package.json
  • Loading branch information
Dennis Bartlett committed May 5, 2013
2 parents de77ff0 + 8a09b5f commit 5855de3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 2 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
{
"name": "Ameen Ahmed",
"email": "ameen.ahmed.b@gmail.com"
},
{
"name": "Colin Wren",
"email": "colin@cawren.com"
}
],
"version": "0.8.91",
Expand Down Expand Up @@ -108,7 +112,6 @@
"devDependencies": {
"mocha": "*",
"chai": "*",
"coffee-script": "*",
"request": "*"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions test/http/fixtures/api/controllers/ViewTestController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
1 change: 1 addition & 0 deletions test/http/fixtures/views/viewTest/create.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
createView
1 change: 1 addition & 0 deletions test/http/fixtures/views/viewTest/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indexView
5 changes: 4 additions & 1 deletion test/http/helpers/appHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var fs = require('fs');
var fs = require('fs-extra');
var wrench = require('wrench');
var exec = require('child_process').exec;
var path = require('path');
Expand Down Expand Up @@ -44,6 +44,9 @@ module.exports.build = function(/* [appName], done */) {

// Copy File to Test App
var data = fs.readFileSync(filePath);

// Create file and any missing parent directories in its path
fs.createFileSync(path.resolve('./', appName, file), data);
fs.writeFileSync(path.resolve('./', appName, file), data);
});

Expand Down
60 changes: 60 additions & 0 deletions test/http/router.viewRendering.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var assert = require('assert');
var httpHelper = require('./helpers/httpHelper.js');
var appHelper = require('./helpers/appHelper');

describe('View routes', function() {
var appName = 'testApp';

before(function(done) {
appHelper.build(function(err) {
if (err) return done(err);

process.chdir(appName);
done();
});
});

after(function() {
process.chdir('../');
appHelper.teardown();
});

describe('with default routing', function() {

it('should respond to a get request to localhost:1337 with welcome page', function(done) {

httpHelper.testRoute('get', '', function(err, response) {
if (err) done(new Error(err));

assert(response.body.indexOf('It works!') !== -1);
done();
});
});
});

describe('with no specified routing', function() {

it('should respond to get request to :controller with the template at views/:controller/index.ejs', function(done) {

// Empty router file
httpHelper.writeRoutes({});

httpHelper.testRoute('get', 'viewTest', function(err, response) {
if (err) done(new Error(err));

assert(response.body.indexOf('indexView') !== -1);
done();
});
});

it('should respond to get request to :controller/:action with the template at views/:controller/:action.ejs', function(done) {

httpHelper.testRoute('get', 'viewTest/create', function(err, response) {
if (err) done(new Error(err));

assert(response.body.indexOf('createView') !== -1);
done();
});
});
});
});

0 comments on commit 5855de3

Please sign in to comment.