{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} module TransactionLevelTest where import Init share [mkPersist sqlSettings, mkMigrate "migration"] [persistUpperCase| Wombat name Text sqltype=varchar(80) Primary name deriving Eq Show Ord |] specsWith :: (MonadIO m, MonadFail m) => RunDb SqlBackend m -> Spec specsWith :: RunDb SqlBackend m -> Spec specsWith RunDb SqlBackend m runDb = String -> Spec -> Spec forall a. HasCallStack => String -> SpecWith a -> SpecWith a describe String "IsolationLevel" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do let item :: Wombat item = Text -> Wombat Wombat Text "uno" isolationLevels :: [IsolationLevel] isolationLevels = [IsolationLevel forall a. Bounded a => a minBound..IsolationLevel forall a. Bounded a => a maxBound] [IsolationLevel] -> (IsolationLevel -> Spec) -> Spec forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [IsolationLevel] isolationLevels ((IsolationLevel -> Spec) -> Spec) -> (IsolationLevel -> Spec) -> Spec forall a b. (a -> b) -> a -> b $ \IsolationLevel il -> String -> Spec -> Spec forall a. HasCallStack => String -> SpecWith a -> SpecWith a describe String "insertOnDuplicateKeyUpdate" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it (IsolationLevel -> String forall a. Show a => a -> String show IsolationLevel il String -> ShowS forall a. [a] -> [a] -> [a] ++ String " works") (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ RunDb SqlBackend m runDb RunDb SqlBackend m -> RunDb SqlBackend m forall a b. (a -> b) -> a -> b $ do IsolationLevel -> ReaderT SqlBackend m () forall (m :: * -> *). MonadIO m => IsolationLevel -> ReaderT SqlBackend m () transactionUndoWithIsolation IsolationLevel il [Filter Wombat] -> ReaderT SqlBackend m () forall backend (m :: * -> *) record. (PersistQueryWrite backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m () deleteWhere ([] :: [Filter Wombat]) Wombat -> ReaderT SqlBackend m () forall backend record (m :: * -> *). (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m () insert_ Wombat item Just Wombat item' <- Key Wombat -> ReaderT SqlBackend m (Maybe Wombat) forall backend record (m :: * -> *). (PersistStoreRead backend, MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record) get (Text -> Key Wombat WombatKey Text "uno") Wombat item' Wombat -> Wombat -> ReaderT SqlBackend m () forall a (m :: * -> *). (HasCallStack, Eq a, Show a, MonadIO m) => a -> a -> m () @== Wombat item