X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FNews.hs;h=913477168540ea47e178adca60e0d1b21bd2165e;hb=013f57feae7dc719269990544d076a2b4bb108c4;hp=2cc9698fb2d2e212fd9d45da74f71d938eca3c90;hpb=b8d151d034a338242ee1193638ff077614d10580;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/News.hs b/src/TSN/XML/News.hs index 2cc9698..9134771 100644 --- a/src/TSN/XML/News.hs +++ b/src/TSN/XML/News.hs @@ -3,7 +3,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} @@ -11,6 +10,7 @@ -- a root element \ that contains an entire news item. -- module TSN.XML.News ( + dtd, pickle_message, -- * Tests news_tests, @@ -30,7 +30,7 @@ import Data.Tuple.Curry ( uncurryN ) import Data.Typeable ( Typeable ) import Database.Groundhog ( countAll, - executeRaw, + deleteAll, insert_, migrate, runMigration, @@ -73,15 +73,21 @@ import Xml ( unsafe_unpickle ) +-- | The DTD to which this module corresponds. Used to invoke dbimport. +-- +dtd :: String +dtd = "newsxml.dtd" + + -- -- DB/XML Data types -- -- * News/Message --- | The msg_id child of contains an event_id attribute; we --- embed it into the 'News' type. We (pointlessly) use the "db_" --- prefix here so that the two names don't collide on "id" when +-- | The msg_id child of \ contains an event_id attribute; we +-- embed it into the 'News' type. We (pointlessly) use the \"db_\" +-- prefix here so that the two names don't collide on \"id\" when -- Groundhog is creating its fields using our field namer. -- data MsgId = @@ -272,7 +278,6 @@ mkPersist defaultCodegenConfig [groundhog| -- use our own codegen to peel those off before naming the columns. mkPersist tsn_codegen_config [groundhog| - entity: News - dbName: news constructors: - name: News uniques: @@ -505,9 +510,11 @@ test_unpickle_succeeds = testGroup "unpickle tests" test_on_delete_cascade :: TestTree test_on_delete_cascade = testGroup "cascading delete tests" [ check "deleting news deletes its children" - "test/xml/newsxml.xml" ] + "test/xml/newsxml.xml" + 4 -- 2 news_teams and 2 news_locations that should remain. + ] where - check desc path = testCase desc $ do + check desc path expected = testCase desc $ do news <- unsafe_unpickle path pickle_message let a = undefined :: News let b = undefined :: NewsTeam @@ -522,14 +529,11 @@ test_on_delete_cascade = testGroup "cascading delete tests" migrate d migrate e _ <- dbimport news - -- No idea how 'delete' works, so do this instead. - executeRaw False "DELETE FROM news;" [] + deleteAll a 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