+
+
+-- | Make sure everything gets deleted when we delete the top-level
+-- record. The casinos and teams should be left behind.
+--
+test_on_delete_cascade :: TestTree
+test_on_delete_cascade = testGroup "cascading delete tests"
+ [ check "deleting odds deletes its children"
+ "test/xml/Odds_XML.xml"
+ 13 -- 5 casinos, 8 teams
+ ,
+
+ check "deleting odds deletes its children (non-int team_id)"
+ "test/xml/Odds_XML-noninteger-team-id.xml"
+ 51 -- 5 casinos, 46 teams
+ ,
+
+ check "deleting odds deleted its children (positive(+) line)"
+ "test/xml/Odds_XML-positive-line.xml"
+ 17 -- 5 casinos, 12 teams
+ ,
+
+ check "deleting odds deleted its children (large file)"
+ "test/xml/Odds_XML-largefile.xml"
+ 189 -- 5 casinos, 184 teams
+ ,
+ check "deleting odds deleted its children (league name)"
+ "test/xml/Odds_XML-league-name.xml"
+ 35 -- 5 casinos, 30 teams
+ ,
+ check "deleting odds deleted its children (missing starters)"
+ "test/xml/Odds_XML-missing-starters.xml"
+ 7 -- 5 casinos, 2 teams
+ ,
+ check "deleting odds deleted its children (TBA game time)"
+ "test/xml/Odds_XML-tba-game-time.xml"
+ 119 -- 5 casinos, 114 teams
+ ,
+ check "deleting odds deleted its children (empty casino)"
+ "test/xml/Odds_XML-empty-casino.xml"
+ 11 -- 5 casinos, 6 teams
+ ,
+ check "deleting odds deleted its children (long import)"
+ "test/xml/Odds_XML-long-import.xml"
+ 219 -- 5 casinos, 214 teams
+ ]
+ where
+ check desc path expected = testCase desc $ do
+ odds <- unsafe_unpickle path pickle_message
+ let a = undefined :: Team
+ let b = undefined :: Odds
+ let c = undefined :: OddsCasino
+ let d = undefined :: OddsGame
+ let e = undefined :: OddsGameLine
+ actual <- withSqliteConn ":memory:" $ runDbConn $ do
+ runMigrationSilent $ do
+ migrate a
+ migrate b
+ migrate c
+ migrate d
+ migrate e
+ _ <- dbimport odds
+ deleteAll b
+ count_a <- countAll a
+ count_b <- countAll b
+ count_c <- countAll c
+ count_d <- countAll d
+ count_e <- countAll e
+ return $ sum [count_a, count_b, count_c,
+ count_d, count_e ]
+ actual @?= expected