Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2807b19

Browse files
chore: Test creating resource with uuid or integer primary key (ash-project#48)
Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
1 parent5dd8a15 commit2807b19

File tree

7 files changed

+195
-0
lines changed

7 files changed

+195
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"attributes": [
3+
{
4+
"allow_nil?":false,
5+
"default":"fragment(\"uuid_generate_v4()\")",
6+
"generated?":false,
7+
"name":"id",
8+
"primary_key?":true,
9+
"references":null,
10+
"type":"binary_id"
11+
},
12+
{
13+
"allow_nil?":true,
14+
"default":"nil",
15+
"generated?":false,
16+
"name":"post_id",
17+
"primary_key?":false,
18+
"references": {
19+
"destination_field":"id",
20+
"multitenancy": {
21+
"attribute":null,
22+
"global":null,
23+
"strategy":null
24+
},
25+
"table":"posts"
26+
},
27+
"type":"binary_id"
28+
},
29+
{
30+
"allow_nil?":true,
31+
"default":"nil",
32+
"generated?":false,
33+
"name":"title",
34+
"primary_key?":false,
35+
"references":null,
36+
"type":"text"
37+
}
38+
],
39+
"base_filter":null,
40+
"hash":"4144E61762BA12123F8970C4DFB17E4A131EBD80C86D79FDE381E1B9BCF8CA22",
41+
"identities": [],
42+
"multitenancy": {
43+
"attribute":null,
44+
"global":null,
45+
"strategy":null
46+
},
47+
"repo":"Elixir.AshPostgres.TestRepo",
48+
"table":"comments"
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"attributes": [
3+
{
4+
"allow_nil?":false,
5+
"default":"nil",
6+
"generated?":true,
7+
"name":"id",
8+
"primary_key?":true,
9+
"references":null,
10+
"type":"integer"
11+
},
12+
{
13+
"allow_nil?":true,
14+
"default":"nil",
15+
"generated?":false,
16+
"name":"title",
17+
"primary_key?":false,
18+
"references":null,
19+
"type":"text"
20+
}
21+
],
22+
"base_filter":null,
23+
"hash":"7627F6422A989723C58538872A3DDB538F9A41CA9D7801AEE241A8EAE707215B",
24+
"identities": [],
25+
"multitenancy": {
26+
"attribute":null,
27+
"global":null,
28+
"strategy":null
29+
},
30+
"repo":"Elixir.AshPostgres.TestRepo",
31+
"table":"integer_posts"
32+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"attributes": [
3+
{
4+
"allow_nil?":true,
5+
"default":"nil",
6+
"generated?":false,
7+
"name":"category",
8+
"primary_key?":false,
9+
"references":null,
10+
"type":"citext"
11+
},
12+
{
13+
"allow_nil?":false,
14+
"default":"fragment(\"uuid_generate_v4()\")",
15+
"generated?":false,
16+
"name":"id",
17+
"primary_key?":true,
18+
"references":null,
19+
"type":"binary_id"
20+
},
21+
{
22+
"allow_nil?":true,
23+
"default":"nil",
24+
"generated?":false,
25+
"name":"public",
26+
"primary_key?":false,
27+
"references":null,
28+
"type":"boolean"
29+
},
30+
{
31+
"allow_nil?":true,
32+
"default":"nil",
33+
"generated?":false,
34+
"name":"score",
35+
"primary_key?":false,
36+
"references":null,
37+
"type":"integer"
38+
},
39+
{
40+
"allow_nil?":true,
41+
"default":"nil",
42+
"generated?":false,
43+
"name":"title",
44+
"primary_key?":false,
45+
"references":null,
46+
"type":"text"
47+
}
48+
],
49+
"base_filter":null,
50+
"hash":"856C6A868E9D616B3D87379A23F22EC4BB7DA51AB17DE47A4D599F2B442AD567",
51+
"identities": [],
52+
"multitenancy": {
53+
"attribute":null,
54+
"global":null,
55+
"strategy":null
56+
},
57+
"repo":"Elixir.AshPostgres.TestRepo",
58+
"table":"posts"
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmoduleAshPostgres.TestRepo.Migrations.MigrateResources2do
2+
@moduledoc"""
3+
Updates resources based on their most recent snapshots.
4+
5+
This file was autogenerated with `mix ash_postgres.generate_migrations`
6+
"""
7+
8+
useEcto.Migration
9+
10+
defupdo
11+
createtable(:integer_posts,primary_key:false)do
12+
add:id,:serial,null:false,primary_key:true
13+
add:title,:text
14+
end
15+
end
16+
17+
defdowndo
18+
droptable("integer_posts")
19+
end
20+
end

‎test/primary_key_test.exs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmoduleAshPostgres.Test.PrimaryKeyTestdo
2+
useAshPostgres.RepoCase,async:false
3+
aliasAshPostgres.Test.{Api,IntegerPost,Post}
4+
5+
requireAsh.Query
6+
7+
test"creates resource with integer primary key"do
8+
assert%IntegerPost{}=IntegerPost|>Ash.Changeset.new(%{title:"title"})|>Api.create!()
9+
end
10+
11+
test"creates resource with uuid primary key"do
12+
assert%Post{}=Post|>Ash.Changeset.new(%{title:"title"})|>Api.create!()
13+
end
14+
end

‎test/support/api.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule AshPostgres.Test.Api do
55
resourcesdo
66
resource(AshPostgres.Test.Post)
77
resource(AshPostgres.Test.Comment)
8+
resource(AshPostgres.Test.IntegerPost)
89
resource(AshPostgres.Test.Rating)
910
end
1011
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmoduleAshPostgres.Test.IntegerPostdo
2+
@moduledocfalse
3+
useAsh.Resource,
4+
data_layer:AshPostgres.DataLayer
5+
6+
postgresdo
7+
table"integer_posts"
8+
repoAshPostgres.TestRepo
9+
end
10+
11+
actionsdo
12+
read(:read)
13+
create(:create)
14+
end
15+
16+
attributesdo
17+
integer_primary_key(:id)
18+
attribute(:title,:string)
19+
end
20+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp