This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
Fix failing test for model update with custom id attribute. #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit fixes a failing test for model updates with a custom id
attribute. It changes the strategy how updated fields from server-side
are merged with locally synced models. Instead of merging objects with
_.extend()
, the received response is merged throughset()
method.Background
As far as I can judge (I'm very new to the codebase), this issue might
have been introduced with PR36, which introduced merging model after
update. Changing the type of the second argument to
localsync
frombb.Model to object seemed to cause the unwanted side effect that the
custom id attribute is no longer discoverable from within
localsync
.Hence, the fixing strategy has been developed around the idea to adhere
to
localsync
type signature. The easiest solution seems to justoverwrite the existing local model instance with the received response
from server through
model.set()
, after previously having parsed theresponse through
model.parse()
(just to be compatible to the overallidea of being agnostic from response formats).
Motivation
I developed this fix in order to get the test suite to all green back
again. I stumbled over the failing test after I checked out the code for
investigation (in pursuit of a completely unrelated thing).
Notes
This is my first contribution to the codebase. Please review my change
thoroughly. I ran the test suite against Chromium and Firefox browsers.
Thanks for your efforts on backbone.dualStorage!