Skip to content

Commit bc9a437

Browse files
author
Alex Young
committed
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.
1 parent 35bf91e commit bc9a437

File tree

5 files changed

+51
-61
lines changed

5 files changed

+51
-61
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test:
2+
./node_modules/.bin/mocha
3+
4+
.PHONY: test

app.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var express = require('express'),
88
stylus = require('stylus'),
99
markdown = require('markdown').markdown,
1010
connectTimeout = require('connect-timeout'),
11-
sys = require('sys'),
11+
util = require('util'),
1212
path = require('path'),
1313
models = require('./models'),
1414
db,
@@ -39,7 +39,7 @@ emails = {
3939
mailOptions[k] = app.set('mailOptions')[k]
4040
}
4141

42-
console.log('[SENDING MAIL]', sys.inspect(mailOptions));
42+
console.log('[SENDING MAIL]', util.inspect(mailOptions));
4343

4444
// Only send mails in production
4545
if (app.settings.env == 'production') {
@@ -162,7 +162,7 @@ function NotFound(msg) {
162162
Error.captureStackTrace(this, arguments.callee);
163163
}
164164

165-
sys.inherits(NotFound, Error);
165+
util.inherits(NotFound, Error);
166166

167167
app.get('/404', function(req, res) {
168168
throw new NotFound;
@@ -409,8 +409,9 @@ app.del('/sessions', loadUser, function(req, res) {
409409
// Search
410410
app.post('/search.:format?', loadUser, function(req, res) {
411411
Document.find({ user_id: req.currentUser.id, keywords: req.body.s },
412-
[], { sort: ['title', 'descending'] },
413412
function(err, documents) {
413+
console.log(documents);
414+
console.log(err);
414415
switch (req.params.format) {
415416
case 'json':
416417
res.send(documents.map(function(d) {

package.json

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nodepad",
33
"description": "A notepad written with Node",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"homepage": "http://dailyjs.com",
66
"author": "Alex R. Young (http://alexyoung.org)",
77
"directories": {
@@ -11,16 +11,20 @@
1111
"node": ">= 0.4.0"
1212
},
1313
"dependencies": {
14-
"express": "2.4.x",
15-
"mongoose": "2.0.3",
16-
"stylus": "0.15.1",
17-
"jade": "0.15.2",
18-
"connect": "1.7.1",
19-
"connect-mongodb": "1.0.0",
20-
"markdown": "0.2.1",
21-
"mailer": "0.4.52",
14+
"express": "2.5.1",
15+
"connect": "1.8.1",
16+
"mongoose": "2.3.12",
17+
"stylus": "0.18.0",
18+
"jade": "0.18.0",
19+
"connect-mongodb": "1.1.1",
20+
"markdown": "0.3.1",
21+
"mailer": "0.6.7",
2222
"connect-timeout": "0.0.1"
2323
},
24+
"devDependencies": {
25+
"tobi": "0.3.2",
26+
"mocha": "0.0.2"
27+
},
2428
"bin": {
2529
"nodepad": "bin/nodepad.js"
2630
}

test/app.test.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
/**
2-
* Run with expresso test/app.test.js
3-
*/
4-
5-
var app = require('../app'),
1+
var app = require(__dirname + '/../app'),
62
assert = require('assert'),
7-
zombie = require('zombie'),
8-
events = require('events'),
9-
testHelper = require('./helper');
10-
11-
app.listen(3001);
3+
tobi = require('tobi'),
4+
testHelper = require('./helper'),
5+
browser = tobi.createBrowser(app);
126

13-
testHelper.models = [app.User];
7+
describe('Sign in', function() {
8+
before(function(done) {
9+
testHelper.clear([app.User], function() {
10+
var user = new app.User({'email' : '[email protected]', 'password' : 'test' });
11+
user.save(done);
12+
console.log('done');
13+
});
14+
});
1415

15-
testHelper.setup(function() {
16-
// Fixtures
17-
var user = new app.User({'email' : '[email protected]', 'password' : 'test' });
18-
user.save(function() {
19-
testHelper.run(exports)
16+
after(function(done) {
17+
app.close();
18+
done();
2019
});
21-
});
2220

23-
testHelper.tests = {
24-
'test login': function() {
25-
zombie.visit('http://localhost:3001/', function(err, browser, status) {
21+
it('should allow valid users to sign in', function(done) {
22+
// FIXME: tobi doesn't seem to work at the moment
23+
browser.get('/sessions/new', function(res, $) {
24+
console.log('got / page');
2625
// Fill email, password and submit form
27-
browser.
28-
fill('user[email]', '[email protected]').
29-
fill('user[password]', 'test').
30-
pressButton('Log In', function(err, browser, status) {
26+
$('form#login')
27+
.fill('user[email]', '[email protected]')
28+
.fill('user[password]', 'test')
29+
.submit(function(res, $) {
30+
console.log('form submitted');
3131
// Form submitted, new page loaded.
3232
assert.equal(browser.text('#header a.destroy'), 'Log Out');
3333
testHelper.end();
34+
done();
3435
});
3536
});
36-
}
37-
};
38-
37+
});
38+
});

test/helper.js

+2-21
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,7 @@ function prepare(models, next) {
2020
};
2121

2222
module.exports = {
23-
run: function(e) {
24-
for (var test in state.tests) {
25-
e[test] = state.tests[test];
26-
}
27-
},
28-
29-
setup: function(next) {
30-
prepare(state.models, next);
31-
},
32-
33-
end: function() {
34-
prepare(state.models, process.exit);
35-
},
36-
37-
set models(models) {
38-
state.models = models;
39-
},
40-
41-
set tests(tests) {
42-
state.tests = tests;
23+
clear: function(models, next) {
24+
prepare(models, next);
4325
}
4426
};
45-

0 commit comments

Comments
 (0)