Skip to content
Browse files

Fixes #16: Node 0.6 support.

I've started improving the unit tests, but tobi doesn't seem to work correctly at the moment so I'll have to work on this later.
  • Loading branch information...
1 parent 35bf91e commit bc9a437601f9aa173cca2b8d179a30dc2950ea3e Alex Young committed Nov 23, 2011
Showing with 51 additions and 61 deletions.
  1. +4 −0 Makefile
  2. +5 −4 app.js
  3. +13 −9 package.json
  4. +27 −27 test/app.test.js
  5. +2 −21 test/helper.js
View
4 Makefile
@@ -0,0 +1,4 @@
+test:
+ ./node_modules/.bin/mocha
+
+.PHONY: test
View
9 app.js
@@ -8,7 +8,7 @@ var express = require('express'),
stylus = require('stylus'),
markdown = require('markdown').markdown,
connectTimeout = require('connect-timeout'),
- sys = require('sys'),
+ util = require('util'),
path = require('path'),
models = require('./models'),
db,
@@ -39,7 +39,7 @@ emails = {
mailOptions[k] = app.set('mailOptions')[k]
}
- console.log('[SENDING MAIL]', sys.inspect(mailOptions));
+ console.log('[SENDING MAIL]', util.inspect(mailOptions));
// Only send mails in production
if (app.settings.env == 'production') {
@@ -162,7 +162,7 @@ function NotFound(msg) {
Error.captureStackTrace(this, arguments.callee);
}
-sys.inherits(NotFound, Error);
+util.inherits(NotFound, Error);
app.get('/404', function(req, res) {
throw new NotFound;
@@ -409,8 +409,9 @@ app.del('/sessions', loadUser, function(req, res) {
// Search
app.post('/search.:format?', loadUser, function(req, res) {
Document.find({ user_id: req.currentUser.id, keywords: req.body.s },
- [], { sort: ['title', 'descending'] },
function(err, documents) {
+ console.log(documents);
+ console.log(err);
switch (req.params.format) {
case 'json':
res.send(documents.map(function(d) {
View
22 package.json
@@ -1,7 +1,7 @@
{
"name": "nodepad",
"description": "A notepad written with Node",
- "version": "0.1.0",
+ "version": "0.1.1",
"homepage": "http://dailyjs.com",
"author": "Alex R. Young (http://alexyoung.org)",
"directories": {
@@ -11,16 +11,20 @@
"node": ">= 0.4.0"
},
"dependencies": {
- "express": "2.4.x",
- "mongoose": "2.0.3",
- "stylus": "0.15.1",
- "jade": "0.15.2",
- "connect": "1.7.1",
- "connect-mongodb": "1.0.0",
- "markdown": "0.2.1",
- "mailer": "0.4.52",
+ "express": "2.5.1",
+ "connect": "1.8.1",
+ "mongoose": "2.3.12",
+ "stylus": "0.18.0",
+ "jade": "0.18.0",
+ "connect-mongodb": "1.1.1",
+ "markdown": "0.3.1",
+ "mailer": "0.6.7",
"connect-timeout": "0.0.1"
},
+ "devDependencies": {
+ "tobi": "0.3.2",
+ "mocha": "0.0.2"
+ },
"bin": {
"nodepad": "bin/nodepad.js"
}
View
54 test/app.test.js
@@ -1,38 +1,38 @@
-/**
- * Run with expresso test/app.test.js
- */
-
-var app = require('../app'),
+var app = require(__dirname + '/../app'),
assert = require('assert'),
- zombie = require('zombie'),
- events = require('events'),
- testHelper = require('./helper');
-
-app.listen(3001);
+ tobi = require('tobi'),
+ testHelper = require('./helper'),
+ browser = tobi.createBrowser(app);
-testHelper.models = [app.User];
+describe('Sign in', function() {
+ before(function(done) {
+ testHelper.clear([app.User], function() {
+ var user = new app.User({'email' : 'alex@example.com', 'password' : 'test' });
+ user.save(done);
+ console.log('done');
+ });
+ });
-testHelper.setup(function() {
- // Fixtures
- var user = new app.User({'email' : 'alex@example.com', 'password' : 'test' });
- user.save(function() {
- testHelper.run(exports)
+ after(function(done) {
+ app.close();
+ done();
});
-});
-testHelper.tests = {
- 'test login': function() {
- zombie.visit('http://localhost:3001/', function(err, browser, status) {
+ it('should allow valid users to sign in', function(done) {
+ // FIXME: tobi doesn't seem to work at the moment
+ browser.get('/sessions/new', function(res, $) {
+ console.log('got / page');
// Fill email, password and submit form
- browser.
- fill('user[email]', 'alex@example.com').
- fill('user[password]', 'test').
- pressButton('Log In', function(err, browser, status) {
+ $('form#login')
+ .fill('user[email]', 'alex@example.com')
+ .fill('user[password]', 'test')
+ .submit(function(res, $) {
+ console.log('form submitted');
// Form submitted, new page loaded.
assert.equal(browser.text('#header a.destroy'), 'Log Out');
testHelper.end();
+ done();
});
});
- }
-};
-
+ });
+});
View
23 test/helper.js
@@ -20,26 +20,7 @@ function prepare(models, next) {
};
module.exports = {
- run: function(e) {
- for (var test in state.tests) {
- e[test] = state.tests[test];
- }
- },
-
- setup: function(next) {
- prepare(state.models, next);
- },
-
- end: function() {
- prepare(state.models, process.exit);
- },
-
- set models(models) {
- state.models = models;
- },
-
- set tests(tests) {
- state.tests = tests;
+ clear: function(models, next) {
+ prepare(models, next);
}
};
-

0 comments on commit bc9a437

Please sign in to comment.
Something went wrong with that request. Please try again.