Skip to content

Commit

Permalink
cleanup, unify
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Dec 5, 2023
1 parent 6c83aac commit 2357144
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 82 deletions.
1 change: 1 addition & 0 deletions lib/radiator/podcasts.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/radiator/podcasts/episode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 0 additions & 59 deletions test/radiator/podcast_test.exs

This file was deleted.

53 changes: 53 additions & 0 deletions test/radiator/podcasts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions test/support/fixtures/podcast_fixtures.ex

This file was deleted.

21 changes: 19 additions & 2 deletions test/support/fixtures/podcasts_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check warning on line 26 in test/support/fixtures/podcasts_fixtures.ex

View workflow job for this annotation

GitHub Actions / Build & Test

variable "station" is unused (if the variable is not meant to be used, prefix it with an underscore)

{:ok, podcast} =
attrs
|> Enum.into(%{
hostname: "some hostname",
title: "some title"
})
|> Radiator.Podcasts.create_podcast()
|> Podcasts.create_podcast()

podcast
end
Expand All @@ -28,7 +45,7 @@ defmodule Radiator.PodcastsFixtures do
|> Enum.into(%{
title: "some title"
})
|> Radiator.Podcasts.create_episode()
|> Podcasts.create_episode()

episode
end
Expand Down

0 comments on commit 2357144

Please sign in to comment.