Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayneP authored Aug 28, 2023
2 parents acd2fa0 + 7e6f5bd commit 263811a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/shopify_api/rest/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,18 @@ def attributes_to_update
self.class.read_only_attributes&.include?("@#{attribute}".to_sym)
end

HashDiff::Comparison.new(
diff = HashDiff::Comparison.new(
deep_stringify_keys(original_state_for_update),
deep_stringify_keys(to_hash(true)),
).left_diff

diff.each do |attribute, value|
if value.is_a?(Hash) && value[0] == HashDiff::NO_VALUE
diff[attribute] = send(attribute)
end
end

diff
end

sig { returns(Symbol) }
Expand Down
26 changes: 26 additions & 0 deletions test/clients/base_rest_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@ def test_loads_unknown_attribute
assert_equal("some-value", resource.to_hash["unknown"])
end

def test_saves_removing_children
draft_order_data = {
"id" => 1124601987358,
"line_items" => [{
"id" => 58266522976542,
"title" => "The Minimal Snowboard",
"price" => "885.95",
}],
}
draft_order = ShopifyAPI::DraftOrder.create_instance(
session: @session,
data: draft_order_data,
)

body = draft_order_data.dup
body["line_items"] = []
stubbed_request = stub_request(:put, "#{@prefix}/draft_orders/#{draft_order_data.dig("id")}.json")
.with(body: hash_including("draft_order": { line_items: [] }))
.to_return(status: 200)

draft_order.line_items = []
draft_order.save

assert_requested(stubbed_request)
end

def test_loads_unknown_attribute_with_special_character
body = { fake_resource: { id: 1, attribute: "attribute", "unknown?": "some-value" } }.to_json

Expand Down

0 comments on commit 263811a

Please sign in to comment.