+3
-1
@@ -75,7 +75,9 @@ app conn req respond = do
|
|||||||
jsonBodyAction req (\row -> do
|
jsonBodyAction req (\row -> do
|
||||||
allvals <- insert ver table row conn
|
allvals <- insert ver table row conn
|
||||||
keys <- primaryKeyColumns ver (unpack table) conn
|
keys <- primaryKeyColumns ver (unpack table) conn
|
||||||
let keyvals = allvals `intersection` fromList (zip keys $ repeat SqlNull)
|
let keyvals = if null keys
|
||||||
|
then allvals
|
||||||
|
else allvals `intersection` fromList (zip keys $ repeat SqlNull)
|
||||||
let params = urlEncodeVars $ map (\t -> (fst t, "eq." <> convert (snd t) :: String)) $ toList keyvals
|
let params = urlEncodeVars $ map (\t -> (fst t, "eq." <> convert (snd t) :: String)) $ toList keyvals
|
||||||
return $ responseLBS status201
|
return $ responseLBS status201
|
||||||
[ jsonContentType
|
[ jsonContentType
|
||||||
|
|||||||
@@ -50,6 +50,14 @@ spec = around appWithFixture $
|
|||||||
post "/simple_pk" [json| { "extra":"foo"} |]
|
post "/simple_pk" [json| { "extra":"foo"} |]
|
||||||
`shouldRespondWith` 400
|
`shouldRespondWith` 400
|
||||||
|
|
||||||
|
context "into a table with no pk" $
|
||||||
|
it "succeeds with 201 and a link including all fields" $ do
|
||||||
|
p <- post "/no_pk" [json| { "a":"foo", "b":"bar" } |]
|
||||||
|
liftIO $ do
|
||||||
|
simpleBody p `shouldBe` ""
|
||||||
|
simpleHeaders p `shouldSatisfy` matchHeader hLocation "/no_pk\\?a=eq.foo&b=eq.bar"
|
||||||
|
simpleStatus p `shouldBe` created201
|
||||||
|
|
||||||
context "with compound pk supplied" $
|
context "with compound pk supplied" $
|
||||||
it "builds response location header appropriately" $
|
it "builds response location header appropriately" $
|
||||||
post "/compound_pk" [json| { "k1":12, "k2":42 } |]
|
post "/compound_pk" [json| { "k1":12, "k2":42 } |]
|
||||||
|
|||||||
Reference in New Issue
Block a user