Skip to content

Commit

Permalink
Add tests for missing directories in exception
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 28, 2024
1 parent 1691937 commit 9ae7afe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
1 change: 1 addition & 0 deletions lib/phoenix_ecto/exceptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Phoenix.Ecto.StorageNotCreatedError do
end

defmodule Phoenix.Ecto.PendingMigrationError do
@enforce_keys [:repo, :directories]
defexception [:repo, :directories]

def message(%__MODULE__{repo: repo}) do
Expand Down
72 changes: 42 additions & 30 deletions test/phoenix_ecto/check_repo_status_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do

conn = conn(:get, "/")

assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
mock_migrations_fn: mock_migrations_fn
)
end)
exception =
assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
mock_migrations_fn: mock_migrations_fn
)
end)

assert exception.directories == []
after
Application.delete_env(:check_repo_ready, :ecto_repos)
Process.unregister(StorageUpRepo)
Expand Down Expand Up @@ -122,26 +125,32 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do
# set to a single directory
mock_migrations_fn = fn _repo, ["foo"], _opts -> [{:down, 1, "migration"}] end

assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
migration_paths: fn _repo -> "foo" end,
mock_migrations_fn: mock_migrations_fn
)
end)
exception =
assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
migration_paths: fn _repo -> "foo" end,
mock_migrations_fn: mock_migrations_fn
)
end)

assert exception.directories == ["foo"]

# set to multiple directories
mock_migrations_fn = fn _repo, ["foo", "bar"], _opts -> [{:down, 1, "migration"}] end

assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
migration_paths: fn _repo -> ["foo", "bar"] end,
mock_migrations_fn: mock_migrations_fn
)
end)
exception =
assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
migration_paths: fn _repo -> ["foo", "bar"] end,
mock_migrations_fn: mock_migrations_fn
)
end)

assert exception.directories == ["foo", "bar"]
after
Application.delete_env(:check_repo_ready, :ecto_repos)
Process.unregister(StorageUpRepo)
Expand Down Expand Up @@ -244,13 +253,16 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do

conn = conn(:get, "/")

assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
mock_migrations_fn: mock_migrations_fn
)
end)
exception =
assert_raise(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
mock_migrations_fn: mock_migrations_fn
)
end)

assert exception.directories == []
after
Application.delete_env(:check_repo_ready, :ecto_repos)
Process.unregister(StorageUpRepo)
Expand Down

0 comments on commit 9ae7afe

Please sign in to comment.