forked from ash-project/ash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathash.gen.resources_test.exs
More file actions
120 lines (102 loc) · 3.08 KB
/
ash.gen.resources_test.exs
File metadata and controls
120 lines (102 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
defmodule Mix.Tasks.Ash.Gen.ResourcesTest do
use ExUnit.Case
import Igniter.Test
@moduletag :igniter
test "generates complete blog system with different resource configurations" do
test_project()
|> Igniter.compose_task("ash.gen.resources", [
"MyApp.Blog.Post --uuid-primary-key id --attribute title:string:required:public,body:text:public,status:atom --relationship belongs_to:author:MyApp.Accounts.User:required --default-actions read,create,update --timestamps;MyApp.Blog.Comment --attribute content:text:required:public --relationship belongs_to:post:MyApp.Blog.Post:required,belongs_to:author:MyApp.Accounts.User:required --default-actions read,create;MyApp.Accounts.User --uuid-primary-key id --attribute name:string:required:public,email:string:required:public --default-actions read,create,update"
])
|> assert_creates("lib/my_app/blog/post.ex", """
defmodule MyApp.Blog.Post do
use Ash.Resource,
otp_app: :test,
domain: MyApp.Blog
attributes do
uuid_primary_key(:id)
attribute :title, :string do
allow_nil?(false)
public?(true)
end
attribute :body, :text do
public?(true)
end
attribute(:status, :atom)
timestamps()
end
relationships do
belongs_to :author, MyApp.Accounts.User do
allow_nil?(false)
end
end
actions do
defaults([:read, create: [:title, :body], update: [:title, :body]])
end
end
""")
|> assert_creates("lib/my_app/blog/comment.ex", """
defmodule MyApp.Blog.Comment do
use Ash.Resource,
otp_app: :test,
domain: MyApp.Blog
attributes do
attribute :content, :text do
allow_nil?(false)
public?(true)
end
end
relationships do
belongs_to :post, MyApp.Blog.Post do
allow_nil?(false)
end
belongs_to :author, MyApp.Accounts.User do
allow_nil?(false)
end
end
actions do
defaults([:read, create: [:content]])
end
end
""")
|> assert_creates("lib/my_app/accounts/user.ex", """
defmodule MyApp.Accounts.User do
use Ash.Resource,
otp_app: :test,
domain: MyApp.Accounts
attributes do
uuid_primary_key(:id)
attribute :name, :string do
allow_nil?(false)
public?(true)
end
attribute :email, :string do
allow_nil?(false)
public?(true)
end
end
actions do
defaults([:read, create: [:name, :email], update: [:name, :email]])
end
end
""")
|> assert_creates("lib/my_app/blog.ex", """
defmodule MyApp.Blog do
use Ash.Domain,
otp_app: :test
resources do
resource(MyApp.Blog.Post)
resource(MyApp.Blog.Comment)
end
end
""")
|> assert_creates("lib/my_app/accounts.ex", """
defmodule MyApp.Accounts do
use Ash.Domain,
otp_app: :test
resources do
resource(MyApp.Accounts.User)
end
end
""")
end
end