Skip to content

Commit ae6cf8f

Browse files
snewcomerjoshsmith
authored andcommitted
Sort GithubEvent list by inserted_at close #1172
1 parent 890f24b commit ae6cf8f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/code_corps_web/controllers/github_event_controller.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ defmodule CodeCorpsWeb.GithubEventController do
1919
github_events =
2020
GithubEvent
2121
|> Query.id_filter(params)
22+
|> Ecto.Query.order_by([asc: :inserted_at])
2223
|> paginate(params)
2324

2425
conn |> render("index.json-api", data: github_events)

test/lib/code_corps_web/controllers/github_event_controller_test.exs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ defmodule CodeCorpsWeb.GithubEventControllerTest do
2828
end
2929

3030
@tag authenticated: :admin
31-
test "lists all entries on index", %{conn: conn} do
32-
[github_event_1, github_event_2] = insert_pair(:github_event)
31+
test "lists all entries on index by inserted_at", %{conn: conn} do
32+
github_event_1 = insert(:github_event, inserted_at: Timex.now())
33+
github_event_2 = insert(:github_event, inserted_at: Timex.now() |> Timex.shift(days: 3))
3334

34-
conn
35+
data =
36+
conn
3537
|> request_index
3638
|> json_response(200)
37-
|> assert_ids_from_response([github_event_1.id, github_event_2.id])
39+
|> Map.get("data")
40+
41+
[first_event, second_event] = data
42+
assert first_event["id"] == github_event_1.id |> Integer.to_string
43+
assert second_event["id"] == github_event_2.id |> Integer.to_string
3844
end
3945

4046
@tag authenticated: :admin

0 commit comments

Comments
 (0)