Last active
August 29, 2015 13:57
-
-
Save grinnbearit/9906045 to your computer and use it in GitHub Desktop.
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
(ns constraint-test | |
(:use [midje.sweet]) | |
(:require [datomic.api :as d])) | |
(def db-uri "datomic:mem://bug-test") | |
(def conn nil) | |
(defn setup | |
[uri] | |
(d/create-database uri) | |
(let [conn (d/connect uri)] | |
(d/transact conn [{:db/id #db/id[:db.part/db] | |
:db/ident :gentile/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
{:db/id #db/id[:db.part/db] | |
:db/ident :drink/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
{:db/id #db/id[:db.part/db] | |
:db/ident :drink/drinker | |
:db/valueType :db.type/ref | |
:db/unique :db.unique/value | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db}]) | |
conn)) | |
(background (before :facts (alter-var-root #'conn (constantly (setup db-uri)))) | |
(after :facts (d/delete-database db-uri))) | |
(facts | |
@(d/transact conn [{:db/id (d/tempid :db.part/user -1) | |
:gentile/name "Lord Hackworth"} | |
{:db/id (d/tempid :db.part/user) | |
:drink/name "Oolong Suchong" | |
:drink/drinker (d/tempid :db.part/user -1)}]) | |
(let [[gentile drink] (-> (d/q '{:find [?gentile ?drink] | |
:where [[?drink :drink/drinker ?gentile]]} | |
(d/db conn)) | |
first)] | |
@(d/transact conn [[:db.fn/retractEntity drink] | |
{:db/id (d/tempid :db.part/user) | |
:drink/name "Soymilk Matcha Latte" | |
:drink/drinker (d/tempid :db.part/user gentile)}]) | |
=> (throws java.util.concurrent.ExecutionException))) ;; shouldn't throw this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment