diff --git a/lib/radiator/podcasts.ex b/lib/radiator/podcasts.ex index 5c8f3f88..a965f53c 100644 --- a/lib/radiator/podcasts.ex +++ b/lib/radiator/podcasts.ex @@ -1,6 +1,7 @@ defmodule Radiator.Podcasts do @moduledoc """ The Podcast context. + Handles repo operations for stations, episodes, and podcasts. """ import Ecto.Query, warn: false diff --git a/lib/radiator/podcasts/episode.ex b/lib/radiator/podcasts/episode.ex index 94bb8da8..baf3aa07 100644 --- a/lib/radiator/podcasts/episode.ex +++ b/lib/radiator/podcasts/episode.ex @@ -13,6 +13,6 @@ defmodule Radiator.Podcasts.Episode do def changeset(episode, attrs) do episode |> cast(attrs, [:title]) - |> validate_required([:title]) + |> validate_required([:title, :podcast_id]) end end diff --git a/test/radiator/podcast_test.exs b/test/radiator/podcast_test.exs deleted file mode 100644 index cd0f05bd..00000000 --- a/test/radiator/podcast_test.exs +++ /dev/null @@ -1,59 +0,0 @@ -defmodule Radiator.PodcastTest do - use Radiator.DataCase - - alias Radiator.Podcasts - - describe "stations" do - alias Radiator.Podcasts.Station - - import Radiator.PodcastFixtures - - @invalid_attrs %{title: nil} - - test "list_stations/0 returns all stations" do - station = station_fixture() - assert Podcasts.list_stations() == [station] - end - - test "get_station!/1 returns the station with given id" do - station = station_fixture() - assert Podcasts.get_station!(station.id) == station - end - - test "create_station/1 with valid data creates a station" do - valid_attrs = %{title: "some title"} - - assert {:ok, %Station{} = station} = Podcasts.create_station(valid_attrs) - assert station.title == "some title" - end - - test "create_station/1 with invalid data returns error changeset" do - assert {:error, %Ecto.Changeset{}} = Podcasts.create_station(@invalid_attrs) - end - - test "update_station/2 with valid data updates the station" do - station = station_fixture() - update_attrs = %{title: "some updated title"} - - assert {:ok, %Station{} = station} = Podcasts.update_station(station, update_attrs) - assert station.title == "some updated title" - end - - test "update_station/2 with invalid data returns error changeset" do - station = station_fixture() - assert {:error, %Ecto.Changeset{}} = Podcasts.update_station(station, @invalid_attrs) - assert station == Podcasts.get_station!(station.id) - end - - test "delete_station/1 deletes the station" do - station = station_fixture() - assert {:ok, %Station{}} = Podcasts.delete_station(station) - assert_raise Ecto.NoResultsError, fn -> Podcasts.get_station!(station.id) end - end - - test "change_station/1 returns a station changeset" do - station = station_fixture() - assert %Ecto.Changeset{} = Podcasts.change_station(station) - end - end -end diff --git a/test/radiator/podcasts_test.exs b/test/radiator/podcasts_test.exs index d040d671..35f08453 100644 --- a/test/radiator/podcasts_test.exs +++ b/test/radiator/podcasts_test.exs @@ -2,6 +2,59 @@ defmodule Radiator.PodcastsTest do use Radiator.DataCase alias Radiator.Podcasts + import Radiator.PodcastsFixtures + + describe "stations" do + alias Radiator.Podcasts.Station + + @invalid_attrs %{title: nil} + + test "list_stations/0 returns all stations" do + station = station_fixture() + assert Podcasts.list_stations() == [station] + end + + test "get_station!/1 returns the station with given id" do + station = station_fixture() + assert Podcasts.get_station!(station.id) == station + end + + test "create_station/1 with valid data creates a station" do + valid_attrs = %{title: "some title"} + + assert {:ok, %Station{} = station} = Podcasts.create_station(valid_attrs) + assert station.title == "some title" + end + + test "create_station/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Podcasts.create_station(@invalid_attrs) + end + + test "update_station/2 with valid data updates the station" do + station = station_fixture() + update_attrs = %{title: "some updated title"} + + assert {:ok, %Station{} = station} = Podcasts.update_station(station, update_attrs) + assert station.title == "some updated title" + end + + test "update_station/2 with invalid data returns error changeset" do + station = station_fixture() + assert {:error, %Ecto.Changeset{}} = Podcasts.update_station(station, @invalid_attrs) + assert station == Podcasts.get_station!(station.id) + end + + test "delete_station/1 deletes the station" do + station = station_fixture() + assert {:ok, %Station{}} = Podcasts.delete_station(station) + assert_raise Ecto.NoResultsError, fn -> Podcasts.get_station!(station.id) end + end + + test "change_station/1 returns a station changeset" do + station = station_fixture() + assert %Ecto.Changeset{} = Podcasts.change_station(station) + end + end describe "podcasts" do alias Radiator.Podcasts.Podcast diff --git a/test/support/fixtures/podcast_fixtures.ex b/test/support/fixtures/podcast_fixtures.ex deleted file mode 100644 index e1a19992..00000000 --- a/test/support/fixtures/podcast_fixtures.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule Radiator.PodcastFixtures do - @moduledoc """ - This module defines test helpers for creating - entities via the `Radiator.Podcast` context. - """ - - @doc """ - Generate a station. - """ - def station_fixture(attrs \\ %{}) do - {:ok, station} = - attrs - |> Enum.into(%{ - title: "some title" - }) - |> Radiator.Podcasts.create_station() - - station - end -end diff --git a/test/support/fixtures/podcasts_fixtures.ex b/test/support/fixtures/podcasts_fixtures.ex index 857aa13e..70b78b53 100644 --- a/test/support/fixtures/podcasts_fixtures.ex +++ b/test/support/fixtures/podcasts_fixtures.ex @@ -3,18 +3,35 @@ defmodule Radiator.PodcastsFixtures do This module defines test helpers for creating entities via the `Radiator.Podcasts` context. """ + alias Radiator.Podcasts + + @doc """ + Generate a station. + """ + def station_fixture(attrs \\ %{}) do + {:ok, station} = + attrs + |> Enum.into(%{ + title: "metastation" + }) + |> Podcasts.create_station() + + station + end @doc """ Generate a podcast. """ def podcast_fixture(attrs \\ %{}) do + station = station_fixture() + {:ok, podcast} = attrs |> Enum.into(%{ hostname: "some hostname", title: "some title" }) - |> Radiator.Podcasts.create_podcast() + |> Podcasts.create_podcast() podcast end @@ -28,7 +45,7 @@ defmodule Radiator.PodcastsFixtures do |> Enum.into(%{ title: "some title" }) - |> Radiator.Podcasts.create_episode() + |> Podcasts.create_episode() episode end