File: MigrationOnlySpec.hs

package info (click to toggle)
haskell-persistent 2.17.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,196 kB
  • sloc: haskell: 14,076; makefile: 3
file content (65 lines) | stat: -rw-r--r-- 1,892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

module Database.Persist.TH.MigrationOnlySpec where

import TemplateTestImports

import Data.Text (Text)

import Database.Persist.ImplicitIdDef
import Database.Persist.ImplicitIdDef.Internal (fieldTypeFromTypeable)
import Database.Persist.Types

mkPersist sqlSettings [persistLowerCase|

HasMigrationOnly
    name String
    blargh Int MigrationOnly

    deriving Eq Show
|]

pass :: IO ()
pass = pure ()

asIO :: IO a -> IO a
asIO = id

spec :: Spec
spec = describe "MigrationOnlySpec" $ do
    describe "HasMigrationOnly" $ do
        let
            edef =
                entityDef $ Proxy @HasMigrationOnly
        describe "getEntityFields" $ do
            it "has one field" $ do
                length (getEntityFields edef)
                    `shouldBe` 1
        describe "getEntityFieldsDatabase" $ do
            it "has two fields" $ do
                length (getEntityFieldsDatabase edef)
                    `shouldBe` 2
        describe "toPersistFields" $ do
            it "should have one field" $ do
                map toPersistValue (toPersistFields (HasMigrationOnly "asdf"))
                    `shouldBe`
                        [PersistText ("asdf" :: Text)]
        describe "fromPersistValues" $ do
            it "should work with only item in list" $ do
                fromPersistValues [PersistText "Hello"]
                    `shouldBe`
                        Right (HasMigrationOnly "Hello")