Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate Plug Locations #146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doomspork FYI added a test for this plug too, it was missing one.

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