 
 (facts "about registration"
        (fact "user can register with valid credentials and is redirected to profile-created page, with user-login and access_token added to session"
-             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params {:some "session-data"})
-                                 (u/register-user @storage/user-store))
-                   registered-user (user/retrieve-user @storage/user-store email)]
+             (let [user-store (m/create-memory-store)
+                   response (->> (th/create-request :post (routes/path :register-user) register-user-params {:some "session-data"})
+                                 (u/register-user user-store))
+                   registered-user (user/retrieve-user user-store email)]
                response => (check-redirects-to (routes/path :show-profile-created))
                response => (contains {:session (contains {:user-login   (:login registered-user)
                                                           :access_token (complement nil?)})})))
 
        (fact "session is not lost when redirecting from registration"
-             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params {:some "session-data"})
-                                 (u/register-user @storage/user-store))]
+             (let [user-store (m/create-memory-store)
+                   response (->> (th/create-request :post (routes/path :register-user) register-user-params {:some "session-data"})
+                                 (u/register-user user-store))]
                response => (check-redirects-to (routes/path :show-profile-created))
                response => (contains {:session (contains {:some "session-data"})})))
 
        (fact "user data is saved"
-             (->> (th/create-request :post (routes/path :register-user) register-user-params)
-                  (u/register-user @storage/user-store)) => anything
-             (provided
-               (user/store-user! @storage/user-store "valid@email.com" "password") => ...user...))
+             (let [user-store (m/create-memory-store)]
+               (->> (th/create-request :post (routes/path :register-user) register-user-params)
+                    (u/register-user user-store))) => anything
+             (provided
+              (user/store-user! anything "valid@email.com" "password") => ...user...))
 
        (fact "user is send a confirmation email with the correct content"
              (against-background
                (uuid/uuid) => confirmation-id)
-             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params)
-                                 (u/register-user @storage/user-store))
-                   registered-user (user/retrieve-user @storage/user-store email)]
+             (let [user-store (m/create-memory-store)
+                   response (->> (th/create-request :post (routes/path :register-user) register-user-params)
+                                 (u/register-user user-store))
+                   registered-user (user/retrieve-user user-store email)]
                (:email @most-recent-email) => email
                (:body @most-recent-email) => (contains {:confirmation-id confirmation-id})))
 
        (fact "when user email is send, flash message is assoc-ed in redirect"
              (against-background
                (uuid/uuid) => confirmation-id)
-             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params)
-                                 (u/register-user @storage/user-store))]
+             (let [user-store (m/create-memory-store)
+                   response (->> (th/create-request :post (routes/path :register-user) register-user-params)
+                                 (u/register-user user-store))]
                (:flash response) => :confirm-email-sent)))
 
 (facts "about registration validation errors"
        (fact "email must not be a duplicate"
-             (let [html-response (->> (th/create-request :post "/register" register-user-params)
-                                      (u/register-user @storage/user-store)
+             (let [user-store (m/create-memory-store)
+                   html-response (->> (th/create-request :post "/register" register-user-params)
+                                      (u/register-user user-store)
                                       :body
                                       html/html-snippet)]
                (-> (html/select html-response [:.form-row--validation-error])

            [stonecutter.db.client :as c]
            [stonecutter.db.user :as user]
            [stonecutter.db.storage :as storage]
            [stonecutter.util.uuid :as uuid]
            [stonecutter.validation :as v]))


(fact "account can be deleted, user is redirected to profile-deleted and session is cleared"
      (->> (th/create-request :post "/delete-account" nil {:user-login   "account_to_be@deleted.com"
                                                        :access_token ...token...})
           (u/delete-account ...user-store...)) => (every-checker
                                                    (check-redirects-to "/profile-deleted")
                                                    (contains {:session nil}))
      (provided
       (user/delete-user! ...user-store... "account_to_be@deleted.com") => anything))

(fact "user can access profile-deleted page when not signed in"
      (-> (th/create-request :get "/profile-deleted" nil)
