Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix post with body in tests + improvements #174

Merged
merged 3 commits into from

3 participants

@thiagofm

Includes #168

chrismcg and others added some commits
@chrismcg chrismcg Make post(path, body) work in tests
Not entirely happy with the solution as it could be tricky to notice the
args have changed order in the future but the is_binary test helps with
that
31ab8e3
@thiagofm thiagofm Merge branch 'master' of github.com:dynamo/dynamo into fix_post_with_…
…body_in_tests
6124106
@thiagofm thiagofm Added improvements to post accept hash dict 369ddaf
@devinus devinus merged commit 117d522 into from
@chatgris chatgris referenced this pull request
Closed

Can not fetch req_body #167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 8, 2013
  1. @chrismcg

    Make post(path, body) work in tests

    chrismcg authored
    Not entirely happy with the solution as it could be tricky to notice the
    args have changed order in the future but the is_binary test helps with
    that
Commits on Dec 24, 2013
  1. @thiagofm
  2. @thiagofm
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 2 deletions.
  1. +12 −2 lib/dynamo/http/case.ex
  2. +15 −0 test/dynamo/http/case_test.exs
View
14 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 """
@@ -208,6 +214,10 @@ defmodule Dynamo.HTTP.Case do
do_process endpoint, Dynamo.Connection.Test.new(method, path)
end
+ def process(endpoint, path, method, body) when is_binary(path) do
+ do_process endpoint, conn(method, path, body)
+ end
+
defp do_process(endpoint, conn) do
conn = endpoint.service(conn)
View
15 test/dynamo/http/case_test.exs
@@ -15,6 +15,11 @@ defmodule Dynamo.HTTP.CaseTest do
get "/get_session" do
conn.send(200, get_session(conn, :hello))
end
+
+ post "/test_post" do
+ conn = conn.fetch :body
+ conn.send 200, conn.req_body
+ end
end
use ExUnit.Case
@@ -37,4 +42,14 @@ defmodule Dynamo.HTTP.CaseTest do
conn = get(conn, "/get_session")
assert conn.sent_body == "world"
end
+
+ test "sees the request body from a post" 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
Something went wrong with that request. Please try again.