Permalink
Browse files

added tests for solutions/get-solutions

  • Loading branch information...
1 parent eb0ec8e commit d4cadbca1d656f94c602abf9b4a8a8c67969e6d5 @ckirkendall ckirkendall committed Nov 24, 2011
Showing with 50 additions and 6 deletions.
  1. +8 −1 resources/error-messages.properties
  2. +4 −5 src/foreclojure/solutions.clj
  3. +38 −0 test/foreclojure/test/solutions.clj
@@ -21,4 +21,11 @@ settings.email-exists=User with this email address already exists
security.login-required=You must %s to do this
security.err-reset-email=Something went wrong emailing your new password! Please contact <a href='mailto:team@4clojure.com?subject=Password Reset: %s'>team@4clojure.com</a> - we'll reset it manually and look into the problem. When you do, please mention your username.
-security.email-unknown=We don't know anyone with that email address!
+security.email-unknown=We don't know anyone with that email address!
+
+#######################################
+# solution related error messages #
+#######################################
+
+solution.scored-early=Scored %d, before 4clojure started saving solutions.
+solution.solved-early=Solved before 4clojure started scoring solutions
@@ -1,7 +1,8 @@
(ns foreclojure.solutions
(:require [clojure.string :as s])
(:use [somnium.congomongo :only [fetch-one update!]]
- [useful.debug :only [?]]))
+ [useful.debug :only [?]]
+ [foreclojure.messages :only [err-msg]]))
(defn get-solution
([perm-level user-id problem-id]
@@ -19,10 +20,8 @@
:where {:_id user-id}
:only [(keyword (str "scores." problem-id))
:solved])]
- (cond (seq scores) (str "Scored " (first (vals scores))
- ", before 4clojure started saving solutions."),
-
- (some #{problem-id} solved) "Solved before 4clojure started scoring solutions")))))
+ (cond (seq scores) (err-msg "solution.scored-early" (first (vals scores))),
+ (some #{problem-id} solved) (err-msg "solution.solved-early"))))))
(defn save-solution [user-id problem-id code]
(update! :solutions
@@ -0,0 +1,38 @@
+(ns foreclojure.test.solutions
+ (:require [clojure.string :as s])
+ (:use [somnium.congomongo :only [fetch-one update!]])
+ (:use [useful.debug :only [?]])
+ (:use [foreclojure.messages :only [err-msg]])
+ (:use [foreclojure.solutions])
+ (:use [clojure.test])
+ (:use [midje.sweet]))
+
+(deftest test-get-solution
+ "this test covers the getting solutions to display"
+ (let [uid 1
+ pid 1
+ code "I AM SOME COOL CODE"]
+ (fact "about get-solution: private"
+ (get-solution :private uid pid) => code
+ (provided
+ (fetch-one :solutions :where {:user uid :problem pid}) => {:code code}))
+ (fact "about get-solution: hide solutions"
+ (get-solution :public uid pid) => falsey
+ (provided
+ (fetch-one :users :where {:_id uid} :only [:hide-solutions]) => {:hide-solutions true}))
+ (fact "about get-solution: scored early"
+ (get-solution uid pid) => (err-msg "solution.scored-early" pid)
+ (provided
+ (fetch-one :solutions :where {:user uid, :problem pid}) => {}
+ (fetch-one :users
+ :where {:_id uid}
+ :only [(keyword (str "scores." pid))
+ :solved]) => {:scores {pid pid} :solved []}))
+ (fact "about get-solution: solved early"
+ (get-solution uid pid) => (err-msg "solution.solved-early")
+ (provided
+ (fetch-one :solutions :where {:user uid, :problem pid}) => {}
+ (fetch-one :users
+ :where {:_id uid}
+ :only [(keyword (str "scores." pid))
+ :solved]) => {:scores {} :solved [pid]}))))

0 comments on commit d4cadbc

Please sign in to comment.