Skip to content

Commit 5ffc1d2

Browse files
committed
Fix testing DB setup
1 parent 47cd0de commit 5ffc1d2

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

config/config.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ use Mix.Config
2121
# Configuration from the imported file will override the ones defined
2222
# here (which is why it is important to import them last).
2323
#
24-
# import_config "#{Mix.env}.exs"
24+
import_config "#{Mix.env}.exs"

config/dev.exs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use Mix.Config

config/test.exs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use Mix.Config
2+
3+
config :ecto_ordered, EctoOrderedTest.Repo,
4+
pool: Ecto.Adapters.SQL.Sandbox,
5+
url: System.get_env("DATABASE_URL") || "ecto://postgres:postgres@localhost/ecto_ordered_test",
6+
priv: "priv/test/repo"

mix.exs

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule EctoOrdered.Mixfile do
66
version: "0.0.2",
77
elixir: "~> 1.0",
88
description: "Ecto extension to support ordered list models",
9+
elixirc_paths: path(Mix.env),
910
package: package,
1011
deps: deps]
1112
end
@@ -26,6 +27,12 @@ defmodule EctoOrdered.Mixfile do
2627
[:ecto]
2728
end
2829

30+
defp path(:test) do
31+
["lib", "test/support", "test/fixtures"]
32+
end
33+
defp path(_), do: ["lib"]
34+
35+
2936
# Dependencies can be Hex packages:
3037
#
3138
# {:mydep, "~> 0.3.0"}
File renamed without changes.

test/support/repo.ex

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defmodule EctoOrderedTest.Repo do
2+
use Ecto.Repo, otp_app: :ecto_ordered,
3+
adapter: Ecto.Adapters.Postgres
4+
end

test/test_helper.exs

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
Logger.configure level: :error
2-
Application.put_env(:ecto_ordered, EctoOrderedTest.Repo, pool: Ecto.Adapters.SQL.Sandbox,
3-
database: "ecto_ordered_test",
4-
url: System.get_env("DATABASE_URL") || "ecto://postgres:postgres@localhost/ecto_ordered_test")
5-
6-
Code.require_file "test_migrations.exs", __DIR__
7-
defmodule EctoOrderedTest.Repo do
8-
use Ecto.Repo, otp_app: :ecto_ordered,
9-
adapter: Ecto.Adapters.Postgres
10-
end
2+
ExUnit.configure(exclude: [skip: true])
113

124
defmodule EctoOrdered.TestCase do
135
use ExUnit.CaseTemplate
@@ -28,9 +20,12 @@ defmodule EctoOrdered.TestCase do
2820

2921
end
3022

23+
24+
Mix.Task.run "ecto.drop", ~w(-r EctoOrderedTest.Repo)
25+
Mix.Task.run "ecto.create", ~w(-r EctoOrderedTest.Repo)
26+
Mix.Task.run "ecto.migrate", ~w(-r EctoOrderedTest.Repo)
27+
3128
EctoOrderedTest.Repo.start_link
32-
_ = Ecto.Migrator.up(EctoOrderedTest.Repo, 0, EctoOrderedTest.Migrations)
29+
ExUnit.start()
3330
Ecto.Adapters.SQL.Sandbox.mode(EctoOrderedTest.Repo, :manual)
3431

35-
ExUnit.configure(exclude: [skip: true])
36-
ExUnit.start()

0 commit comments

Comments
 (0)