Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
migrating to 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
narkisr committed Apr 27, 2012
1 parent 7c44c2b commit 9cd67a7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/com/narkisr/couchfs/couch_file.clj
Expand Up @@ -8,7 +8,7 @@
)
(:use
[slingshot.slingshot :only [try+]]
[cheshire.core :only [parse-string ]]
[cheshire.core :only [parse-string]]
(com.narkisr common-fs file-info)
)
(:import (couchdb.errors ResourceConflict) )
Expand All @@ -19,9 +19,9 @@
(try+
(if attachment
(file-update/update-attachment path couch-id (:name file) contents-str)
(file-update/update-rev-and-time path (couch/update-document couch-id (parse-string contents-str))))
(file-update/update-rev-and-time path (couch/update-document couch-id (parse-string contents-str true))))
(catch ResourceConflict e
(file-update/use-lastest-rev path couch-id (parse-string contents-str))))))
(file-update/use-lastest-rev path couch-id (parse-string contents-str true))))))

(defn fetch-content
([file] (-> file :content (apply [])))
Expand Down
8 changes: 5 additions & 3 deletions test/com/narkisr/attachments.clj
@@ -1,20 +1,22 @@
(ns com.narkisr.attachments
(:import java.io.File)
(:use
(clojure (test :only [use-fixtures deftest is]))
(com.narkisr common-test)
(clojure.contrib shell-out (duck-streams :only [slurp*]) test-is str-utils)))
(clojure.java (shell :only [sh]))
))

; these tests actually mount a live couchdb therefor they require one up
(use-fixtures :once mount-and-sleep)

(deftest add-attachment
(spit (File. file-path) "<html>hello world</html>")
(is (= (-> (File. file-path) slurp*) "<html>hello world</html>"))
(is (= (slurp file-path) "<html>hello world</html>"))
(sh "rm" file-path)
(is (not (-> file-path (File.) (.exists))))
(spit (File. file-path) "<html>hello world</html>")
(sh "mv" file-path rename-path)
(is (= (-> (File. rename-path) slurp*) "<html>hello world</html>")))
(is (= (slurp rename-path) "<html>hello world</html>")))

(deftest multiple-attachments
(let [names (range 0 20) target "fake/multi/" hidden "fake/.multi"]
Expand Down
4 changes: 3 additions & 1 deletion test/com/narkisr/common_test.clj
Expand Up @@ -3,8 +3,10 @@
(:import java.io.File)
(:use
(com.narkisr.couchfs (mounter :only [mount-with-group]))
(clojure.java (shell :only [sh]))
(com.narkisr fs-logic )
(clojure.contrib shell-out )))
))


(def meta-file)
(def uuid)
Expand Down
6 changes: 4 additions & 2 deletions test/com/narkisr/fs_logic_test.clj
@@ -1,5 +1,7 @@
(ns com.narkisr.fs-logic-test
(:use clojure.contrib.test-is com.narkisr.fs-logic)
(:use
(clojure (test :only [use-fixtures deftest is]))
com.narkisr.fs-logic)
(:import com.narkisr.protocols.Directory
com.narkisr.protocols.Root
com.narkisr.protocols.MetaFolder
Expand All @@ -8,7 +10,7 @@
(defn init [f]
(let [content "some nice content"]
(dosync (ref-set root (Root. "" 0755 [:description "Root directory"] 0
{"README" (File. "README" 0644 [:description "A Readme File" :mimetype "text/plain"] 0 (. content getBytes) (. content length) )})))
{"README" (File. "README" 0644 [:description "A Readme File" :mimetype "text/plain"] 0 (. content getBytes) (. content length) )})))
(f)))

(use-fixtures :once init)
Expand Down
15 changes: 9 additions & 6 deletions test/com/narkisr/integration.clj
Expand Up @@ -2,14 +2,17 @@
(:require [com.narkisr.protocols :as proto])
(:import java.io.File)
(:use
(com.narkisr.couchfs (couch-access :only [update-document get-document]))
(com.narkisr fs-logic common-test)
(clojure.contrib shell-out test-is str-utils (duck-streams :only [slurp*]) (json :only [read-json json-str]))))
[clojure.test :only [use-fixtures deftest is do-template]]
[cheshire.core :only [parse-string generate-string]]
[clojure.java.shell :only [sh]]
(com.narkisr.couchfs
(couch-access :only [update-document get-document]))
(com.narkisr fs-logic common-test)))

; these tests actually mount a live couchdb therefor they require one up
(use-fixtures :once mount-and-sleep)

(defn slurp-json [] (-> meta-file (File.) slurp* read-json))
(defn slurp-json [] (-> meta-file slurp (parse-string true)))

(deftest empty-ls
(is (= (sh "ls" "fake") (str uuid "\n"))))
Expand All @@ -21,9 +24,9 @@

(deftest in-place-edit
"Note that using :key won't work when assoc or dissoc since couch is saving it as a string."
(spit (File. meta-file) (json-str (assoc (slurp-json) :key "value")))
(spit (File. meta-file) (generate-string (assoc (slurp-json) :key "value")))
(is (= ((slurp-json) :key) "value"))
(spit (File. meta-file) (json-str (dissoc (slurp-json) :key "value")))
(spit (File. meta-file) (generate-string (dissoc (slurp-json) :key "value")))
(is (= (contains? (slurp-json) :key) false))
(is (= ((slurp-json) :_rev) ((get-document uuid) :_rev))))

Expand Down
16 changes: 16 additions & 0 deletions test/com/narkisr/utils.clj
@@ -0,0 +1,16 @@
(ns com.narkisr.utils
(:import java.lang.IllegalArgumentException))

; see http://tinyurl.com/d5kceu8
(defmacro do-template
"Repeatedly evaluates template expr (in a do block) using values in
args. args are grouped by the number of holes in the template.
Example: (do-template (check _1 _2) :a :b :c :d)
expands to (do (check :a :b) (check :c :d))"
[expr & args]
(when-not (template? expr)
(throw (IllegalArgumentException. (str (pr-str expr) " is not a valid template."))))
(let [expr (walk/postwalk-replace {'_ '_1} expr)
argcount (count (find-holes expr))]
`(do ~@(map (fn [a] (apply-template expr a))
(partition argcount args)))))

0 comments on commit 9cd67a7

Please sign in to comment.