Skip to content

Commit b41451c

Browse files
committed
Make tests pass
1 parent 3dd6ccc commit b41451c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/serializers/associations_test.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ def blog_id
159159
end
160160
end
161161

162-
actual = serializable(post, adapter: :json_api, serializer: BelongsToBlogModelSerializer).as_json
162+
actual =
163+
begin
164+
original_option = BelongsToBlogModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship
165+
BelongsToBlogModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
166+
serializable(post, adapter: :json_api, serializer: BelongsToBlogModelSerializer).as_json
167+
ensure
168+
BelongsToBlogModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = original_option
169+
end
163170
expected = { data: { id: '1', type: 'posts', relationships: { blog: { data: { id: '5', type: 'blogs' } } } } }
164171

165172
assert_equal expected, actual
@@ -189,7 +196,14 @@ def test_belongs_to_allows_id_overwriting
189196
}
190197
post = BelongsToExternalBlogModel.new(attributes)
191198

192-
actual = serializable(post, adapter: :json_api, serializer: BelongsToExternalBlogModelSerializer).as_json
199+
actual =
200+
begin
201+
original_option = BelongsToExternalBlogModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship
202+
BelongsToExternalBlogModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
203+
serializable(post, adapter: :json_api, serializer: BelongsToExternalBlogModelSerializer).as_json
204+
ensure
205+
BelongsToExternalBlogModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = original_option
206+
end
193207
expected = { data: { id: '1', type: 'posts', relationships: { :'external-blog' => { data: { id: '6', type: 'external-blogs' } } } } }
194208

195209
assert_equal expected, actual

0 commit comments

Comments
 (0)