+
+
+-- | 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 "deleting news deletes its children"
+ "test/xml/newsxml.xml" ]
+ where
+ check desc path = testCase desc $ do
+ news <- unsafe_unpickle path pickle_message
+ let a = undefined :: News
+ let b = undefined :: NewsTeam
+ let c = undefined :: News_NewsTeam
+ let d = undefined :: NewsLocation
+ let e = undefined :: News_NewsLocation
+ actual <- withSqliteConn ":memory:" $ runDbConn $ do
+ runMigration silentMigrationLogger $ do
+ migrate a
+ migrate b
+ migrate c
+ migrate d
+ migrate e
+ _ <- dbimport news
+ -- No idea how 'delete' works, so do this instead.
+ executeRaw False "DELETE FROM news;" []
+ count_a <- countAll a
+ count_b <- countAll b
+ count_c <- countAll c
+ count_d <- countAll d
+ count_e <- countAll e
+ return $ count_a + count_b + count_c + count_d + count_e
+ -- There are 2 news_teams and 2 news_locations that should remain.
+ let expected = 4
+ actual @?= expected