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

updates plug to allow data with only relationships #93

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
1 change: 1 addition & 0 deletions lib/jsonapi/plugs/format_required.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule JSONAPI.FormatRequired do
def init(opts), do: opts

def call(%{method: method} = conn, _opts) when method in ["DELETE", "GET", "HEAD"], do: conn
def call(%{params: %{"data" => %{"relationships" => _}}} = conn, _), do: conn
def call(%{params: %{"data" => %{"attributes" => _}}} = conn, _), do: conn
def call(%{params: %{"data" => _}} = conn, _), do: send_error(conn, missing_data_attributes_param())
def call(conn, _), do: send_error(conn, missing_data_param())
Expand Down
9 changes: 9 additions & 0 deletions test/jsonapi/plugs/format_required_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ defmodule JSONAPI.FormatRequiredTest do
assert %{"source" => %{"pointer" => "/data/attributes"}, "title" => "Missing attributes in data parameter"} = error
end

test "does not halt if only relationships member is present" do
conn =
:post
|> conn("/example", Poison.encode!(%{data: %{relationships: %{}}}))
|> call_plug

refute conn.halted
end

test "passes request through" do
conn =
:post
Expand Down