diff --git a/__tests__/Model.spec.js b/__tests__/Model.spec.js index d356c83..0656043 100644 --- a/__tests__/Model.spec.js +++ b/__tests__/Model.spec.js @@ -140,6 +140,22 @@ describe('Model', () => { model.save(item) expect(collection.create).toBeCalledWith(model, { optimistic: true }) }) + + it('sends merged attributes on the request', () => { + const adapter = apiClient() + const spy = jest.spyOn(adapter, 'post') + + model.save({ name }) + + expect(spy).toHaveBeenCalledTimes(1) + expect(spy.mock.calls[0][1]).toEqual({ + name: 'dylan', + album: 'kind of blue' + }) + + spy.mockReset() + spy.mockRestore() + }) }) describe('and it does not have a collection', () => { @@ -147,6 +163,22 @@ describe('Model', () => { model.collection = null }) + it('sends merged attributes on the request', () => { + const adapter = apiClient() + const spy = jest.spyOn(adapter, 'post') + + model.save({ name }) + + expect(spy).toHaveBeenCalledTimes(1) + expect(spy.mock.calls[0][1]).toEqual({ + name: 'dylan', + album: 'kind of blue' + }) + + spy.mockReset() + spy.mockRestore() + }) + describe('if its optimistic (default)', () => { it('it sets model straight away', () => { model.save({ name }) diff --git a/src/Model.js b/src/Model.js index 36b57d6..e0d541b 100644 --- a/src/Model.js +++ b/src/Model.js @@ -203,7 +203,7 @@ export default class Model { if (this.collection) { return this.collection.create(this, { optimistic }) } else { - return this._create(attributes, { optimistic }) + return this._create(this.attributes.toJS(), { optimistic }) } }