Skip to content

Commit 6b611e8

Browse files
garytaylorchingor13
authored andcommitted
Fixes #237 Resource links missing on create (#238)
1 parent af6bd62 commit 6b611e8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/json_api_client/resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def save
409409
mark_as_persisted!
410410
if updated = last_result_set.first
411411
self.attributes = updated.attributes
412+
self.links.attributes = updated.links.attributes
412413
self.relationships.attributes = updated.relationships.attributes
413414
clear_changes_information
414415
end

test/unit/creation_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def setup
3535
id: "1",
3636
attributes: {
3737
title: "Rails is Omakase"
38+
},
39+
links: {
40+
self: "http://example.com/articles/1",
41+
other: {
42+
href: "http://example.com/other"
43+
}
3844
}
3945
}
4046
}.to_json)
@@ -68,6 +74,16 @@ def test_can_create_with_new_record_and_save
6874
assert_equal "1", article.id
6975
end
7076

77+
def test_can_create_with_links
78+
article = Article.new({
79+
title: "Rails is Omakase"
80+
})
81+
82+
assert article.save
83+
assert article.persisted?
84+
assert_equal "http://example.com/articles/1", article.links.self
85+
end
86+
7187
def test_can_create_with_new_record_with_relationships_and_save
7288
stub_request(:post, "http://example.com/articles")
7389
.with(headers: {content_type: "application/vnd.api+json", accept: "application/vnd.api+json"}, body: {

0 commit comments

Comments
 (0)