diff --git a/lib/radiator/podcast.ex b/lib/radiator/podcast.ex index e55daffa..785030cc 100644 --- a/lib/radiator/podcast.ex +++ b/lib/radiator/podcast.ex @@ -7,7 +7,7 @@ defmodule Radiator.Podcast do import Ecto.Query, warn: false alias Radiator.Repo - alias Radiator.Podcast.Network + alias Radiator.Podcast.{ Episode, Network, Show} @doc """ Returns the list of networks. @@ -103,18 +103,16 @@ defmodule Radiator.Podcast do Network.changeset(network, attrs) end - alias Radiator.Podcast.Show - @doc """ Returns the list of shows. ## Examples - iex> list_podcasts() + iex> list_shows() [%Show{}, ...] """ - def list_podcasts do + def list_shows do Repo.all(Show) end @@ -125,28 +123,28 @@ defmodule Radiator.Podcast do ## Examples - iex> get_podcast!(123) + iex> get_show!(123) %Show{} - iex> get_podcast!(456) + iex> get_show!(456) ** (Ecto.NoResultsError) """ - def get_podcast!(id), do: Repo.get!(Show, id) + def get_show!(id), do: Repo.get!(Show, id) @doc """ Creates a show. ## Examples - iex> create_podcast(%{field: value}) + iex> create_show(%{field: value}) {:ok, %Show{}} - iex> create_podcast(%{field: bad_value}) + iex> create_show(%{field: bad_value}) {:error, %Ecto.Changeset{}} """ - def create_podcast(attrs \\ %{}) do + def create_show(attrs \\ %{}) do %Show{} |> Show.changeset(attrs) |> Repo.insert() @@ -157,14 +155,14 @@ defmodule Radiator.Podcast do ## Examples - iex> update_podcast(show, %{field: new_value}) + iex> update_show(show, %{field: new_value}) {:ok, %Show{}} - iex> update_podcast(show, %{field: bad_value}) + iex> update_show(show, %{field: bad_value}) {:error, %Ecto.Changeset{}} """ - def update_podcast(%Show{} = show, attrs) do + def update_show(%Show{} = show, attrs) do show |> Show.changeset(attrs) |> Repo.update() @@ -175,14 +173,14 @@ defmodule Radiator.Podcast do ## Examples - iex> delete_podcast(show) + iex> delete_show(show) {:ok, %Show{}} - iex> delete_podcast(show) + iex> delete_show(show) {:error, %Ecto.Changeset{}} """ - def delete_podcast(%Show{} = show) do + def delete_show(%Show{} = show) do Repo.delete(show) end @@ -191,16 +189,14 @@ defmodule Radiator.Podcast do ## Examples - iex> change_podcast(show) + iex> change_show(show) %Ecto.Changeset{data: %Show{}} """ - def change_podcast(%Show{} = show, attrs \\ %{}) do + def change_show(%Show{} = show, attrs \\ %{}) do Show.changeset(show, attrs) end - alias Radiator.Podcast.Episode - @doc """ Returns the list of episodes. diff --git a/test/radiator/podcasts_test.exs b/test/radiator/podcast_test.exs similarity index 75% rename from test/radiator/podcasts_test.exs rename to test/radiator/podcast_test.exs index 3cbbf8f9..831ce720 100644 --- a/test/radiator/podcasts_test.exs +++ b/test/radiator/podcast_test.exs @@ -2,10 +2,11 @@ defmodule Radiator.PodcastTest do use Radiator.DataCase alias Radiator.Podcast + alias Radiator.Podcast.Network + import Radiator.PodcastFixtures describe "networks" do - alias Radiator.Podcast.Network @invalid_attrs %{title: nil} @@ -63,54 +64,54 @@ defmodule Radiator.PodcastTest do @invalid_attrs %{title: nil, hostname: nil} - test "list_podcasts/0 returns all shows" do - show = podcast_fixture() - assert Shows.list_podcasts() == [show] + test "list_shows/0 returns all shows" do + show = show_fixture() + assert Shows.list_shows() == [show] end - test "get_podcast!/1 returns the show with given id" do - show = podcast_fixture() - assert Shows.get_podcast!(show.id) == show + test "get_show!/1 returns the show with given id" do + show = show_fixture() + assert Shows.get_show!(show.id) == show end - test "create_podcast/1 with valid data creates a show" do + test "create_show/1 with valid data creates a show" do network = network_fixture() valid_attrs = %{title: "some title", network_id: network.id} - assert {:ok, %Show{} = show} = Shows.create_podcast(valid_attrs) + assert {:ok, %Show{} = show} = Shows.create_show(valid_attrs) assert show.title == "some title" assert show.network_id == network.id end - test "create_podcast/1 with invalid data returns error changeset" do - assert {:error, %Ecto.Changeset{}} = Shows.create_podcast(@invalid_attrs) + test "create_show/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Shows.create_show(@invalid_attrs) end - test "update_podcast/2 with valid data updates the show" do - show = podcast_fixture() + test "update_show/2 with valid data updates the show" do + show = show_fixture() updated_network = network_fixture() update_attrs = %{title: "some updated title", network_id: updated_network.id} - assert {:ok, %Show{} = show} = Shows.update_podcast(show, update_attrs) + assert {:ok, %Show{} = show} = Shows.update_show(show, update_attrs) assert show.title == "some updated title" assert show.network_id == updated_network.id end - test "update_podcast/2 with invalid data returns error changeset" do - show = podcast_fixture() - assert {:error, %Ecto.Changeset{}} = Shows.update_podcast(show, @invalid_attrs) - assert show == Shows.get_podcast!(show.id) + test "update_show/2 with invalid data returns error changeset" do + show = show_fixture() + assert {:error, %Ecto.Changeset{}} = Shows.update_show(show, @invalid_attrs) + assert show == Shows.get_show!(show.id) end - test "delete_podcast/1 deletes the show" do - show = podcast_fixture() - assert {:ok, %Show{}} = Shows.delete_podcast(show) - assert_raise Ecto.NoResultsError, fn -> Shows.get_podcast!(show.id) end + test "delete_show/1 deletes the show" do + show = show_fixture() + assert {:ok, %Show{}} = Shows.delete_show(show) + assert_raise Ecto.NoResultsError, fn -> Shows.get_show!(show.id) end end - test "change_podcast/1 returns a show changeset" do - show = podcast_fixture() - assert %Ecto.Changeset{} = Shows.change_podcast(show) + test "change_show/1 returns a show changeset" do + show = show_fixture() + assert %Ecto.Changeset{} = Shows.change_show(show) end end @@ -132,7 +133,7 @@ defmodule Radiator.PodcastTest do end test "create_episode/1 with valid data creates a episode" do - show = podcast_fixture() + show = show_fixture() valid_attrs = %{title: "some title", show_id: show.id} assert {:ok, %Episode{} = episode} = Shows.create_episode(valid_attrs) @@ -146,7 +147,7 @@ defmodule Radiator.PodcastTest do test "update_episode/2 with valid data updates the episode" do episode = episode_fixture() - updated_podcast = podcast_fixture() + updated_podcast = show_fixture() update_attrs = %{title: "some updated title", show_id: updated_podcast.id} assert {:ok, %Episode{} = episode} = Shows.update_episode(episode, update_attrs) diff --git a/test/support/fixtures/podcasts_fixtures.ex b/test/support/fixtures/podcast_fixtures.ex similarity index 82% rename from test/support/fixtures/podcasts_fixtures.ex rename to test/support/fixtures/podcast_fixtures.ex index 91a57a26..85ab8f0b 100644 --- a/test/support/fixtures/podcasts_fixtures.ex +++ b/test/support/fixtures/podcast_fixtures.ex @@ -14,7 +14,7 @@ defmodule Radiator.PodcastFixtures do |> Enum.into(%{ title: "metanetwork" }) - |> Podcasts.create_network() + |> Podcast.create_network() network end @@ -22,7 +22,7 @@ defmodule Radiator.PodcastFixtures do @doc """ Generate a show. """ - def podcast_fixture(attrs \\ %{}) do + def show_fixture(attrs \\ %{}) do network = network_fixture() {:ok, show} = @@ -32,7 +32,7 @@ defmodule Radiator.PodcastFixtures do title: "some title", network: network }) - |> Podcasts.create_podcast() + |> Podcast.create_show() show end @@ -41,7 +41,7 @@ defmodule Radiator.PodcastFixtures do Generate a episode. """ def episode_fixture(attrs \\ %{}) do - show = podcast_fixture() + show = show_fixture() {:ok, episode} = attrs @@ -49,7 +49,7 @@ defmodule Radiator.PodcastFixtures do title: "my show episode 23", show_id: show.id }) - |> Podcasts.create_episode() + |> Podcast.create_episode() episode end