@@ -4,6 +4,8 @@ defmodule AshPostgres.MigrationGeneratorTest do
4
4
5
5
import ExUnit.CaptureLog
6
6
7
+ alias AshPostgres.MigrationGenerator
8
+
7
9
setup do
8
10
current_shell = Mix . shell ( )
9
11
@@ -1252,13 +1254,17 @@ defmodule AshPostgres.MigrationGeneratorTest do
1252
1254
1253
1255
describe "--dev option" do
1254
1256
setup do
1257
+ { snapshot_path , migration_path } = { "test_snapshots_path" , "test_migration_path" }
1258
+
1255
1259
on_exit ( fn ->
1256
- File . rm_rf! ( "test_snapshots_path" )
1257
- File . rm_rf! ( "test_migration_path" )
1260
+ File . rm_rf! ( snapshot_path )
1261
+ File . rm_rf! ( migration_path )
1258
1262
end )
1263
+
1264
+ [ opts: [ snapshot_path: snapshot_path , migration_path: migration_path ] ]
1259
1265
end
1260
1266
1261
- test "generates dev migration" do
1267
+ test "generates dev migration" , % { opts: opts } do
1262
1268
defposts do
1263
1269
attributes do
1264
1270
uuid_primary_key ( :id )
@@ -1268,32 +1274,14 @@ defmodule AshPostgres.MigrationGeneratorTest do
1268
1274
1269
1275
defdomain ( [ Post ] )
1270
1276
1271
- AshPostgres.MigrationGenerator . generate ( Domain ,
1272
- snapshot_path: "test_snapshots_path" ,
1273
- snapshots_only: false ,
1274
- migration_path: "test_migration_path" ,
1275
- dev: true
1276
- )
1277
-
1278
- assert [ dev_file ] =
1279
- Path . wildcard ( "test_migration_path/**/*_migrate_resources*.exs" )
1280
- |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
1281
-
1277
+ assert :ok == MigrationGenerator . generate ( Domain , opts ++ [ dev: true ] )
1278
+ assert [ dev_file ] = get_migration_files ( opts )
1282
1279
assert String . contains? ( dev_file , "_dev.exs" )
1283
- contents = File . read! ( dev_file )
1284
-
1285
- AshPostgres.MigrationGenerator . generate ( Domain ,
1286
- snapshot_path: "test_snapshots_path" ,
1287
- migration_path: "test_migration_path"
1288
- )
1289
-
1290
- assert [ file ] =
1291
- Path . wildcard ( "test_migration_path/**/*_migrate_resources*.exs" )
1292
- |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
1293
-
1280
+ assert { :ok , dev_file_read } = File . read ( dev_file )
1281
+ assert :ok == MigrationGenerator . generate ( Domain , opts )
1282
+ assert [ file ] = get_migration_files ( opts )
1283
+ assert dev_file_read == File . read! ( file )
1294
1284
refute String . contains? ( file , "_dev.exs" )
1295
-
1296
- assert contents == File . read! ( file )
1297
1285
end
1298
1286
end
1299
1287
@@ -2345,4 +2333,11 @@ defmodule AshPostgres.MigrationGeneratorTest do
2345
2333
~S[ modify :post_id, references(:posts, column: :id, name: "comments_post_id_fkey", type: :uuid, prefix: "public")]
2346
2334
end
2347
2335
end
2336
+
2337
+ defp get_migration_files ( opts ) do
2338
+ opts [ :migration_path ]
2339
+ |> Path . join ( "**/*_migrate_resources*.exs" )
2340
+ |> Path . wildcard ( )
2341
+ |> Enum . reject ( & String . contains? ( & 1 , "extensions" ) )
2342
+ end
2348
2343
end
0 commit comments