Blob Blame History Raw
From 2d78eac7bf5e756f817fae9c9f8fec1071004c27 Mon Sep 17 00:00:00 2001
From: Keenan Brock <keenan@thebrocks.net>
Date: Mon, 14 Dec 2015 17:04:46 -0500
Subject: [PATCH] support tests with various id sorting

---
 test/concerns/sort_by_ancestry_test.rb | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/test/concerns/sort_by_ancestry_test.rb b/test/concerns/sort_by_ancestry_test.rb
index 0629d0b..878473f 100644
--- a/test/concerns/sort_by_ancestry_test.rb
+++ b/test/concerns/sort_by_ancestry_test.rb
@@ -3,6 +3,11 @@ require_relative '../environment'
 class SortByAncestryTest < ActiveSupport::TestCase
   def test_sort_by_ancestry
     AncestryTestDatabase.with_model do |model|
+      # - n1
+      #   - n2
+      #     - n3
+      #     - n4
+      #   - n5
       n1 = model.create!
       n2 = model.create!(:parent => n1)
       n3 = model.create!(:parent => n2)
@@ -10,7 +15,19 @@ class SortByAncestryTest < ActiveSupport::TestCase
       n5 = model.create!(:parent => n1)
 
       records = model.sort_by_ancestry(model.all.sort_by(&:id).reverse)
-      assert_equal [n1, n2, n4, n3, n5].map(&:id), records.map(&:id)
+      if records[1] == n2
+        if records[2] == n3
+          assert_equal [n1, n2, n3, n4, n5].map(&:id), records.map(&:id)
+        else
+          assert_equal [n1, n2, n4, n3, n5].map(&:id), records.map(&:id)
+        end
+      else
+        if records[3] == n3
+          assert_equal [n1, n5, n2, n3, n4].map(&:id), records.map(&:id)
+        else
+          assert_equal [n1, n5, n2, n4, n3].map(&:id), records.map(&:id)
+        end
+      end
     end
   end
 
@@ -27,4 +44,4 @@ class SortByAncestryTest < ActiveSupport::TestCase
       assert_equal [n1, n3, n5, n2, n4, n6].map(&:id), records.map(&:id)
     end
   end
-end
\ No newline at end of file
+end
-- 
2.5.5