Skip to content

Commit

Permalink
WIP 3 renaming of base resources
Browse files Browse the repository at this point in the history
New hierarchy:

Podcast.Network (e.g. Metaebene or ARD or BBC)
Podcast.Show (e.g. Freakshow or Minkorrekt)
Podcast.Episode (e.g. FR123 or Mi014)
  • Loading branch information
electronicbites committed Dec 16, 2023
1 parent b0d5269 commit 555b2a0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 53 deletions.
38 changes: 17 additions & 21 deletions lib/radiator/podcast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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

Expand All @@ -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.
Expand Down
55 changes: 28 additions & 27 deletions test/radiator/podcasts_test.exs → test/radiator/podcast_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ defmodule Radiator.PodcastFixtures do
|> Enum.into(%{
title: "metanetwork"
})
|> Podcasts.create_network()
|> Podcast.create_network()

network
end

@doc """
Generate a show.
"""
def podcast_fixture(attrs \\ %{}) do
def show_fixture(attrs \\ %{}) do
network = network_fixture()

{:ok, show} =
Expand All @@ -32,7 +32,7 @@ defmodule Radiator.PodcastFixtures do
title: "some title",
network: network
})
|> Podcasts.create_podcast()
|> Podcast.create_show()

show
end
Expand All @@ -41,15 +41,15 @@ defmodule Radiator.PodcastFixtures do
Generate a episode.
"""
def episode_fixture(attrs \\ %{}) do
show = podcast_fixture()
show = show_fixture()

{:ok, episode} =
attrs
|> Enum.into(%{
title: "my show episode 23",
show_id: show.id
})
|> Podcasts.create_episode()
|> Podcast.create_episode()

episode
end
Expand Down

0 comments on commit 555b2a0

Please sign in to comment.