moves computing dummy-view outside of view-check

This commit is contained in:
Dave Della Costa 2014-06-19 12:08:35 +09:00
parent fc941ce90e
commit 21f6ff29d2
2 changed files with 6 additions and 6 deletions

View file

@ -27,9 +27,8 @@
(map #(str "?" %) (range 0 (count (rest view-sig)))))
(defn view-check
[action view-fn view-sig]
(let [view-map (apply view-fn (view-sig->dummy-args view-sig))
{:keys [p q]} (swap-preds view-map)]
[action dummy-vm]
(let [{:keys [p q]} (swap-preds dummy-vm)]
(-> q
(update-in [:where] #(merge % (:where action)))
(assoc :select (mapv second p)))))

View file

@ -15,8 +15,9 @@
(is (= (:where q) (:where swapped)))))
(deftest constructs-view-check
(let [update (hsql/build :update :foo :set {:d "d"} :where [:= :c "c"])
check (hsql/build :select [:a :b] :from :foo :where [:and [:and true true] [:= :c "c"]])
calcc (vc/view-check update view [:view 1 2])]
(let [dummy-vm (apply view (vc/view-sig->dummy-args [:view 1 2]))
update (hsql/build :update :foo :set {:d "d"} :where [:= :c "c"])
check (hsql/build :select [:a :b] :from :foo :where [:and [:and true true] [:= :c "c"]])
calcc (vc/view-check update dummy-vm)] ;;view )]
(is (= (into #{} (:select check)) (into #{} (:select calcc))))
(is (= (:where check) (:where calcc)))))