Skip to content

Commit c2deea5

Browse files
committed
Fix resource serialization involving last_result_set
1 parent 02e0fb3 commit c2deea5

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- [#351](https://github.com/JsonApiClient/json_api_client/pull/351) - Remove rudimental `last_result_set` relationship from serializer
6+
57
## 1.12.2
68

79
- [#350](https://github.com/JsonApiClient/json_api_client/pull/350) - fix resource including with blank `relationships` response data

lib/json_api_client/resource.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ def save
458458
self.attributes = updated.attributes
459459
self.links.attributes = updated.links.attributes
460460
self.relationships.attributes = updated.relationships.attributes
461-
self.relationships.last_result_set = last_result_set
462461
clear_changes_information
463462
self.relationships.clear_changes_information
464463
_clear_cached_relationships
@@ -477,7 +476,6 @@ def destroy
477476
false
478477
else
479478
mark_as_destroyed!
480-
self.relationships.last_result_set = nil
481479
_clear_cached_relationships
482480
_clear_belongs_to_params
483481
true

test/unit/serializing_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,29 @@ def test_as_json
5252
assert_equal expected, resource.first.as_json
5353
end
5454

55+
def test_as_json_involving_last_result_set
56+
expected = {
57+
'type' => 'articles',
58+
'id' => '1',
59+
'attributes' => {
60+
'title' => 'Rails is Omakase'
61+
}
62+
}
63+
stub_request(:post, "http://example.com/articles")
64+
.to_return(headers: {content_type: "application/vnd.api+json"}, body: {
65+
data: [{
66+
type: "articles",
67+
id: "1",
68+
attributes: {
69+
title: "Rails is Omakase"
70+
}
71+
}]
72+
}.to_json)
73+
74+
resource = Article.create
75+
assert_equal expected, resource.as_json
76+
end
77+
5578
def test_as_json_api
5679
expected = {
5780
'type' => 'articles',

0 commit comments

Comments
 (0)