diff --git a/src/Dbapi.hs b/src/Dbapi.hs index d7b6d8922..9ce15f69a 100644 --- a/src/Dbapi.hs +++ b/src/Dbapi.hs @@ -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" ) diff --git a/test/Feature/InsertSpec.hs b/test/Feature/InsertSpec.hs index a13643a8a..34b945177 100644 --- a/test/Feature/InsertSpec.hs +++ b/test/Feature/InsertSpec.hs @@ -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 = [] + }