Use random-uuid here

This commit is contained in:
Michael S. Klishin 2011-08-15 01:38:11 +04:00
parent f096c032cd
commit 1bba60418e
2 changed files with 9 additions and 4 deletions

View file

@ -8,12 +8,17 @@
;; You must not remove this notice, or any other, from this software.
(ns monger.util
(:import (java.security SecureRandom) (java.math.BigInteger)))
(:import (java.security SecureRandom) (java.math BigInteger)))
;;
;; API
;;
(defn ^String random-uuid
"Generates a secure random UUID string"
[]
(.toString (java.util.UUID/randomUUID)))
(defn ^String random-str
"Generates a secure random string"
[^long n, ^long num-base]

View file

@ -103,14 +103,14 @@
(deftest find-full-document-by-id-when-document-does-not-exist
(let [collection "libraries"
doc-id (monger.util/random-str 140 16)]
doc-id (monger.util/random-uuid)]
(monger.collection/remove collection)
(is (nil? (monger.collection/find-by-id collection doc-id)))))
(deftest find-full-document-by-id-when-document-exists
(let [collection "libraries"
doc-id (monger.util/random-str 140 16)
doc-id (monger.util/random-uuid)
doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }]
(monger.collection/remove collection)
(monger.collection/insert collection doc)
@ -118,7 +118,7 @@
(deftest find-partial-document-by-id-when-document-exists
(let [collection "libraries"
doc-id (monger.util/random-str 140 16)
doc-id (monger.util/random-uuid)
doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }]
(monger.collection/remove collection)
(monger.collection/insert collection doc)