File tree 2 files changed +49
-7
lines changed
2 files changed +49
-7
lines changed Original file line number Diff line number Diff line change 1
1
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 ) ;
4
11
5
- mongoose . model ( 'show' , new schema ( {
6
- textValue : String
7
- } ) ) ;
8
-
9
- return mongoose . model ( 'show' ) ;
12
+ return mongoose . model ( 'show' ) ;
10
13
} ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments