Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 82 lines (65 sloc) 2.354 kB
5911ed3 @1602 Added performance test
authored
1 Schema = require('../index').Schema
2 Text = Schema.Text
3
4 require('./spec_helper').init exports
5
6 schemas =
7 neo4j:
8 url: 'http://localhost:7474/'
9 mongoose:
10 url: 'mongodb://localhost/test'
11 redis: {}
12 memory: {}
d333fe1 @athieriot First version of a cradle adapter
athieriot authored
13 cradle: {}
5911ed3 @1602 Added performance test
authored
14
15 testOrm = (schema) ->
16
17 User = Post = 'unknown'
c5da2b5 @1602 Redis indexes intersections
authored
18 maxUsers = 100
19 maxPosts = 50000
5911ed3 @1602 Added performance test
authored
20 users = []
21
22 it 'should define simple', (test) ->
23
24 User = schema.define 'User', {
25 name: String,
26 bio: Text,
27 approved: Boolean,
28 joinedAt: Date,
29 age: Number
30 }
31
c5da2b5 @1602 Redis indexes intersections
authored
32 Post = schema.define 'Post',
33 title: { type: String, length: 255, index: true }
5911ed3 @1602 Added performance test
authored
34 content: { type: Text }
35 date: { type: Date, detault: Date.now }
36 published: { type: Boolean, default: false }
37
38 User.hasMany(Post, {as: 'posts', foreignKey: 'userId'})
39 Post.belongsTo(User, {as: 'author', foreignKey: 'userId'})
40
41 test.done()
42
43 it 'should create users', (test) ->
44 wait = maxUsers
45 done = (e, u) ->
46 users.push(u)
47 test.done() if --wait == 0
48 User.create(done) for i in [1..maxUsers]
49
50 it 'should create bunch of data', (test) ->
51 wait = maxPosts
52 done = -> test.done() if --wait == 0
53 rnd = (title) ->
54 {
c5da2b5 @1602 Redis indexes intersections
authored
55 userId: users[Math.floor(Math.random() * maxUsers)].id
56 title: 'Post number ' + (title % 5)
5911ed3 @1602 Added performance test
authored
57 }
58 Post.create(rnd(num), done) for num in [1..maxPosts]
59
60 it 'do some queries using foreign keys', (test) ->
61 wait = 4
62 done = -> test.done() if --wait == 0
63 ts = Date.now()
64 query = (num) ->
c5da2b5 @1602 Redis indexes intersections
authored
65 users[num].posts { title: 'Post number 3' }, (err, collection) ->
5911ed3 @1602 Added performance test
authored
66 console.log('User ' + num + ':', collection.length, 'posts in', Date.now() - ts,'ms')
67 done()
c5da2b5 @1602 Redis indexes intersections
authored
68 query num for num in [0..4]
69
70 return
5911ed3 @1602 Added performance test
authored
71
72 it 'should destroy all data', (test) ->
73 Post.destroyAll ->
74 User.destroyAll(test.done)
75
76 Object.keys(schemas).forEach (schemaName) ->
77 return if process.env.ONLY && process.env.ONLY != schemaName
78 context schemaName, ->
79 schema = new Schema schemaName, schemas[schemaName]
80 testOrm(schema)
81
Something went wrong with that request. Please try again.