Display latest purchase in stats page
This commit is contained in:
@@ -99,7 +99,7 @@ defmodule MusicLibrary.Records do
|
||||
def get_latest_record! do
|
||||
q =
|
||||
from r in Record,
|
||||
order_by: [desc: r.inserted_at],
|
||||
order_by: [desc: r.purchased_at],
|
||||
limit: 1,
|
||||
select: ^@fields
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ defmodule MusicLibraryWeb.StatsControllerTest do
|
||||
end
|
||||
|
||||
test "it shows the latest record", %{conn: conn, records: records} do
|
||||
latest_record = Enum.max_by(records, & &1.inserted_at)
|
||||
latest_record = Enum.max_by(records, & &1.purchased_at)
|
||||
|
||||
conn = get(conn, "/")
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ defmodule MusicLibrary.RecordsFixtures do
|
||||
def record_fixture(attrs \\ %{}) do
|
||||
record_musicbrainz_id = Ecto.UUID.generate()
|
||||
artist_name = Enum.random(@artists)
|
||||
current_time = DateTime.utc_now()
|
||||
|
||||
artists_attrs = [
|
||||
%{
|
||||
@@ -71,6 +72,7 @@ defmodule MusicLibrary.RecordsFixtures do
|
||||
type: :album,
|
||||
format: Record.formats() |> Enum.random(),
|
||||
release: Enum.random(1969..2024) |> Integer.to_string(),
|
||||
purchased_at: current_time,
|
||||
artists: artists_attrs
|
||||
})
|
||||
|> MusicLibrary.Records.create_record()
|
||||
|
||||
Reference in New Issue
Block a user