/
table_spec.coffee
39 lines (32 loc) · 1.31 KB
/
table_spec.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
{ Monarch, async, pg } = require "../spec_helper"
describe "Relations.Table", ->
class Blog extends Monarch.Record
@extended(this)
@columns
public: 'boolean'
title: 'string'
authorId: 'integer'
blogs = Blog.table
beforeEach (done) ->
Monarch.Db.Connection.query("TRUNCATE TABLE blogs;", done)
describe "#create", ->
describe "when a single attribute hash is passed", ->
it "inserts a record with the given attributes", (done) ->
blogs.create { public: true, title: "New Blog 1", authorId: 11 }, ->
blogs.find { title: "New Blog 1" }, (err, record) ->
expect(record.public()).toBeTruthy()
expect(record.authorId()).toBe(11)
done()
describe "when an array of attribute hashes is passed", ->
it "inserts a record with each set of attributes", (done) ->
hashes = [
{ id: 1, public: true, title: "New Blog 1", authorId: 11 }
{ id: 2, public: true, title: "New Blog 2", authorId: 12 }
]
blogs.create hashes, ->
blogs.all (err, records) ->
expect(records).toEqualRecords(Blog, [
{ id: 1, public: true, title: "New Blog 1", authorId: 11 }
{ id: 2, public: true, title: "New Blog 2", authorId: 12 }
])
done()