Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added improvements to post accept hash dict

  • Loading branch information...
commit 369ddaf3f2a718483b7ba424009cc52ae5e07daf 1 parent 6124106
@thiagofm thiagofm authored
Showing with 13 additions and 2 deletions.
  1. +8 −2 lib/dynamo/http/case.ex
  2. +5 −0 test/dynamo/http/case_test.exs
View
10 lib/dynamo/http/case.ex
@@ -108,14 +108,20 @@ defmodule Dynamo.HTTP.Case do
end
@doc """
- Does a POST request to the given path:
+ Does a POST request to the given path and optionally body:
post("/foo")
post(conn, "/foo")
+ post(conn, "/foo", "test body") # POSTs to `/foo` with `test body` body
+ post(conn, "/foo", [{"foo", "bar"}]) # POSTs to `/foo` with `foo=bar` body
"""
defmacro post(arg1, arg2 // nil) do
- do_method :POST, arg1, arg2
+ if is_list(arg2) do
+ do_method :POST, arg1, URI.encode_query(arg2)
+ else
+ do_method :POST, arg1, arg2
+ end
end
@doc """
View
5 test/dynamo/http/case_test.exs
@@ -47,4 +47,9 @@ defmodule Dynamo.HTTP.CaseTest do
conn = post("/test_post", "test body")
assert conn.sent_body == "test body"
end
+
+ test "sees the request body from a post with HashDict" do
+ conn = post("/test_post", [{"foo", "bar"}, {"bar", "foo"}])
+ assert conn.sent_body == "foo=bar&bar=foo"
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.