@@ -83,80 +83,87 @@ def render_collection_with_include
83
83
def test_render_resource_without_include
84
84
get :render_resource_without_include
85
85
response = JSON . parse ( @response . body )
86
- refute response . key? 'linked '
86
+ refute response . key? 'included '
87
87
end
88
88
89
89
def test_render_resource_with_include
90
90
get :render_resource_with_include
91
91
response = JSON . parse ( @response . body )
92
- assert response . key? 'linked '
93
- assert_equal 1 , response [ 'linked' ] [ 'authors '] . size
94
- assert_equal 'Steve K.' , response [ 'linked' ] [ 'authors '] . first [ 'name' ]
92
+ assert response . key? 'included '
93
+ assert_equal 1 , response [ 'included ' ] . size
94
+ assert_equal 'Steve K.' , response [ 'included ' ] . first [ 'name' ]
95
95
end
96
96
97
97
def test_render_resource_with_nested_has_many_include
98
98
get :render_resource_with_nested_has_many_include
99
99
response = JSON . parse ( @response . body )
100
- expected_linked = {
101
- "authors" => [ {
100
+ expected_linked = [
101
+ {
102
102
"id" => "1" ,
103
+ "type" => "authors" ,
103
104
"name" => "Steve K." ,
104
105
"links" => {
105
106
"posts" => { "linkage" => [ ] } ,
106
107
"roles" => { "linkage" => [ { "type" => "roles" , "id" => "1" } , { "type" => "roles" , "id" => "2" } ] } ,
107
108
"bio" => { "linkage" => nil }
108
109
}
109
- } ] ,
110
- "roles" => [ {
110
+ } , {
111
111
"id" => "1" ,
112
+ "type" => "roles" ,
112
113
"name" => "admin" ,
113
114
"links" => {
114
115
"author" => { "linkage" => { "type" => "authors" , "id" => "1" } }
115
116
}
116
117
} , {
117
118
"id" => "2" ,
119
+ "type" => "roles" ,
118
120
"name" => "colab" ,
119
121
"links" => {
120
122
"author" => { "linkage" => { "type" => "authors" , "id" => "1" } }
121
123
}
122
- } ]
123
- }
124
- assert_equal expected_linked , response [ 'linked ' ]
124
+ }
125
+ ]
126
+ assert_equal expected_linked , response [ 'included ' ]
125
127
end
126
128
127
129
def test_render_resource_with_nested_include
128
130
get :render_resource_with_nested_include
129
131
response = JSON . parse ( @response . body )
130
- assert response . key? 'linked '
131
- assert_equal 1 , response [ 'linked' ] [ 'authors '] . size
132
- assert_equal 'Anonymous' , response [ 'linked' ] [ 'authors '] . first [ 'name' ]
132
+ assert response . key? 'included '
133
+ assert_equal 1 , response [ 'included ' ] . size
134
+ assert_equal 'Anonymous' , response [ 'included ' ] . first [ 'name' ]
133
135
end
134
136
135
137
def test_render_collection_without_include
136
138
get :render_collection_without_include
137
139
response = JSON . parse ( @response . body )
138
- refute response . key? 'linked '
140
+ refute response . key? 'included '
139
141
end
140
142
141
143
def test_render_collection_with_include
142
144
get :render_collection_with_include
143
145
response = JSON . parse ( @response . body )
144
- assert response . key? 'linked '
146
+ assert response . key? 'included '
145
147
end
146
148
147
149
def test_render_resource_with_nested_attributes_even_when_missing_associations
148
150
get :render_resource_with_missing_nested_has_many_include
149
151
response = JSON . parse ( @response . body )
150
- assert response . key? 'linked '
151
- refute response [ 'linked' ] . key? 'roles'
152
+ assert response . key? 'included '
153
+ refute has_type? ( response [ 'included' ] , 'roles' )
152
154
end
153
155
154
156
def test_render_collection_with_missing_nested_has_many_include
155
157
get :render_collection_with_missing_nested_has_many_include
156
158
response = JSON . parse ( @response . body )
157
- assert response . key? 'linked'
158
- assert response [ 'linked' ] . key? 'roles'
159
+ assert response . key? 'included'
160
+ assert has_type? ( response [ 'included' ] , 'roles' )
161
+ end
162
+
163
+ def has_type? ( collection , value )
164
+ collection . detect { |i | i [ 'type' ] == value }
159
165
end
166
+
160
167
end
161
168
end
162
169
end
0 commit comments