packages feed

apiary 0.4.3.1 → 0.4.3.2

raw patch · 3 files changed

+139/−4 lines, 3 filesdep +apiarydep +test-frameworkdep +test-framework-hunitdep ~basedep ~template-haskellPVP ok

version bump matches the API change (PVP)

Dependencies added: apiary, test-framework, test-framework-hunit, wai-test

Dependency ranges changed: base, template-haskell

API changes (from Hackage documentation)

Files

apiary.cabal view
@@ -1,5 +1,5 @@ name:                apiary-version:             0.4.3.1+version:             0.4.3.2 x-revision:          1 synopsis:            Simple web framework inspired by scotty. description:@@ -63,8 +63,8 @@                       , Rank2Types                        -  build-depends:       base              >=4.5 && <4.8-                     , template-haskell  >=2.7 && <2.10+  build-depends:       base              >=4.6 && <4.8+                     , template-haskell  >=2.8 && <2.10                      , transformers      >=0.3 && <0.5                      , mtl               >=2.1 && <2.3                      , monad-control     >=0.3 && <0.4@@ -83,6 +83,20 @@                      , warp              >=2.1 && <2.2    hs-source-dirs:      src+  ghc-options:         -O2 -Wall+  default-language:    Haskell2010++test-suite test-framework+  main-is:             main.hs+  type:                exitcode-stdio-1.0+  build-depends:       base                 >=4.5 && <4.8+                     , test-framework       >=0.8 && <0.9+                     , test-framework-hunit >=0.3 && <0.4+                     , wai                  >=2.1 && <2.2+                     , wai-test             >=2.0 && <2.1+                     , apiary+                     , bytestring           >=0.10 && <0.11+  hs-source-dirs:      test   ghc-options:         -O2 -Wall   default-language:    Haskell2010 
src/Control/Monad/Apiary/Filter/Capture.hs view
@@ -7,7 +7,6 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-}  module Control.Monad.Apiary.Filter.Capture where
+ test/main.hs view
@@ -0,0 +1,122 @@+{-# LANGUAGE OverloadedStrings #-}++import Test.Framework+import Test.Framework.Providers.HUnit++import Web.Apiary+import Network.Wai+import Network.Wai.Test++import qualified Data.ByteString.Lazy as L++getRoot :: Request+getRoot = defaultRequest++postRoot :: Request+postRoot = defaultRequest { requestMethod = "POST" }++deleteRoot :: Request+deleteRoot = defaultRequest { requestMethod = "DELETE" }++putRoot :: Request+putRoot = defaultRequest { requestMethod = "PUT" }++getIndexHtml :: Request+getIndexHtml = setPath defaultRequest "/index.html"++getNeko :: Request+getNeko = setPath defaultRequest "/neko"++--------------------------------------------------------------------------------+assertPlain200 :: L.ByteString -> Application -> Request -> IO ()+assertPlain200 body app req = flip runSession app $ do+    res <- request req+    assertStatus 200 res+    assertContentType "text/plain" res+    assertBody body res++assertHtml200 :: L.ByteString -> Application -> Request -> IO ()+assertHtml200 body app req = flip runSession app $ do+    res <- request req+    assertStatus 200 res+    assertContentType "text/html" res+    assertBody body res++assert404 :: Application -> Request -> IO ()+assert404 app req = flip runSession app $ do+    res <- request req+    assertStatus 404 res+    assertContentType "text/plain" res+    assertBody "404 Page Notfound." res++--------------------------------------------------------------------------------++helloWorldApp :: Application+helloWorldApp = runApiary def $ action $ do+    contentType "text/plain"+    lbs "hello"++helloWorldAllTest :: Test+helloWorldAllTest = testGroup "helloWorld" +    [ testCase "GET /"     $ assertPlain200 "hello" helloWorldApp getRoot+    , testCase "GET /neko" $ assertPlain200 "hello" helloWorldApp getNeko+    , testCase "POST /"    $ assertPlain200 "hello" helloWorldApp postRoot+    ]++--------------------------------------------------------------------------------++methodFilterApp :: Application+methodFilterApp = runApiary def $ do+    method   "GET" . action $ contentType "text/plain" >> lbs "GET"+    stdMethod POST . action $ contentType "text/plain" >> lbs "POST"++methodFilterTest :: Test+methodFilterTest = testGroup "methodFilter"+    [ testCase "GET /"     $ assertPlain200 "GET" methodFilterApp getRoot+    , testCase "POST /"    $ assertPlain200 "POST" methodFilterApp postRoot+    , testCase "GET /neko" $ assertPlain200 "GET" methodFilterApp getNeko+    , testCase "DELETE /"  $ assert404 methodFilterApp deleteRoot+    ]++--------------------------------------------------------------------------------+rootFilterApp :: Application+rootFilterApp = runApiary def .  root . action $ do+    contentType "text/html"+    lbs "root"++rootFilterTest :: Test+rootFilterTest = testGroup "rootFilter"+    [ testCase "GET /"           $ assertHtml200 "root" rootFilterApp getRoot+    , testCase "POST /"          $ assertHtml200 "root" rootFilterApp postRoot+    , testCase "GET /neko"       $ assert404 rootFilterApp getNeko+    , testCase "GET /index.html" $ assertHtml200 "root" rootFilterApp getIndexHtml+    ]++--------------------------------------------------------------------------------++multipleFilter1App :: Application+multipleFilter1App = runApiary def $ do+    root $ do+        stdMethod GET  . action $ contentType "text/plain" >> lbs "GET /"+        stdMethod POST . action $ contentType "text/html"  >> lbs "POST /"++    stdMethod DELETE . action $ contentType "text/plain" >> lbs "DELETE ANY"++multipleFilter1Test :: Test+multipleFilter1Test = testGroup "multiple test1: root, method"+    [ testCase "GET /index.html" $ assertPlain200 "GET /"       multipleFilter1App getIndexHtml+    , testCase "POST /"          $ assertHtml200 "POST /"      multipleFilter1App postRoot+    , testCase "DELETE /"        $ assertPlain200 "DELETE ANY" multipleFilter1App deleteRoot+    , testCase "PUT /"           $ assert404 multipleFilter1App putRoot+    ]++--------------------------------------------------------------------------------++main :: IO ()+main = defaultMain +    [ helloWorldAllTest+    , methodFilterTest+    , rootFilterTest+    , multipleFilter1Test+    ]+