forked from 8thlight/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql_spec.clj
61 lines (48 loc) · 1.75 KB
/
mysql_spec.clj
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
61
(ns hyperion.mysql-spec
(:use [speclj.core]
[hyperion.sql.spec-helper]
[hyperion.dev.spec :only [it-behaves-like-a-datastore]]
[hyperion.api :only [*ds* new-datastore]]
[hyperion.sql.jdbc :only [execute-mutation]]
[hyperion.sql.query]
[hyperion.mysql :only [new-mysql-datastore]]))
(def create-table-query
"CREATE TABLE %s (
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(35),
first_name VARCHAR(35),
inti INTEGER,
data VARCHAR(32),
PRIMARY KEY (id)
)")
(defn create-table [table-name]
(execute-mutation
(make-query (format create-table-query table-name))))
(def drop-table-query "DROP TABLE IF EXISTS %s")
(defn drop-table [table-name]
(execute-mutation
(make-query (format drop-table-query table-name))))
(describe "MySQL Datastore"
(context "creation"
(it "with a kv pairs as params"
(let [ds (new-mysql-datastore :connection-url "jdbc:mysql://localhost:3306/hyperion?user=root" :database "hyperion")]
(should= "hyperion" (.database (.db ds)))))
(it "with factory fn"
(let [ds (new-datastore :implementation :mysql :connection-url "jdbc:mysql://localhost:3306/hyperion?user=root" :database "hyperion")]
(should= "hyperion" (.database (.db ds)))))
)
(context "live"
(with-connection-and-rollback "jdbc:mysql://localhost:3306/hyperion?user=root")
(around [it]
(try
(create-table "testing")
(create-table "other_testing")
(binding [*ds* (new-mysql-datastore :connection-url "jdbc:mysql://localhost:3306/hyperion?user=root" :database "hyperion")]
(it))
(finally
(drop-table "testing")
(drop-table "other_testing")
)))
(it-behaves-like-a-datastore)
)
)