-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple test for schema functionality.
- Loading branch information
Showing
4 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE UndecidableInstances #-} | ||
module SchemaTest where | ||
|
||
import Init | ||
import qualified PersistentTestModels as PTM | ||
|
||
share [mkPersist persistSettings, mkMigrate "migration"] [persistLowerCase| | ||
Person schema=my_special_schema | ||
name Text | ||
age Int | ||
weight Int | ||
deriving Show Eq | ||
|] | ||
|
||
cleanDB :: (MonadIO m, PersistQuery backend, PersistEntityBackend Person ~ backend) => ReaderT backend m () | ||
cleanDB = do | ||
deleteWhere ([] :: [Filter Person]) | ||
deleteWhere ([] :: [Filter PTM.Person]) | ||
|
||
specsWith :: (MonadIO m, MonadFail m) => RunDb SqlBackend m -> Spec | ||
specsWith runDb = describe "schema support" $ do | ||
it "insert a Person under non-default schema" $ runDb $ do | ||
insert_ $ Person "name" 1 2 | ||
return () | ||
it "insert PTM.Person and Person and check they end up in different tables" $ runDb $ do | ||
cleanDB | ||
insert_ $ Person "name" 1 2 | ||
insert_ $ PTM.Person "name2" 3 Nothing | ||
schemaPersonCount <- count ([] :: [Filter Person]) | ||
ptmPersoncount <- count ([] :: [Filter PTM.Person]) | ||
-- both tables should contain only one record despite similarly named Entities | ||
schemaPersonCount + ptmPersoncount @== 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters