Skip to content

Commit a5f4830

Browse files
committed
Rewriting from scratch on a 48h contest
1 parent 3e7ac41 commit a5f4830

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

models/show.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
module.exports.show = function (mongoose) {
2-
// Standard Mongoose stuff here...
3-
var schema = mongoose.Schema;
2+
var schema = mongoose.Schema;
3+
show_schema = new schema({
4+
tvdb_id: {type: Number, unique: true}
5+
, name: {type: String}
6+
});
7+
show_schema.statics.search = function(name, callback) {
8+
return this.where('name', new RegExp(name, 'i')).run(callback);
9+
};
10+
mongoose.model('show', show_schema);
411

5-
mongoose.model('show', new schema({
6-
textValue: String
7-
}));
8-
9-
return mongoose.model('show');
12+
return mongoose.model('show');
1013
};

tests/unit/show.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var testFixture = require('nodeunit').testCase;
2+
var mongoose = require('mongoose');
3+
mongoose.connect('mongodb://localhost/testing');
4+
var shows = require('../../models/show.js').show(mongoose);
5+
require('assert');
6+
7+
8+
exports['Show'] = testFixture({
9+
setUp: function(callback){
10+
tvshow = new shows;
11+
tvshow.tvdb_id = 999;
12+
tvshow.save();
13+
callback();
14+
},
15+
'we have a tv db id': function(test){
16+
test.equals(tvshow.tvdb_id, 999);
17+
test.done();
18+
}
19+
});
20+
exports['Finding a show'] = testFixture({
21+
setUp: function(callback){
22+
show = new shows;
23+
show.name = 'Lost';
24+
show.tvdb_id = 999;
25+
show.save();
26+
callback();
27+
},
28+
'we find the show from the database': function(test){
29+
shows.search('Lost', function(err, docs){
30+
test.ok(docs);
31+
test.done();
32+
});
33+
},
34+
tearDown: function(callback){
35+
shows.remove();
36+
mongoose.disconnect();
37+
callback();
38+
}
39+
});

0 commit comments

Comments
 (0)