Skip to content

Fix resource serialization involving last_result_set #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- [#351](https://github.com/JsonApiClient/json_api_client/pull/351) - Remove rudimental `last_result_set` relationship from serializer

## 1.13.0

- [#348](https://github.com/JsonApiClient/json_api_client/pull/348) - add NestedParamPaginator to address inconsistency in handling of pagination query string params (issue [#347](https://github.com/JsonApiClient/json_api_client/issues/347)).
Expand Down
2 changes: 0 additions & 2 deletions lib/json_api_client/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ def save
self.attributes = updated.attributes
self.links.attributes = updated.links.attributes
self.relationships.attributes = updated.relationships.attributes
self.relationships.last_result_set = last_result_set
clear_changes_information
self.relationships.clear_changes_information
_clear_cached_relationships
Expand All @@ -477,7 +476,6 @@ def destroy
false
else
mark_as_destroyed!
self.relationships.last_result_set = nil
_clear_cached_relationships
_clear_belongs_to_params
true
Expand Down
23 changes: 23 additions & 0 deletions test/unit/serializing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ def test_as_json
assert_equal expected, resource.first.as_json
end

def test_as_json_involving_last_result_set
expected = {
'type' => 'articles',
'id' => '1',
'attributes' => {
'title' => 'Rails is Omakase'
}
}
stub_request(:post, "http://example.com/articles")
.to_return(headers: {content_type: "application/vnd.api+json"}, body: {
data: [{
type: "articles",
id: "1",
attributes: {
title: "Rails is Omakase"
}
}]
}.to_json)

resource = Article.create
assert_equal expected, resource.as_json
end

def test_as_json_api
expected = {
'type' => 'articles',
Expand Down