Merge pull request #65 from begriffs/put-status-code

Successful PUT requests actually return 200
This commit is contained in:
Joe Nelson
2014-10-10 11:50:15 -07:00
2 changed files with 20 additions and 11 deletions
+3 -8
View File
@@ -149,15 +149,10 @@ appWithRole conn req respond =
cols <- columns ver (cs table) conn
let colNames = S.fromList $ map (cs . colName) cols
let specifiedCols = S.fromList $ map fst $ getRow row
if colNames == specifiedCols then do
allvals <- upsert ver table row qq conn
let params = urlEncodeVars $ map (\t -> (fst t, "eq." <> convert (snd t) :: String)) $ toList $ filterByKeys allvals keys
return $ responseLBS status201
[ jsonContentType
, (hLocation, "/" <> cs table <> "?" <> cs params)
] ""
return $ if colNames == specifiedCols then
responseLBS status200 [ jsonContentType ] ""
else return $ if S.null colNames then responseLBS status404 [] ""
else if S.null colNames then responseLBS status404 [] ""
else responseLBS status400 []
"You must specify all columns in PUT request"
)
+17 -3
View File
@@ -105,6 +105,20 @@ spec = around appWithFixture $ do
[json| { "k1":12, "k2":42, "extra":3 } |]
liftIO $ do
simpleBody p `shouldBe` ""
simpleStatus p `shouldBe` created201
simpleHeaders p `shouldSatisfy` matchHeader
hLocation "/compound_pk\\?k1=eq\\.12&k2=eq\\.42"
simpleStatus p `shouldBe` status200
context "with an auto-incrementing primary key" $
it "succeeds with 201 and link" $
request methodPut "/auto_incrementing_pk?id=eq.1" []
[json| {
"id":1,
"nullable_string":"hi",
"non_nullable_string":"bye",
"inserted_at": "now()"
} |]
`shouldRespondWith` ResponseMatcher {
matchBody = Nothing,
matchStatus = 200,
matchHeaders = []
}