Remove unused Comment functionality from the scaffolding
This commit is contained in:
parent
d96bc12834
commit
0a230e7644
5 changed files with 0 additions and 63 deletions
|
@ -6,6 +6,4 @@
|
|||
|
||||
/ HomeR GET
|
||||
|
||||
/comments CommentR POST
|
||||
|
||||
/profile ProfileR GET
|
||||
|
|
|
@ -49,7 +49,6 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet,
|
|||
-- Don't forget to add new modules to your cabal file!
|
||||
import Handler.Common
|
||||
import Handler.Home
|
||||
import Handler.Comment
|
||||
import Handler.Profile
|
||||
|
||||
-- This line actually creates our YesodDispatch instance. It is the second half
|
||||
|
|
|
@ -150,7 +150,6 @@ instance Yesod App where
|
|||
|
||||
-- Routes not requiring authentication.
|
||||
isAuthorized (AuthR _) _ = return Authorized
|
||||
isAuthorized CommentR _ = return Authorized
|
||||
isAuthorized HomeR _ = return Authorized
|
||||
isAuthorized FaviconR _ = return Authorized
|
||||
isAuthorized RobotsR _ = return Authorized
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
module Handler.Comment where
|
||||
|
||||
import Import
|
||||
|
||||
postCommentR :: Handler Value
|
||||
postCommentR = do
|
||||
-- requireJsonBody will parse the request body into the appropriate type, or return a 400 status code if the request JSON is invalid.
|
||||
-- (The ToJSON and FromJSON instances are derived in the config/models file).
|
||||
comment <- (requireJsonBody :: Handler Comment)
|
||||
|
||||
-- The YesodAuth instance in Foundation.hs defines the UserId to be the type used for authentication.
|
||||
maybeCurrentUserId <- maybeAuthId
|
||||
let comment' = comment { commentUserId = maybeCurrentUserId }
|
||||
|
||||
insertedComment <- runDB $ insertEntity comment'
|
||||
returnJson insertedComment
|
|
@ -1,43 +0,0 @@
|
|||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Handler.CommentSpec (spec) where
|
||||
|
||||
import TestImport
|
||||
import Data.Aeson
|
||||
|
||||
spec :: Spec
|
||||
spec = withApp $ do
|
||||
describe "valid request" $ do
|
||||
it "gives a 200" $ do
|
||||
get HomeR
|
||||
statusIs 200
|
||||
|
||||
let message = "My message" :: Text
|
||||
body = object [ "message" .= message ]
|
||||
encoded = encode body
|
||||
|
||||
request $ do
|
||||
setMethod "POST"
|
||||
setUrl CommentR
|
||||
setRequestBody encoded
|
||||
addRequestHeader ("Content-Type", "application/json")
|
||||
|
||||
statusIs 200
|
||||
|
||||
[Entity _id comment] <- runDB $ selectList [CommentMessage ==. message] []
|
||||
assertEq "Should have " comment (Comment message Nothing)
|
||||
|
||||
describe "invalid requests" $ do
|
||||
it "400s when the JSON body is invalid" $ do
|
||||
get HomeR
|
||||
|
||||
let body = object [ "foo" .= ("My message" :: Value) ]
|
||||
|
||||
request $ do
|
||||
setMethod "POST"
|
||||
setUrl CommentR
|
||||
setRequestBody $ encode body
|
||||
addRequestHeader ("Content-Type", "application/json")
|
||||
|
||||
statusIs 400
|
||||
|
Loading…
Reference in a new issue