Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first real Midje test - with beginning of refactoring the SQL c…
…ode\!
- Loading branch information
1 parent
0c3840c
commit dfc494f
Showing
3 changed files
with
22 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
(ns defdrink.models.drinks | ||
(:require [clojure.java.jdbc :as sql])) | ||
(:require [clojure.java.jdbc :as sql2]) | ||
(:require [defdrink.utils.sql :as sql])) | ||
|
||
(defn all [] | ||
(sql/with-connection (System/getenv "DATABASE_URL") | ||
(sql/with-query-results results | ||
["select * from drinks order by name asc"] | ||
(into [] results)))) | ||
(sql/select :drinks)) | ||
|
||
(defn insert [name] | ||
(sql/with-connection (System/getenv "DATABASE_URL") | ||
(sql/insert-record :drinks {:name name}))) | ||
(sql2/with-connection (System/getenv "DATABASE_URL") | ||
(sql2/insert-record :drinks {:name name}))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns defdrink.utils.sql | ||
(:require [clojure.java.jdbc :as sql])) | ||
|
||
(defn- run-query [query] | ||
(sql/with-query-results results [query] (into [] results))) | ||
|
||
(defn select [table] | ||
(sql/with-connection | ||
(System/getenv "DATABASE_URL") | ||
(run-query (format "select * from %s" table)))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
(ns defdrink.test.models.drinks | ||
(:use clojure.test) | ||
(:use midje.sweet)) | ||
(:use midje.sweet) | ||
(:use defdrink.models.drinks) | ||
(:require [defdrink.utils.sql :as sql])) | ||
|
||
(fact (+ 1 1) => even?) | ||
(fact (all) => [...drink1... ...drink2...] | ||
(provided (sql/select :drinks) => [...drink1... ...drink2...])) |