Skip to content

Commit

Permalink
Add overrides to use plural types
Browse files Browse the repository at this point in the history
There’s a feature in JaSerializer 0.13 to apply this globally
but when I tried to use it I was pulled into a cascading
problem with these issues:
phoenixframework/phoenix#3119
getsentry/sentry-elixir#275

I couldn’t figure that out so I’m manually overriding instead
for now.

This is all happening because Mirage uses plural types and
the overlaps-processing client-side code needed to check
for both, ugh.
  • Loading branch information
backspace committed Dec 9, 2018
1 parent 8969ad6 commit 97982d9
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/prison_rideshare_web/views/commitment_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule PrisonRideshareWeb.CommitmentView do
use PrisonRideshareWeb, :view
use JaSerializer.PhoenixView

def type(_, _), do: "commitments"

has_one(
:person,
type: "people",
Expand Down
2 changes: 1 addition & 1 deletion lib/prison_rideshare_web/views/overlap_commitment_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule PrisonRideshareWeb.OverlapCommitmentView do
use PrisonRideshareWeb, :view
use JaSerializer.PhoenixView

def type(_, _), do: "commitment"
def type(_, _), do: "commitments"

has_one(
:person,
Expand Down
4 changes: 2 additions & 2 deletions lib/prison_rideshare_web/views/overlap_ride_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ defmodule PrisonRideshareWeb.OverlapRideView do
use PrisonRideshareWeb, :view
use JaSerializer.PhoenixView

def type(_, _), do: "ride"
def type(_, _), do: "rides"

has_many(
:commitments,
type: "commitment",
type: "commitments",
include: true,
serializer: PrisonRideshareWeb.OverlapCommitmentView
)
Expand Down
2 changes: 2 additions & 0 deletions lib/prison_rideshare_web/views/person_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule PrisonRideshareWeb.PersonView do
use PrisonRideshareWeb, :view
use JaSerializer.PhoenixView

def type(_, _), do: "people"

attributes([
:name,
:email,
Expand Down
2 changes: 2 additions & 0 deletions lib/prison_rideshare_web/views/slot_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule PrisonRideshareWeb.SlotView do
use PrisonRideshareWeb, :view
use JaSerializer.PhoenixView

def type(_, _), do: "slots"

attributes([:start, :end, :count])

has_many(
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/debt_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ defmodule PrisonRideshareWeb.DebtControllerTest do
defp person_relationship_json(person) do
%{
"data" => %{
"type" => "person",
"type" => "people",
"id" => person.id
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/person_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule PrisonRideshareWeb.PersonControllerTest do
conn = get(conn, person_path(conn, :show, person))
data = json_response(conn, 200)["data"]
assert data["id"] == "#{person.id}"
assert data["type"] == "person"
assert data["type"] == "people"

attributes = data["attributes"]
assert attributes["name"] == person.name
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/ride_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ defmodule PrisonRideshareWeb.RideControllerTest do
},
"driver" => %{
"data" => %{
"type" => "person",
"type" => "people",
"id" => driver.id
}
},
"car-owner" => %{
"data" => %{
"type" => "person",
"type" => "people",
"id" => car_owner.id
}
},
Expand Down Expand Up @@ -446,13 +446,13 @@ defmodule PrisonRideshareWeb.RideControllerTest do
},
"driver" => %{
"data" => %{
"type" => "person",
"type" => "people",
"id" => driver.id
}
},
"car-owner" => %{
"data" => %{
"type" => "person",
"type" => "people",
"id" => car_owner.id
}
},
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/slot_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule PrisonRideshareWeb.SlotControllerTest do
assert json_response(conn, 200)["data"] == [
%{
"id" => later.id,
"type" => "slot",
"type" => "slots",
"attributes" => %{
"start" => "2117-12-10T13:00:00.000000Z",
"end" => "2117-12-10T17:00:00.000000Z",
Expand All @@ -34,7 +34,7 @@ defmodule PrisonRideshareWeb.SlotControllerTest do
},
%{
"id" => earlier.id,
"type" => "slot",
"type" => "slots",
"attributes" => %{
"start" => "2117-12-08T13:00:00.000000Z",
"end" => "2117-12-08T17:00:00.000000Z",
Expand All @@ -44,7 +44,7 @@ defmodule PrisonRideshareWeb.SlotControllerTest do
"commitments" => %{
"data" => [
%{
"type" => "commitment",
"type" => "commitments",
"id" => commitment.id
}
]
Expand Down

0 comments on commit 97982d9

Please sign in to comment.