@@ -103,23 +103,29 @@ def test_relationship_simple_link
103
103
self : '//example.com/link_author/relationships/bio'
104
104
}
105
105
}
106
- assert_relationship ( :bio , expected )
106
+
107
+ author = @author . dup
108
+ assert_author_relationship_serialized ( expected , author , :bio )
107
109
end
108
110
109
111
def test_relationship_block_link
110
112
expected = {
111
113
data : { id : '1337' , type : 'profiles' } ,
112
114
links : { related : '//example.com/profiles/1337' }
113
115
}
114
- assert_relationship ( :profile , expected )
116
+
117
+ author = @author . dup
118
+ assert_author_relationship_serialized ( expected , author , :profile )
115
119
end
116
120
117
121
def test_relationship_nil_link
118
- @author . profile . id = 123
119
122
expected = {
120
123
data : { id : '123' , type : 'profiles' }
121
124
}
122
- assert_relationship ( :profile , expected )
125
+
126
+ author = @author . dup
127
+ author . profile . id = 123
128
+ assert_author_relationship_serialized ( expected , author , :profile )
123
129
end
124
130
125
131
def test_relationship_block_link_href
@@ -129,7 +135,9 @@ def test_relationship_block_link_href
129
135
related : { href : '//example.com/locations/1337' }
130
136
}
131
137
}
132
- assert_relationship ( :locations , expected )
138
+
139
+ author = @author . dup
140
+ assert_author_relationship_serialized ( expected , author , :locations )
133
141
end
134
142
135
143
def test_relationship_block_link_href_and_meta
@@ -142,7 +150,9 @@ def test_relationship_block_link_href_and_meta
142
150
}
143
151
}
144
152
}
145
- assert_relationship ( :posts , expected )
153
+
154
+ author = @author . dup
155
+ assert_author_relationship_serialized ( expected , author , :posts )
146
156
end
147
157
148
158
def test_relationship_block_link_meta
@@ -154,27 +164,33 @@ def test_relationship_block_link_meta
154
164
}
155
165
}
156
166
}
157
- assert_relationship ( :comments , expected )
167
+
168
+ author = @author . dup
169
+ assert_author_relationship_serialized ( expected , author , :comments )
158
170
end
159
171
160
172
def test_relationship_meta
161
173
expected = {
162
174
data : [ { id : 'from-serializer-method' , type : 'roles' } ] ,
163
175
meta : { count : 1 }
164
176
}
165
- assert_relationship ( :roles , expected )
177
+
178
+ author = @author . dup
179
+ assert_author_relationship_serialized ( expected , author , :roles )
166
180
end
167
181
168
182
def test_relationship_not_including_data
169
- @author . define_singleton_method ( :read_attribute_for_serialization ) do |attr |
170
- fail 'should not be called' if attr == :blog
171
- super ( attr )
172
- end
173
183
expected = {
174
184
links : { self : '//example.com/link_author/relationships/blog' }
175
185
}
186
+
187
+ author = @author . dup
188
+ author . define_singleton_method ( :read_attribute_for_serialization ) do |attr |
189
+ fail 'should not be called' if attr == :blog
190
+ super ( attr )
191
+ end
176
192
assert_nothing_raised do
177
- assert_relationship ( :blog , expected )
193
+ assert_author_relationship_serialized ( expected , author , :blog )
178
194
end
179
195
end
180
196
@@ -183,7 +199,9 @@ def test_relationship_including_data_explicit
183
199
data : { id : '1337' , type : 'authors' } ,
184
200
meta : { name : 'Dan Brown' }
185
201
}
186
- assert_relationship ( :reviewer , expected )
202
+
203
+ author = @author . dup
204
+ assert_author_relationship_serialized ( expected , author , :reviewer )
187
205
end
188
206
189
207
def test_relationship_with_everything
@@ -197,14 +215,17 @@ def test_relationship_with_everything
197
215
} ,
198
216
meta : { liked : true }
199
217
}
200
- assert_relationship ( :likes , expected )
218
+
219
+ author = @author . dup
220
+ assert_author_relationship_serialized ( expected , author , :likes )
201
221
end
202
222
203
223
private
204
224
205
- def assert_relationship ( relationship_name , expected )
206
- hash = serializable ( @author , adapter : :json_api ) . serializable_hash
207
- assert_equal ( expected , hash [ :data ] [ :relationships ] [ relationship_name ] )
225
+ def assert_author_relationship_serialized ( expected , author , relationship_name )
226
+ hash = serializable ( author , adapter : :json_api ) . serializable_hash
227
+ actual_relationship = hash [ :data ] [ :relationships ] [ relationship_name ]
228
+ assert_equal ( expected , actual_relationship )
208
229
end
209
230
end
210
231
end
0 commit comments