@@ -4,7 +4,17 @@ defmodule AshPostgres.MigrationGeneratorTest do
4
4
5
5
import ExUnit.CaptureLog
6
6
7
- defmacrop defposts ( mod \\ Post , do: body ) do
7
+ setup do
8
+ current_shell = Mix . shell ( )
9
+
10
+ :ok = Mix . shell ( Mix.Shell.Process )
11
+
12
+ on_exit ( fn ->
13
+ Mix . shell ( current_shell )
14
+ end )
15
+ end
16
+
17
+ defmacrop defresource ( mod , do: body ) do
8
18
quote do
9
19
Code . compiler_options ( ignore_module_conflict: true )
10
20
@@ -13,6 +23,16 @@ defmodule AshPostgres.MigrationGeneratorTest do
13
23
domain: nil ,
14
24
data_layer: AshPostgres.DataLayer
15
25
26
+ unquote ( body )
27
+ end
28
+
29
+ Code . compiler_options ( ignore_module_conflict: false )
30
+ end
31
+ end
32
+
33
+ defmacrop defposts ( mod \\ Post , do: body ) do
34
+ quote do
35
+ defresource unquote ( mod ) do
16
36
postgres do
17
37
table "posts"
18
38
repo ( AshPostgres.TestRepo )
@@ -30,8 +50,23 @@ defmodule AshPostgres.MigrationGeneratorTest do
30
50
31
51
unquote ( body )
32
52
end
53
+ end
54
+ end
33
55
34
- Code . compiler_options ( ignore_module_conflict: false )
56
+ defmacrop defcomments ( mod \\ Comment , do: body ) do
57
+ quote do
58
+ defresource unquote ( mod ) do
59
+ postgres do
60
+ table "comments"
61
+ repo ( AshPostgres.TestRepo )
62
+ end
63
+
64
+ actions do
65
+ defaults ( [ :create , :read , :update , :destroy ] )
66
+ end
67
+
68
+ unquote ( body )
69
+ end
35
70
end
36
71
end
37
72
@@ -108,8 +143,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
108
143
109
144
defdomain ( [ Post ] )
110
145
111
- Mix . shell ( Mix.Shell.Process )
112
-
113
146
AshPostgres.MigrationGenerator . generate ( Domain ,
114
147
snapshot_path: "test_snapshots_path" ,
115
148
migration_path: "test_migration_path" ,
@@ -208,8 +241,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
208
241
209
242
defdomain ( [ Post ] )
210
243
211
- Mix . shell ( Mix.Shell.Process )
212
-
213
244
{ :ok , _ } =
214
245
Ecto.Adapters.SQL . query (
215
246
AshPostgres.TestRepo ,
@@ -291,7 +322,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
291
322
end
292
323
293
324
defdomain ( [ Post ] )
294
- Mix . shell ( Mix.Shell.Process )
295
325
296
326
AshPostgres.MigrationGenerator . generate ( Domain ,
297
327
snapshot_path: "test_snapshots_path" ,
@@ -336,7 +366,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
336
366
end
337
367
338
368
defdomain ( [ Post ] )
339
- Mix . shell ( Mix.Shell.Process )
340
369
341
370
AshPostgres.MigrationGenerator . generate ( Domain ,
342
371
snapshot_path: "test_snapshots_path" ,
@@ -378,8 +407,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
378
407
379
408
defdomain ( [ Post ] )
380
409
381
- Mix . shell ( Mix.Shell.Process )
382
-
383
410
AshPostgres.MigrationGenerator . generate ( Domain ,
384
411
snapshot_path: "test_snapshots_path" ,
385
412
migration_path: "test_migration_path" ,
@@ -470,8 +497,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
470
497
471
498
defdomain ( [ Post ] )
472
499
473
- Mix . shell ( Mix.Shell.Process )
474
-
475
500
AshPostgres.MigrationGenerator . generate ( Domain ,
476
501
snapshot_path: "test_snapshots_path" ,
477
502
migration_path: "test_migration_path" ,
@@ -833,8 +858,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
833
858
834
859
defdomain ( [ Post ] )
835
860
836
- Mix . shell ( Mix.Shell.Process )
837
-
838
861
AshPostgres.MigrationGenerator . generate ( Domain ,
839
862
snapshot_path: "test_snapshots_path" ,
840
863
migration_path: "test_migration_path" ,
@@ -1635,11 +1658,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
1635
1658
File . rm_rf! ( "test_migration_path" )
1636
1659
end )
1637
1660
1638
- defmodule Comment do
1639
- use Ash.Resource ,
1640
- domain: nil ,
1641
- data_layer: AshPostgres.DataLayer
1642
-
1661
+ defcomments do
1643
1662
postgres do
1644
1663
polymorphic? ( true )
1645
1664
repo ( AshPostgres.TestRepo )
@@ -1832,16 +1851,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
1832
1851
end
1833
1852
end
1834
1853
1835
- defmodule Comment do
1836
- use Ash.Resource ,
1837
- domain: nil ,
1838
- data_layer: AshPostgres.DataLayer
1839
-
1840
- postgres do
1841
- table "comments"
1842
- repo AshPostgres.TestRepo
1843
- end
1844
-
1854
+ defcomments do
1845
1855
attributes do
1846
1856
uuid_primary_key ( :id )
1847
1857
end
@@ -1855,8 +1865,6 @@ defmodule AshPostgres.MigrationGeneratorTest do
1855
1865
1856
1866
defdomain ( [ Post , Comment ] )
1857
1867
1858
- Mix . shell ( Mix.Shell.Process )
1859
-
1860
1868
AshPostgres.MigrationGenerator . generate ( Domain ,
1861
1869
snapshot_path: "test_snapshots_path" ,
1862
1870
migration_path: "test_migration_path" ,
@@ -1881,16 +1889,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
1881
1889
end
1882
1890
end
1883
1891
1884
- defmodule Comment do
1885
- use Ash.Resource ,
1886
- domain: nil ,
1887
- data_layer: AshPostgres.DataLayer
1888
-
1889
- postgres do
1890
- table "comments"
1891
- repo AshPostgres.TestRepo
1892
- end
1893
-
1892
+ defcomments do
1894
1893
attributes do
1895
1894
uuid_primary_key ( :id )
1896
1895
end
0 commit comments