Skip to content
Browse files

Updated to the latest version of clj-record. Created an initial trust…

… score table and model.
  • Loading branch information...
1 parent 600a97f commit 16294823653ecd45935f536cb5b1f4fe0a46253f @macourtney committed
View
1 .gitignore
@@ -10,4 +10,5 @@ db
classes
logs
private_key.dat
+.lein-failures
pom.xml
View
2 project.clj
@@ -5,7 +5,7 @@
[commons-codec/commons-codec "1.5"]
[drift "1.2.2"]
[log4j/log4j "1.2.16"]
- [org.clojars.macourtney/clj-record "1.0.1"]
+ [org.clojars.macourtney/clj-record "1.0.2"]
[org.clojars.macourtney/i2p "0.8.7-0"]
[org.clojars.macourtney/mstreaming "0.8.7-0"]
[org.clojars.macourtney/streaming "0.8.7-0"]
View
4 src/darkexchange/model/identity.clj
@@ -37,7 +37,9 @@
(listener identity)))
(clj-record.core/init-model
- (:associations (belongs-to peer))
+ (:associations (belongs-to peer)
+ (has-many scorer_trust_scores :fk target_id)
+ (has-many target-trust-scores :fk target_id :model trust-score))
(:callbacks (:after-update identity-update)
(:after-insert identity-add)
(:after-destroy identity-delete)))
View
11 src/darkexchange/model/trust_score.clj
@@ -0,0 +1,11 @@
+(ns darkexchange.model.trust-score
+ (:require [clj-record.boot :as clj-record-boot]
+ [darkexchange.model.identity :as identity])
+ (:use darkexchange.model.base))
+
+(clj-record.core/init-model
+ (:associations (belongs-to scorer :fk scorer_id :model identity)
+ (belongs-to target :fk target_id :model identity)))
+
+(defn add-trust-score [target-identity basic-score]
+ (insert { :scorer_id (:id (identity/current-user-identity)) :target_id (:id target-identity) :basic basic-score }))
View
20 test/test/darkexchange/model/trust_score.clj
@@ -0,0 +1,20 @@
+(ns test.darkexchange.model.trust-score
+ (:require [test.init :as test-init]
+ [darkexchange.model.identity :as identity-model]
+ [test.fixtures.identity :as identity-fixture]
+ [test.fixtures.util :as fixtures-util])
+ (:use clojure.contrib.test-is
+ darkexchange.model.trust-score))
+
+(fixtures-util/use-fixture-maps :once identity-fixture/fixture-map)
+
+(deftest test-add-trust-score
+ (let [basic-trust-score 0.5
+ target-identity (identity-model/get-record 1)
+ trust-score-id (add-trust-score target-identity basic-trust-score)
+ trust-score (when trust-score-id (get-record trust-score-id))]
+ (is trust-score-id)
+ (is (= basic-trust-score (:basic trust-score)))
+ (is (= (:id (identity-model/current-user-identity)) (:scorer_id trust-score)))
+ (is (= (:id target-identity) (:target_id trust-score)))
+ (destroy-record trust-score)))
View
18 test/test/fixtures/identity.clj
@@ -6,7 +6,23 @@
(def records [
{ :id 1
:name "test-identity"
- :public_key "blah"
+ :public_key "blah"
+ :public_key_algorithm "RSA"
+ :peer_id 1 }
+ { :id 2
+ :name "test-user"
+ :public_key ""
+ :public_key_algorithm "RSA"
+ :peer_id 1 }
+ { :id 3
+ :name "test-identity2"
+ :public_key "blah2"
+ :public_key_algorithm "RSA"
+ :peer_id 1 }
+ { :id 4
+ :name "test-identity3"
+ :public_key "blah3"
+ :public_key_algorithm "RSA"
:peer_id 1 }])
(def fixture-table-name :identities)

0 comments on commit 1629482

Please sign in to comment.
Something went wrong with that request. Please try again.