From ba4dc837e19e5d5322a4bf91928d6ddef8a9de5a Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Tue, 2 Jul 2019 18:50:25 -0700 Subject: [PATCH] Fixes #33 by improving specs --- CHANGELOG.md | 1 + src/next/jdbc/specs.clj | 7 ++++--- test/next/jdbc/sql_test.clj | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c58c7..8e1ff6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 #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 #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 diff --git a/src/next/jdbc/specs.clj b/src/next/jdbc/specs.clj index 3c56068..a3ddd19 100644 --- a/src/next/jdbc/specs.clj +++ b/src/next/jdbc/specs.clj @@ -43,6 +43,7 @@ (s/def ::connectable 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 ::transactable any?) @@ -116,7 +117,7 @@ (s/fdef sql/find-by-keys :args (s/cat :connectable ::connectable :table keyword? - :key-map (s/or :example ::key-map + :key-map (s/or :example ::example-map :where ::sql-params) :opts (s/? ::opts-map))) @@ -135,14 +136,14 @@ :args (s/cat :connectable ::connectable :table keyword? :key-map ::key-map - :where-params (s/or :example ::key-map + :where-params (s/or :example ::example-map :where ::sql-params) :opts (s/? ::opts-map))) (s/fdef sql/delete! :args (s/cat :connectable ::connectable :table keyword? - :where-params (s/or :example ::key-map + :where-params (s/or :example ::example-map :where ::sql-params) :opts (s/? ::opts-map))) diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index d211436..31d8f99 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -155,3 +155,11 @@ (is (= {:next.jdbc/update-count 2} (sql/delete! (ds) :fruit ["id > ?" 4]))) (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 {}))))