From 0179bbc046606a9f2c39c89f1192bf90b9352237 Mon Sep 17 00:00:00 2001 From: Fernando Dobladez Date: Fri, 5 Jul 2013 16:21:35 -0300 Subject: [PATCH] Fix: must return ids in creation order --- src/clojure/monger/ragtime.clj | 4 ++-- test/monger/test/ragtime_test.clj | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/clojure/monger/ragtime.clj b/src/clojure/monger/ragtime.clj index 857c7f1..7628b7d 100644 --- a/src/clojure/monger/ragtime.clj +++ b/src/clojure/monger/ragtime.clj @@ -24,11 +24,11 @@ (let [xs (with-collection migrations-collection (find {}) (sort {:created_at 1}))] - (set (map :_id xs)))))) + (vec (map :_id xs)))))) (defn flush-migrations! "REMOVES all the information about previously performed migrations" [db] (mg/with-db db - (mc/remove migrations-collection))) \ No newline at end of file + (mc/remove migrations-collection))) diff --git a/test/monger/test/ragtime_test.clj b/test/monger/test/ragtime_test.clj index 6fdbbeb..8915b9b 100644 --- a/test/monger/test/ragtime_test.clj +++ b/test/monger/test/ragtime_test.clj @@ -22,10 +22,10 @@ key "1"] (mc/remove db coll {}) (is (not (mc/any? db coll {:_id key}))) - (is (not (contains? (applied-migration-ids db) key))) + (is (not (some #{key} (applied-migration-ids db)))) (add-migration-id db key) (is (mc/any? db coll {:_id key})) - (is (contains? (applied-migration-ids db) key)))) + (is (some #{key} (applied-migration-ids db))))) (deftest test-remove-migration-id @@ -35,6 +35,23 @@ (mc/remove db coll {}) (add-migration-id db key) (is (mc/any? db coll {:_id key})) - (is (contains? (applied-migration-ids db) key)) + (is (some #{key} (applied-migration-ids db))) (remove-migration-id db key) - (is (not (contains? (applied-migration-ids db) key)))))) + (is (not (some #{key} (applied-migration-ids db)))))) + + + (deftest test-migrations-ordering + (let [db (mg/get-db "monger-test") + coll "meta.migrations" + all-keys [ "9" "4" "7" "1" "5" "3" "6" "2" "8"]] + (mc/remove db coll {}) + + (doseq [key all-keys] + (add-migration-id db key)) + + (doseq [key all-keys] + (is (mc/any? db coll {:_id key})) + (is (some #{key} (applied-migration-ids db)))) + + (testing "Applied migrations must come out in creation order" + (is (= all-keys (applied-migration-ids db)))))))