Skip to content

Commit b45b0f6

Browse files
committed
Add tests for --no-timezone
1 parent 3d00dbf commit b45b0f6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/mix/tasks/ecto.create.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule Mix.Tasks.Ecto.Create do
99
repo: [:string, :keep],
1010
no_compile: :boolean,
1111
no_deps_check: :boolean,
12+
no_timezone: :boolean,
1213
timezone: :string
1314
]
1415

@@ -60,6 +61,13 @@ defmodule Mix.Tasks.Ecto.Create do
6061
"create storage for #{inspect(repo)}"
6162
)
6263

64+
opts =
65+
if Keyword.get(opts, :no_timezone) do
66+
Keyword.put(opts, :timezone, nil)
67+
else
68+
opts
69+
end
70+
6371
config_opts = Keyword.take(opts, [:timezone]) ++ repo.config()
6472

6573
case repo.__adapter__().storage_up(config_opts) do

test/mix/tasks/ecto.create_drop_test.exs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ defmodule Mix.Tasks.Ecto.CreateDropTest do
6464
end
6565

6666
test "parses options" do
67-
Process.put(:storage_up, :ok)
68-
Create.run(["-r", to_string(Repo)])
69-
refute Keyword.has_key?(Process.get(:storage_up), :timezone)
67+
run_options = fn args ->
68+
Process.put(:storage_up, :ok)
69+
Create.run(["-r", to_string(Repo)] ++ args)
70+
Keyword.take(Process.get(:storage_up), [:timezone])
71+
end
7072

71-
Process.put(:storage_up, :ok)
72-
Create.run(["-r", to_string(Repo), "--timezone", "Europe/Warsaw"])
73-
assert Keyword.take(Process.get(:storage_up), [:timezone]) == [timezone: "Europe/Warsaw"]
73+
refute Keyword.has_key?(run_options.([]), :timezone)
74+
assert run_options.(["--no-timezone"]) == [timezone: nil]
75+
assert run_options.(["--timezone", "Europe/Warsaw"]) == [timezone: "Europe/Warsaw"]
7476
end
7577

7678
test "runs the adapter storage_up with --quiet" do

0 commit comments

Comments
 (0)