Skip to content

Commit

Permalink
Consolidate Plug Locations (#146)
Browse files Browse the repository at this point in the history
Move these two plugs with their other friends.

Note that this commit introduces a backwards incompatible change: it
renames the `PlugResponseContentType` to `ResponseContentType`.
  • Loading branch information
jherdman authored and doomspork committed Dec 24, 2018
1 parent 0c79609 commit 86f75ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule JSONAPI.PlugResponseContentType do
defmodule JSONAPI.ResponseContentType do
@moduledoc """
Simply add this plug to your endpoint or your router :api pipeline and it will
ensure you return the correct response type.
Expand Down
27 changes: 27 additions & 0 deletions test/jsonapi/plugs/response_content_type_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule JSONAPI.ResponseContentTypeTest do
use ExUnit.Case
use Plug.Test

alias JSONAPI.ResponseContentType

test "sets response content type" do
conn =
:get
|> conn("/example", "")
|> ResponseContentType.call([])
|> send_resp(200, "done")

assert get_resp_header(conn, "content-type") == ["application/vnd.api+json; charset=utf-8"]
end

test "can be overridden when in play" do
conn =
:get
|> conn("/example", "")
|> Plug.Conn.assign(:override_jsonapi, true)
|> ResponseContentType.call([])
|> send_resp(200, "done")

refute get_resp_header(conn, "content-type") == ["application/vnd.api+json; charset=utf-8"]
end
end

0 comments on commit 86f75ef

Please sign in to comment.