Skip to content

Commit

Permalink
Fixes update with nested observable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rdiazv committed Jun 30, 2017
1 parent cc5e55a commit 14d3341
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions __tests__/Model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,28 @@ describe('Model', () => {
expect(model.get('album')).toBe(item.album)
expect(model.request.label).toBe('updating')
})

it('sends merged attributes on the request', () => {
const adapter = apiClient()

spy = jest.spyOn(adapter, 'put')
model.save({
name,
tracks: [
{ name: 'Track 1' },
{ name: 'Track 2' }
]
})

expect(spy).toHaveBeenCalledTimes(1)
expect(spy.mock.calls[0][1]).toEqual({
name: 'dylan',
tracks: [
{ name: 'Track 1' },
{ name: 'Track 2' }
]
})
})
})

describe('and its not patching', () => {
Expand All @@ -311,6 +333,29 @@ describe('Model', () => {
expect(model.get('album')).toBe('kind of blue')
expect(model.request.label).toBe('updating')
})

it('sends merged attributes on the request', () => {
const adapter = apiClient()

spy = jest.spyOn(adapter, 'put')
model.save({
name,
tracks: [
{ name: 'Track 1' },
{ name: 'Track 2' }
]
}, { patch: false })

expect(spy).toHaveBeenCalledTimes(1)
expect(spy.mock.calls[0][1]).toEqual({
...item,
name: 'dylan',
tracks: [
{ name: 'Track 1' },
{ name: 'Track 2' }
]
})
})
})

describe('when it fails', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class Model {
let newAttributes
let data
const label: Label = 'updating'
const originalAttributes = this.attributes.toJS()
const originalAttributes = this.toJS()

if (patch) {
newAttributes = Object.assign({}, originalAttributes, attributes)
Expand Down

0 comments on commit 14d3341

Please sign in to comment.