Skip to content

Commit 9a88740

Browse files
committed
fixup: Preserve nil links
Just as nil attributes are still serialized, this commit ensures that nil links are also serialized. If nil links are not serialized, Spraypaint does not remove the old link value after an update operation.
1 parent 3c309f3 commit 9a88740

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/graphiti/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def respond_to_missing?(method_name, include_private = true)
5353
def add_links!(hash)
5454
return unless @resource.respond_to?(:links?)
5555

56-
hash[:links] = @resource.links(@object).compact if @resource.links?
56+
hash[:links] = @resource.links(@object) if @resource.links?
5757
end
5858

5959
def strip_relationships!(hash)

spec/serialization_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,10 @@ def classification
14051405
resource.link :test_link do |model| nil end
14061406
end
14071407

1408-
specify "are omitted" do
1408+
specify "are still included" do
14091409
render
1410-
expect(json["data"][0]["links"]).not_to have_key("test_link")
1410+
expect(json["data"][0]["links"]).to have_key("test_link")
1411+
expect(json["data"][0]["links"]["test_link"]).to eq(nil)
14111412
end
14121413
end
14131414
end

0 commit comments

Comments
 (0)