From 1f92c3fd2ef91420736ba1b8e39acdc8ca3840a9 Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 27 May 2016 13:11:38 -0400 Subject: [PATCH] update test memory database in prep. for usage in upcoming tests --- test/views/subscription_tests.clj | 2 +- test/views/test_memory_db.clj | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/test/views/subscription_tests.clj b/test/views/subscription_tests.clj index a5b71ef..d4bdefe 100644 --- a/test/views/subscription_tests.clj +++ b/test/views/subscription_tests.clj @@ -28,7 +28,7 @@ (reset! test-sent-data []) (f)) -(use-fixtures :each clear-sent-data-fixture reset-system-fixture) +(use-fixtures :each clear-sent-data-fixture reset-system-fixture reset-memory-db-fixture) diff --git a/test/views/test_memory_db.clj b/test/views/test_memory_db.clj index 54a437b..82bd761 100644 --- a/test/views/test_memory_db.clj +++ b/test/views/test_memory_db.clj @@ -3,9 +3,18 @@ views.protocols views.core)) +(def base-memory-db-contents + {:a {:foo 1 :bar 200 :baz [1 2 3]} + :b {:foo 2 :bar 300 :baz [2 3 4]}}) + (def memory-database - (atom {:a {:foo 1 :bar 200 :baz [1 2 3]} - :b {:foo 2 :bar 300 :baz [2 3 4]}})) + (atom base-memory-db-contents)) + +(defn reset-memory-db-fixture [f] + (reset! memory-database base-memory-db-contents) + (f)) + +(def memory-view-hint-type :memory-db) (defrecord MemoryView [id ks] IView @@ -16,7 +25,8 @@ (into parameters)))) (relevant? [_ namespace parameters hints] (some #(and (= namespace (:namespace %)) - (= ks (:hint %))) + (= ks (:hint %)) + (= memory-view-hint-type (:type %))) hints))) (defrecord SlowMemoryView [id ks] @@ -30,7 +40,8 @@ (into parameters)))) (relevant? [_ namespace parameters hints] (some #(and (= namespace (:namespace %)) - (= ks (:hint %))) + (= ks (:hint %)) + (= memory-view-hint-type (:type %))) hints))) (def views @@ -42,3 +53,9 @@ [(SlowMemoryView. :foo [:foo]) (SlowMemoryView. :bar [:bar]) (SlowMemoryView. :baz [:baz])]) + +(defn memory-db-assoc-in! + [namespace ks v] + (let [ms (swap! memory-database assoc-in (into [namespace] ks) v)] + (put-hints! [(hint namespace ks memory-view-hint-type)]) + ms))