From 60bc2b1a8b8354b6565793d2a40b8cc4287fc15c Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 8 Apr 2014 18:10:32 +1000 Subject: [PATCH] Add test for orderRandom. --- test/Test.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/Test.hs b/test/Test.hs index 85e886c..e1f3152 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -795,6 +795,21 @@ main = do ret <- select $ from (\(_::(SqlExpr (Entity BlogPost))) -> return countRows) liftIO $ ret `shouldBe` [Value (3::Int)] + describe "rand works" $ do + it "returns result in random order" $ + run $ do + _ <- insert p1 + _ <- insert p2 + _ <- insert p3 + _ <- insert p4 + ret1 <- fmap (map unValue) $ select $ from $ \p -> do + orderBy [rand] + return (p ^. PersonId) + ret2 <- fmap (map unValue) $ select $ from $ \p -> do + orderBy [rand] + return (p ^. PersonId) + + liftIO $ (ret1 == ret2) `shouldBe` False ---------------------------------------------------------------------- @@ -859,3 +874,6 @@ run_worker act = #else (runMigrationSilent migrateAll >>) $ act #endif + +unValue :: Value a -> a +unValue (Value a) = a