55defmodule AshSqlite.DevMigrationsTest do
66 use AshSqlite.RepoCase , async: false
77 @ moduletag :migration
8+ @ moduletag :tmp_dir
89
910 alias Ecto.Adapters.SQL.Sandbox
1011
11- setup do
12+ setup % { tmp_dir: tmp_dir } do
1213 current_shell = Mix . shell ( )
1314
1415 :ok = Mix . shell ( Mix.Shell.Process )
@@ -19,6 +20,11 @@ defmodule AshSqlite.DevMigrationsTest do
1920
2021 Sandbox . checkout ( AshSqlite.DevTestRepo )
2122 Sandbox . mode ( AshSqlite.DevTestRepo , { :shared , self ( ) } )
23+
24+ % {
25+ snapshot_path: Path . join ( tmp_dir , "snapshots" ) ,
26+ migration_path: Path . join ( tmp_dir , "migrations" )
27+ }
2228 end
2329
2430 defmacrop defresource ( mod , do: body ) do
@@ -103,20 +109,19 @@ defmodule AshSqlite.DevMigrationsTest do
103109 Enum . each ( new_migration_files , & File . rm! ( Path . join ( migrations_dev_path , & 1 ) ) )
104110 end
105111
106- # Clean up test directories
107- File . rm_rf! ( "test_snapshots_path" )
108- File . rm_rf! ( "test_migration_path" )
109-
110112 try do
111113 AshSqlite.DevTestRepo . query! ( "DROP TABLE IF EXISTS posts" )
112- rescue
113- _ -> :ok
114+ catch
115+ _ , _ -> :ok
114116 end
115117 end )
116118 end
117119
118120 describe "--dev option" do
119- test "generates dev migration" do
121+ test "generates dev migration" , % {
122+ snapshot_path: snapshot_path ,
123+ migration_path: migration_path
124+ } do
120125 defposts do
121126 attributes do
122127 uuid_primary_key ( :id )
@@ -127,32 +132,35 @@ defmodule AshSqlite.DevMigrationsTest do
127132 defdomain ( [ Post ] )
128133
129134 AshSqlite.MigrationGenerator . generate ( Domain ,
130- snapshot_path: "test_snapshots_path" ,
131- migration_path: "test_migration_path" ,
135+ snapshot_path: snapshot_path ,
136+ migration_path: migration_path ,
132137 dev: true
133138 )
134139
135140 assert [ dev_file ] =
136- Path . wildcard ( "test_migration_path /**/*_migrate_resources*.exs" )
141+ Path . wildcard ( "#{ migration_path } /**/*_migrate_resources*.exs" )
137142
138143 assert String . contains? ( dev_file , "_dev.exs" )
139144 contents = File . read! ( dev_file )
140145
141146 AshSqlite.MigrationGenerator . generate ( Domain ,
142- snapshot_path: "test_snapshots_path" ,
143- migration_path: "test_migration_path" ,
147+ snapshot_path: snapshot_path ,
148+ migration_path: migration_path ,
144149 auto_name: true
145150 )
146151
147152 assert [ file ] =
148- Path . wildcard ( "test_migration_path /**/*_migrate_resources*.exs" )
153+ Path . wildcard ( "#{ migration_path } /**/*_migrate_resources*.exs" )
149154
150155 refute String . contains? ( file , "_dev.exs" )
151156
152157 assert contents == File . read! ( file )
153158 end
154159
155- test "removes dev migrations when generating regular migrations" do
160+ test "removes dev migrations when generating regular migrations" , % {
161+ snapshot_path: snapshot_path ,
162+ migration_path: migration_path
163+ } do
156164 defposts do
157165 attributes do
158166 uuid_primary_key ( :id )
@@ -164,31 +172,34 @@ defmodule AshSqlite.DevMigrationsTest do
164172
165173 # Generate dev migration first
166174 AshSqlite.MigrationGenerator . generate ( Domain ,
167- snapshot_path: "test_snapshots_path" ,
168- migration_path: "test_migration_path" ,
175+ snapshot_path: snapshot_path ,
176+ migration_path: migration_path ,
169177 dev: true
170178 )
171179
172180 assert [ dev_file ] =
173- Path . wildcard ( "test_migration_path /**/*_migrate_resources*.exs" )
181+ Path . wildcard ( "#{ migration_path } /**/*_migrate_resources*.exs" )
174182
175183 assert String . contains? ( dev_file , "_dev.exs" )
176184
177185 # Generate regular migration - should remove dev migration
178186 AshSqlite.MigrationGenerator . generate ( Domain ,
179- snapshot_path: "test_snapshots_path" ,
180- migration_path: "test_migration_path" ,
187+ snapshot_path: snapshot_path ,
188+ migration_path: migration_path ,
181189 auto_name: true
182190 )
183191
184192 # Should only have regular migration now
185- files = Path . wildcard ( "test_migration_path /**/*_migrate_resources*.exs" )
193+ files = Path . wildcard ( "#{ migration_path } /**/*_migrate_resources*.exs" )
186194 assert length ( files ) == 1
187195 assert [ regular_file ] = files
188196 refute String . contains? ( regular_file , "_dev.exs" )
189197 end
190198
191- test "requires name when not using dev option" do
199+ test "requires name when not using dev option" , % {
200+ snapshot_path: snapshot_path ,
201+ migration_path: migration_path
202+ } do
192203 defposts do
193204 attributes do
194205 uuid_primary_key ( :id )
@@ -200,8 +211,8 @@ defmodule AshSqlite.DevMigrationsTest do
200211
201212 assert_raise RuntimeError , ~r/ Name must be provided/ , fn ->
202213 AshSqlite.MigrationGenerator . generate ( Domain ,
203- snapshot_path: "test_snapshots_path" ,
204- migration_path: "test_migration_path"
214+ snapshot_path: snapshot_path ,
215+ migration_path: migration_path
205216 )
206217 end
207218 end
0 commit comments