|
1 | 1 | (ns toucan.db-test
|
2 | 2 | (:require [clojure.java.jdbc :as jdbc]
|
| 3 | + [clojure.string :as str] |
3 | 4 | [expectations :refer :all]
|
4 | 5 | [honeysql.core :as hsql]
|
5 | 6 | [toucan
|
6 | 7 | [db :as db]
|
7 |
| - [test-setup :as test]] |
| 8 | + [test-setup :as test] |
| 9 | + [util :as u]] |
8 | 10 | [toucan.test-models
|
9 | 11 | [address :refer [Address]]
|
10 | 12 | [category :refer [Category]]
|
|
57 | 59 | (binding [db/*automatically-convert-dashes-and-underscores* true]
|
58 | 60 | (db/select-one-field :street-name Address)))
|
59 | 61 |
|
| 62 | +;; Ensure that (:identifiers @default-jdbc-options) defaults to `u/lower-case` |
| 63 | +(defn- mangle-a-chars |
| 64 | + [s] |
| 65 | + (-> s u/lower-case (str/replace "a" "â"))) |
| 66 | + |
| 67 | +(expect |
| 68 | + [mangle-a-chars #{:first-nâme :lâst-nâme :id}] ; Note the circumflexes over a's |
| 69 | + (let [original-options @@(var db/default-jdbc-options)] |
| 70 | + (try |
| 71 | + (db/set-default-jdbc-options! {:identifiers mangle-a-chars}) |
| 72 | + [(:identifiers @@(var db/default-jdbc-options)) |
| 73 | + (-> (db/select-one 'User) keys set)] |
| 74 | + (finally |
| 75 | + (db/set-default-jdbc-options! original-options))))) |
| 76 | + |
| 77 | +(expect |
| 78 | + [u/lower-case #{:first-name :last-name :id}] ; Note the absence of circumflexes over a's |
| 79 | + (let [original-options @@(var db/default-jdbc-options)] |
| 80 | + (try |
| 81 | + (db/set-default-jdbc-options! {:identifiers mangle-a-chars}) |
| 82 | + ;; Setting default options without `:identifiers` should default to u/lower-case. If it doesn't, we can expect |
| 83 | + ;; either the current value `mangle-a-chars` (:identifiers wasn't updated), or nil (overwritten). |
| 84 | + (db/set-default-jdbc-options! {}) |
| 85 | + [(:identifiers @@(var db/default-jdbc-options)) |
| 86 | + (-> (db/select-one 'User) keys set)] |
| 87 | + (finally |
| 88 | + (db/set-default-jdbc-options! original-options))))) |
| 89 | + |
60 | 90 | ;; Test replace-underscores
|
61 | 91 | (expect
|
62 | 92 | :2-cans
|
|
0 commit comments