+
+
+-- | Make sure everything gets deleted when we delete the top-level
+-- record.
+--
+test_on_delete_cascade :: TestTree
+test_on_delete_cascade = testGroup "cascading delete tests"
+ [ check "unpickling succeeds"
+ "test/xml/scoresxml.xml"
+ 4, -- 2 teams, 2 locations
+
+ check "unpickling succeeds (no locations)"
+ "test/xml/scoresxml-no-locations.xml"
+ 2 -- 2 teams, 0 locations
+ ]
+ where
+ check desc path expected = testCase desc $ do
+ score <- unsafe_unpickle path pickle_message
+ let a = undefined :: Score
+ let b = undefined :: ScoreGame
+ let c = undefined :: ScoreGameTeam
+ let d = undefined :: ScoreGame_ScoreGameTeam
+ let e = undefined :: ScoreLocation
+ let f = undefined :: Score_ScoreLocation
+ actual <- withSqliteConn ":memory:" $ runDbConn $ do
+ runMigration silentMigrationLogger $ do
+ migrate a
+ migrate b
+ migrate c
+ migrate d
+ migrate e
+ migrate f
+ _ <- dbimport score
+ -- No idea how 'delete' works, so do this instead.
+ executeRaw False "DELETE FROM scores;" []
+ count_a <- countAll a
+ count_b <- countAll b
+ count_c <- countAll c
+ count_d <- countAll d
+ count_e <- countAll e
+ count_f <- countAll f
+ return $ sum [count_a, count_b, count_c,
+ count_d, count_e, count_f ]
+ actual @?= expected