From bcf555ea4cafc01ebce9382013f2c779c47a32f4 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 11 Nov 2024 12:41:56 +0000 Subject: [PATCH] Remove duplication in artists attributes fixture generation --- test/support/fixtures/records_fixtures.ex | 31 ++++++++--------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/test/support/fixtures/records_fixtures.ex b/test/support/fixtures/records_fixtures.ex index b6f8afca..bc7576c1 100644 --- a/test/support/fixtures/records_fixtures.ex +++ b/test/support/fixtures/records_fixtures.ex @@ -52,15 +52,6 @@ defmodule MusicLibrary.RecordsFixtures do artist_name = Enum.random(@artists) current_time = DateTime.utc_now() - artists_attrs = [ - %{ - name: artist_name, - musicbrainz_id: artist_uuid(artist_name), - sort_name: artist_name, - disambiguation: artist_name - } - ] - {:ok, record} = attrs |> Enum.into(%{ @@ -73,7 +64,7 @@ defmodule MusicLibrary.RecordsFixtures do format: Record.formats() |> Enum.random(), release: Enum.random(1969..2024) |> Integer.to_string(), purchased_at: current_time, - artists: artists_attrs + artists: [artist_attrs(artist_name)] }) |> MusicLibrary.Records.create_record() @@ -81,20 +72,20 @@ defmodule MusicLibrary.RecordsFixtures do end def record_fixture_with_artist(artist_name, record_attrs \\ %{}) do - artists_attrs = [ - %{ - name: artist_name, - musicbrainz_id: artist_uuid(artist_name), - sort_name: artist_name, - disambiguation: artist_name - } - ] - record_attrs - |> Map.put(:artists, artists_attrs) + |> Map.put(:artists, [artist_attrs(artist_name)]) |> record_fixture() end + defp artist_attrs(name) do + %{ + name: name, + musicbrainz_id: artist_uuid(name), + sort_name: name, + disambiguation: name + } + end + # The following functions have been lifted from `Ecto.UUID`'s source. # The purpose is to provide a deterministic implementation of uuid generation # that can be used in tests to generate the same artist uuid.