@@ -32,7 +32,9 @@ def setup
32
32
end
33
33
34
34
def test_includes_post_id
35
- assert_equal ( "42" , @adapter . serializable_hash [ :data ] [ :links ] [ :post ] )
35
+ expected = { linkage : { type : "post" , id : "42" } }
36
+
37
+ assert_equal ( expected , @adapter . serializable_hash [ :data ] [ :links ] [ :post ] )
36
38
end
37
39
38
40
def test_includes_linked_post
@@ -42,9 +44,9 @@ def test_includes_linked_post
42
44
title : 'New Post' ,
43
45
body : 'Body' ,
44
46
links : {
45
- comments : [ "1" ] ,
46
- blog : " 999",
47
- author : "1"
47
+ comments : { linkage : [ { type : "comments" , id : "1" } ] } ,
48
+ blog : { linkage : { type : "blog" , id : " 999" } } ,
49
+ author : { linkage : { type : "author" , id : "1" } }
48
50
}
49
51
} ]
50
52
assert_equal expected , @adapter . serializable_hash [ :linked ] [ :posts ]
@@ -55,9 +57,9 @@ def test_limiting_linked_post_fields
55
57
expected = [ {
56
58
title : 'New Post' ,
57
59
links : {
58
- comments : [ "1" ] ,
59
- blog : " 999",
60
- author : "1"
60
+ comments : { linkage : [ { type : "comments" , id : "1" } ] } ,
61
+ blog : { linkage : { type : "blog" , id : " 999" } } ,
62
+ author : { linkage : { type : "author" , id : "1" } }
61
63
}
62
64
} ]
63
65
assert_equal expected , @adapter . serializable_hash [ :linked ] [ :posts ]
@@ -67,7 +69,7 @@ def test_include_nil_author
67
69
serializer = PostSerializer . new ( @anonymous_post )
68
70
adapter = ActiveModel ::Serializer ::Adapter ::JsonApi . new ( serializer )
69
71
70
- assert_equal ( { comments : [ ] , blog : " 999", author : nil } , adapter . serializable_hash [ :data ] [ :links ] )
72
+ assert_equal ( { comments : { linkage : [ ] } , blog : { linkage : { type : "blog" , id : " 999" } } , author : { linkage : nil } } , adapter . serializable_hash [ :data ] [ :links ] )
71
73
end
72
74
73
75
def test_include_type_for_association_when_different_than_name
@@ -76,12 +78,22 @@ def test_include_type_for_association_when_different_than_name
76
78
links = adapter . serializable_hash [ :data ] [ :links ]
77
79
expected = {
78
80
writer : {
79
- type : "author" ,
80
- id : "1"
81
+ linkage : {
82
+ type : "author" ,
83
+ id : "1"
84
+ }
81
85
} ,
82
86
articles : {
83
- type : "posts" ,
84
- ids : [ "42" , "43" ]
87
+ linkage : [
88
+ {
89
+ type : "posts" ,
90
+ id : "42"
91
+ } ,
92
+ {
93
+ type : "posts" ,
94
+ id : "43"
95
+ }
96
+ ]
85
97
}
86
98
}
87
99
assert_equal expected , links
@@ -96,28 +108,28 @@ def test_include_linked_resources_with_type_name
96
108
id : "1" ,
97
109
name : "Steve K." ,
98
110
links : {
99
- posts : [ ] ,
100
- roles : [ ] ,
101
- bio : nil
111
+ posts : { linkage : [ ] } ,
112
+ roles : { linkage : [ ] } ,
113
+ bio : { linkage : nil }
102
114
}
103
115
} ] ,
104
116
posts : [ {
105
117
title : "New Post" ,
106
118
body : "Body" ,
107
119
id : "42" ,
108
120
links : {
109
- comments : [ "1" ] ,
110
- blog : " 999",
111
- author : "1"
121
+ comments : { linkage : [ { type : "comments" , id : "1" } ] } ,
122
+ blog : { linkage : { type : "blog" , id : " 999" } } ,
123
+ author : { linkage : { type : "author" , id : "1" } }
112
124
}
113
125
} , {
114
126
title : "Hello!!" ,
115
127
body : "Hello, world!!" ,
116
128
id : "43" ,
117
129
links : {
118
- comments : [ ] ,
119
- blog : " 999",
120
- author : nil
130
+ comments : { linkage : [ ] } ,
131
+ blog : { linkage : { type : "blog" , id : " 999" } } ,
132
+ author : { linkage : nil }
121
133
}
122
134
} ]
123
135
}
0 commit comments