Fixes #33 by improving specs

This commit is contained in:
Sean Corfield 2019-07-02 18:50:25 -07:00
parent 1fe7e92df2
commit ba4dc837e1
3 changed files with 13 additions and 3 deletions

View file

@ -10,6 +10,7 @@ The following changes have been committed to the **master** branch since the 1.0
* Fix #36 by adding type hint in `with-transaction` macro. * Fix #36 by adding type hint in `with-transaction` macro.
* Fix #35 by explaining the database-specific options needed to ensure `insert-multi!` performs a single, batched operation. * Fix #35 by explaining the database-specific options needed to ensure `insert-multi!` performs a single, batched operation.
* Fix #34 by explaining save points (in the Transactions documentation). * Fix #34 by explaining save points (in the Transactions documentation).
* Fix #33 by updating the spec for the example `key-map` in `find-by-keys`, `update!`, and `delete!` to reflect that you cannot pass an empty map to these functions (and added tests to ensure the calls fail with spec errors).
## Stable Builds ## Stable Builds

View file

@ -43,6 +43,7 @@
(s/def ::connectable any?) (s/def ::connectable any?)
(s/def ::key-map (s/map-of keyword? any?)) (s/def ::key-map (s/map-of keyword? any?))
(s/def ::example-map (s/map-of keyword? any? :min-count 1))
(s/def ::opts-map (s/map-of keyword? any?)) (s/def ::opts-map (s/map-of keyword? any?))
(s/def ::transactable any?) (s/def ::transactable any?)
@ -116,7 +117,7 @@
(s/fdef sql/find-by-keys (s/fdef sql/find-by-keys
:args (s/cat :connectable ::connectable :args (s/cat :connectable ::connectable
:table keyword? :table keyword?
:key-map (s/or :example ::key-map :key-map (s/or :example ::example-map
:where ::sql-params) :where ::sql-params)
:opts (s/? ::opts-map))) :opts (s/? ::opts-map)))
@ -135,14 +136,14 @@
:args (s/cat :connectable ::connectable :args (s/cat :connectable ::connectable
:table keyword? :table keyword?
:key-map ::key-map :key-map ::key-map
:where-params (s/or :example ::key-map :where-params (s/or :example ::example-map
:where ::sql-params) :where ::sql-params)
:opts (s/? ::opts-map))) :opts (s/? ::opts-map)))
(s/fdef sql/delete! (s/fdef sql/delete!
:args (s/cat :connectable ::connectable :args (s/cat :connectable ::connectable
:table keyword? :table keyword?
:where-params (s/or :example ::key-map :where-params (s/or :example ::example-map
:where ::sql-params) :where ::sql-params)
:opts (s/? ::opts-map))) :opts (s/? ::opts-map)))

View file

@ -155,3 +155,11 @@
(is (= {:next.jdbc/update-count 2} (is (= {:next.jdbc/update-count 2}
(sql/delete! (ds) :fruit ["id > ?" 4]))) (sql/delete! (ds) :fruit ["id > ?" 4])))
(is (= 4 (count (sql/query (ds) ["select * from fruit"])))))) (is (= 4 (count (sql/query (ds) ["select * from fruit"]))))))
(deftest no-empty-example-maps
(is (thrown? clojure.lang.ExceptionInfo
(sql/find-by-keys (ds) :fruit {})))
(is (thrown? clojure.lang.ExceptionInfo
(sql/update! (ds) :fruit {} {})))
(is (thrown? clojure.lang.ExceptionInfo
(sql/delete! (ds) :fruit {}))))