Include artists in record test fixture
This commit is contained in:
@@ -41,7 +41,7 @@ defmodule MusicLibraryWeb.StatsControllerTest do
|
|||||||
assert html_response(conn, 200) =~ escape(latest_record.title)
|
assert html_response(conn, 200) =~ escape(latest_record.title)
|
||||||
|
|
||||||
for artist <- latest_record.artists do
|
for artist <- latest_record.artists do
|
||||||
assert html_response(conn, 200) =~ escape(artist["name"])
|
assert html_response(conn, 200) =~ escape(artist.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ defmodule MusicLibraryWeb.RecordIndexTest do
|
|||||||
assert record_row_html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
assert record_row_html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
||||||
|
|
||||||
for artist <- record.artists do
|
for artist <- record.artists do
|
||||||
assert record_row_html =~ escape(artist["name"])
|
assert record_row_html =~ escape(artist.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ defmodule MusicLibraryWeb.RecordShowTest do
|
|||||||
assert html =~ Phoenix.HTML.Safe.to_iodata(record.updated_at)
|
assert html =~ Phoenix.HTML.Safe.to_iodata(record.updated_at)
|
||||||
|
|
||||||
for artist <- record.artists do
|
for artist <- record.artists do
|
||||||
assert html =~ escape(artist["name"])
|
assert html =~ escape(artist.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,7 +28,17 @@ defmodule MusicLibrary.RecordsFixtures do
|
|||||||
"Red",
|
"Red",
|
||||||
"Foxtrot",
|
"Foxtrot",
|
||||||
"The Lamb Lies Down on Broadway",
|
"The Lamb Lies Down on Broadway",
|
||||||
"Thick as a Brick"
|
"Thick as a Brick",
|
||||||
|
"Marbles",
|
||||||
|
"Vigil in a Wilderness of Mirrors"
|
||||||
|
]
|
||||||
|
@artists [
|
||||||
|
"Steven Wilson",
|
||||||
|
"King Crimson",
|
||||||
|
"Pink Floyd",
|
||||||
|
"Genesis",
|
||||||
|
"Marillion",
|
||||||
|
"Fish"
|
||||||
]
|
]
|
||||||
# While it would be great to have this random, it's ok to use one single image
|
# While it would be great to have this random, it's ok to use one single image
|
||||||
@marbles_cover_data_path "#{__DIR__}/marillion-marbles.jpg"
|
@marbles_cover_data_path "#{__DIR__}/marillion-marbles.jpg"
|
||||||
@@ -38,19 +48,30 @@ defmodule MusicLibrary.RecordsFixtures do
|
|||||||
def raven_cover_fixture, do: @raven_cover_data_path
|
def raven_cover_fixture, do: @raven_cover_data_path
|
||||||
|
|
||||||
def record_fixture(attrs \\ %{}) do
|
def record_fixture(attrs \\ %{}) do
|
||||||
musicbrainz_id = Ecto.UUID.generate()
|
record_musicbrainz_id = Ecto.UUID.generate()
|
||||||
|
artist_name = Enum.random(@artists)
|
||||||
|
|
||||||
|
artists_attrs = [
|
||||||
|
%{
|
||||||
|
name: artist_name,
|
||||||
|
musicbrainz_id: Ecto.UUID.generate(),
|
||||||
|
sort_name: artist_name,
|
||||||
|
disambiguation: artist_name
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
{:ok, record} =
|
{:ok, record} =
|
||||||
attrs
|
attrs
|
||||||
|> Enum.into(%{
|
|> Enum.into(%{
|
||||||
genres: Enum.take_random(@genres, :rand.uniform(3)),
|
genres: Enum.take_random(@genres, :rand.uniform(3)),
|
||||||
cover_url: "https://coverartarchive.org/release-group/#{musicbrainz_id}/front",
|
cover_url: "https://coverartarchive.org/release-group/#{record_musicbrainz_id}/front",
|
||||||
cover_data: File.read!(@marbles_cover_data_path),
|
cover_data: File.read!(@marbles_cover_data_path),
|
||||||
musicbrainz_id: musicbrainz_id,
|
musicbrainz_id: record_musicbrainz_id,
|
||||||
title: Enum.random(@titles),
|
title: Enum.random(@titles),
|
||||||
type: :album,
|
type: :album,
|
||||||
format: Record.formats() |> Enum.random(),
|
format: Record.formats() |> Enum.random(),
|
||||||
release: Enum.random(1969..2024) |> Integer.to_string()
|
release: Enum.random(1969..2024) |> Integer.to_string(),
|
||||||
|
artists: artists_attrs
|
||||||
})
|
})
|
||||||
|> MusicLibrary.Records.create_record()
|
|> MusicLibrary.Records.create_record()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user