Commits

Anonymous committed ba17af5

add unit test for :groupby and :other attributes in entity/find-xxx functions

Comments (0)

Files changed (2)

 
 ## 0.2 / 2010-Sep-?? (GMT+5:30)
 
+- [TODO] Add support for composite primary keys
 - [TODO] Support large sized query result-sets (by adding lazy loading option)
-- [TODO] Add :group-by and :rest arguments to entity/find-xxx functions
 - [TODO] Optimistic locks using lock-counter field (optional column in meta)
 - [TODO] *show-sql* to be implemented for non-SELECT queries too
-- [TODO] Add support for composite primary keys
 
 - DSL for SQL clauses, Sub-query support
+- Support :groupby and :other attributes in entity/find-xxx functions
 
 - [????] Provide 'insert' and 'update' functions
 

src/test/clj/org/bituf/sqlrat/test/dbblog.clj

 (ns org.bituf.sqlrat.test.dbblog
   (:use org.bituf.sqlrat.entity)
+  (:use org.bituf.sqlrat.clause)
   (:use org.bituf.sqlrat.test.dbconfig)
   (:use org.bituf.sqlrat.test.util)
   (:use clojure.test))
         (is (and (not-nil? newid) (not (zero? newid))))
         (ppe "Saved row #3" saved)))))
 
+
 (deftest test-read-entry-table
   (print-test-title "test-read-entry-table")
   (fail-on-exception
         (is (= 3 (count ea)))
         (ppe "\nAll rows:" ea)))))
 
+
 (deftest test-populate-comment-table
   (print-test-title "test-populate-comment-table")
   (fail-on-exception
         (is (not (zero? (get-id-value (saved 2)))))
         (ppe "Saved 3 children for entry (ID=3)" saved)))))
 
+
 (deftest test-fetch-entry-comment-graph
   (print-test-title "test-fetch-entry-comment-graph")
   (fail-on-exception
           (println (str "\nComments# for entry ID: " (:autoid each))
             (read-count-col (comments each))))))))
 
+
+(deftest test-comment-groupby-other
+  (print-test-title "test-comment-groupby-other")
+  (fail-on-exception
+    (println "** Fetching comments using GROUP BY and LIMIT **")
+    (in-db db
+      (let [entries (find-by-criteria blog-entry-meta)
+            comments (find-rels entries entry-comment-meta :cols count-col
+                       :other (limit 1 2))]
+        (is (= 3 (count entries)))
+        (ppe "\nAll entries:" entries)
+        (doseq [each entries]
+          (is (= (read-count-col (comments each)) ({2 2 3 3} (:autoid each))))
+          (println (str "\nComments# for entry ID: " (:autoid each))
+            (read-count-col (comments each))))))))
+
+
 (deftest test-fetch-comment-siblings
   (print-test-title "test-fetch-comment-siblings")
   (fail-on-exception
         (ppe "\nSiblings with WHERE clause:" sw)
         (ppe "\nSiblings with selected columns and WHERE clause:" sb)))))
 
+
 (deftest test-count-function
   (print-test-title "test-count-function")
   (fail-on-exception
         (is (= 2 (read-count-col s)))
         (is (= 1 (read-count-col sw)))))))
 
+
 (deftest test-delete-entities
   (print-test-title "test-delete-entities")
   (fail-on-exception
           (let [ne (find-by-id blog-entry-meta 3)]
             (is (nil? ne))))))))
 
+
 (defn test-ns-hook []
   (test-recreate-tables)
   (test-populate-entry-table)
   (test-read-entry-table)
   (test-populate-comment-table)
   (test-fetch-entry-comment-graph)
+  (test-comment-groupby-other)
   (test-fetch-comment-siblings)
   (test-count-function)
   (test-delete-entities))