@@ -10,27 +10,32 @@ defmodule Mix.Tasks.Ecto.CreateDropTest do
1010 @ behaviour Ecto.Adapter.Storage
1111
1212 defmacro __before_compile__ ( _ ) , do: :ok
13- def dumpers ( _ , _ ) , do: raise "not implemented"
14- def loaders ( _ , _ ) , do: raise "not implemented"
15- def init ( _ ) , do: raise "not implemented"
16- def checkout ( _ , _ , _ ) , do: raise "not implemented"
17- def checked_out? ( _ ) , do: raise "not implemented"
18- def ensure_all_started ( _ , _ ) , do: raise "not implemented"
13+ def dumpers ( _ , _ ) , do: raise ( "not implemented" )
14+ def loaders ( _ , _ ) , do: raise ( "not implemented" )
15+ def init ( _ ) , do: raise ( "not implemented" )
16+ def checkout ( _ , _ , _ ) , do: raise ( "not implemented" )
17+ def checked_out? ( _ ) , do: raise ( "not implemented" )
18+ def ensure_all_started ( _ , _ ) , do: raise ( "not implemented" )
19+
20+ def storage_up ( opts ) do
21+ return = Process . get ( :storage_up )
22+ Process . put ( :storage_up , opts )
23+ return || raise "no storage_up"
24+ end
1925
20- def storage_up ( _ ) , do: Process . get ( :storage_up ) || raise "no storage_up"
21- def storage_down ( _ ) , do: Process . get ( :storage_down ) || raise "no storage_down"
22- def storage_status ( _ ) , do: raise "no storage_status"
26+ def storage_down ( _ ) , do: Process . get ( :storage_down ) || raise ( "no storage_down" )
27+ def storage_status ( _ ) , do: raise ( "no storage_status" )
2328 end
2429
2530 defmodule NoStorageAdapter do
2631 @ behaviour Ecto.Adapter
2732 defmacro __before_compile__ ( _ ) , do: :ok
28- def dumpers ( _ , _ ) , do: raise "not implemented"
29- def loaders ( _ , _ ) , do: raise "not implemented"
30- def init ( _ ) , do: raise "not implemented"
31- def checkout ( _ , _ , _ ) , do: raise "not implemented"
32- def checked_out? ( _ ) , do: raise "not implemented"
33- def ensure_all_started ( _ , _ ) , do: raise "not implemented"
33+ def dumpers ( _ , _ ) , do: raise ( "not implemented" )
34+ def loaders ( _ , _ ) , do: raise ( "not implemented" )
35+ def init ( _ ) , do: raise ( "not implemented" )
36+ def checkout ( _ , _ , _ ) , do: raise ( "not implemented" )
37+ def checked_out? ( _ ) , do: raise ( "not implemented" )
38+ def ensure_all_started ( _ , _ ) , do: raise ( "not implemented" )
3439 end
3540
3641 # Mocked repos
@@ -52,70 +57,95 @@ defmodule Mix.Tasks.Ecto.CreateDropTest do
5257
5358 test "runs the adapter storage_up" do
5459 Process . put ( :storage_up , :ok )
55- Create . run [ "-r" , to_string ( Repo ) ]
56- assert_received { :mix_shell , :info , [ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has been created" ] }
60+ Create . run ( [ "-r" , to_string ( Repo ) ] )
61+
62+ assert_received { :mix_shell , :info ,
63+ [ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has been created" ] }
64+ end
65+
66+ 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 )
70+
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" ]
5774 end
5875
5976 test "runs the adapter storage_up with --quiet" do
6077 Process . put ( :storage_up , :ok )
61- Create . run [ "-r" , to_string ( Repo ) , "--quiet" ]
78+ Create . run ( [ "-r" , to_string ( Repo ) , "--quiet" ] )
6279 refute_received { :mix_shell , :info , [ _ ] }
6380 end
6481
6582 test "informs the user when the repo is already up" do
6683 Process . put ( :storage_up , { :error , :already_up } )
67- Create . run [ "-r" , to_string ( Repo ) ]
68- assert_received { :mix_shell , :info , [ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has already been created" ] }
84+ Create . run ( [ "-r" , to_string ( Repo ) ] )
85+
86+ assert_received { :mix_shell , :info ,
87+ [
88+ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has already been created"
89+ ] }
6990 end
7091
7192 test "raises an error when storage_up gives an unknown feedback" do
7293 Process . put ( :storage_up , { :error , :confused } )
94+
7395 assert_raise Mix.Error , fn ->
74- Create . run [ "-r" , to_string ( Repo ) ]
96+ Create . run ( [ "-r" , to_string ( Repo ) ] )
7597 end
7698 end
7799
78100 test "raises an error on storage_up when the adapter doesn't define a storage" do
79101 assert_raise Mix.Error , ~r/ to implement Ecto.Adapter.Storage/ , fn ->
80- Create . run [ "-r" , to_string ( NoStorageRepo ) ]
102+ Create . run ( [ "-r" , to_string ( NoStorageRepo ) ] )
81103 end
82104 end
83105
84106 ## Down
85107
86108 test "runs the adapter storage_down" do
87109 Process . put ( :storage_down , :ok )
88- Drop . run [ "-r" , to_string ( Repo ) ]
89- assert_received { :mix_shell , :info , [ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has been dropped" ] }
110+ Drop . run ( [ "-r" , to_string ( Repo ) ] )
111+
112+ assert_received { :mix_shell , :info ,
113+ [ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has been dropped" ] }
90114 end
91115
92116 test "runs the adapter storage_down with --quiet" do
93117 Process . put ( :storage_down , :ok )
94- Drop . run [ "-r" , to_string ( Repo ) , "--quiet" ]
118+ Drop . run ( [ "-r" , to_string ( Repo ) , "--quiet" ] )
95119 refute_received { :mix_shell , :info , [ _ ] }
96120 end
97121
98122 test "informs the user when the repo is already down" do
99123 Process . put ( :storage_down , { :error , :already_down } )
100- Drop . run [ "-r" , to_string ( Repo ) ]
101- assert_received { :mix_shell , :info , [ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has already been dropped" ] }
124+ Drop . run ( [ "-r" , to_string ( Repo ) ] )
125+
126+ assert_received { :mix_shell , :info ,
127+ [
128+ "The database for Mix.Tasks.Ecto.CreateDropTest.Repo has already been dropped"
129+ ] }
102130 end
103131
104132 test "raises an error when storage_down gives an unknown feedback" do
105133 Process . put ( :storage_down , { :error , { :error , :confused } } )
134+
106135 assert_raise Mix.Error , ~r/ couldn't be dropped: {:error, :confused}/ , fn ->
107- Drop . run [ "-r" , to_string ( Repo ) ]
136+ Drop . run ( [ "-r" , to_string ( Repo ) ] )
108137 end
109138
110139 Process . put ( :storage_down , { :error , "unknown" } )
140+
111141 assert_raise Mix.Error , ~r/ couldn't be dropped: unknown/ , fn ->
112- Drop . run [ "-r" , to_string ( Repo ) ]
142+ Drop . run ( [ "-r" , to_string ( Repo ) ] )
113143 end
114144 end
115145
116146 test "raises an error on storage_down when the adapter doesn't define a storage" do
117147 assert_raise Mix.Error , ~r/ to implement Ecto.Adapter.Storage/ , fn ->
118- Drop . run [ "-r" , to_string ( NoStorageRepo ) ]
148+ Drop . run ( [ "-r" , to_string ( NoStorageRepo ) ] )
119149 end
120150 end
121151end
0 commit comments