/
define.coffee
60 lines (48 loc) · 1.97 KB
/
define.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
should = require 'should'
try config = require '../conf/test' catch e
ron = require '..'
describe 'define', ->
it 'Define # new schema # string', (next) ->
client = ron config
user = client.define 'user'
user.should.be.instanceof ron.Records
user.should.eql client.get 'user'
client.quit next
it 'Define # new schema # object', (next) ->
client = ron config
user = client.define name: 'user'
user.should.eql client.get 'user'
user.should.be.instanceof ron.Records
client.quit next
it 'Define # identifier', (next) ->
client = ron config
user = client.define name: 'user'
user.should.eql user.identifier('id')
user.identifier().should.eql 'id'
client.quit next
it 'Define # index', (next) ->
client = ron config
user = client.define name: 'user'
user.should.eql user.index('my_index')
['my_index'].should.eql user.index()
client.quit next
it 'Define # unique', (next) ->
client = ron config
user = client.define name: 'user'
user.should.eql user.unique('my_unique')
user.unique().should.eql ['my_unique']
client.quit next
it 'Define # property', (next) ->
client = ron config
user = client.define name: 'user'
# Define properties
user.should.eql user.property('id', identifier: true)
user.should.eql user.property('username', unique: true)
user.should.eql user.property('email', { index: true, email: true })
user.should.eql user.property('name', {})
# Retrieve properties
user.property('id').should.eql { name: 'id', identifier: true, type: 'int' }
user.property('username').should.eql { name: 'username', unique: true }
user.property('email').should.eql { name: 'email', index: true, email: true }
user.property('name').should.eql { name: 'name' }
client.quit next