-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5249 from emberjs/hjdivad/test-client-side-delete
Fix client-side delete + resurrection
- Loading branch information
Showing
2 changed files
with
92 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { resolve } from 'rsvp'; | ||
import { run } from '@ember/runloop'; | ||
import setupStore from 'dummy/tests/helpers/store'; | ||
|
||
import { module, test } from 'qunit'; | ||
|
||
import DS from 'ember-data'; | ||
|
||
module('integration/adapter/store-adapter - client-side delete', { | ||
beforeEach() { | ||
this.Bookstore = DS.Model.extend({ | ||
books: DS.hasMany('book', { async: false, inverse: 'bookstore' }) | ||
}); | ||
this.Book = DS.Model.extend({ | ||
bookstore: DS.belongsTo('bookstore', { inverse: 'books' }) | ||
}); | ||
|
||
this.env = setupStore({ | ||
bookstore: this.Bookstore, | ||
book: this.Book | ||
}); | ||
this.store = this.env.store; | ||
this.adapter = this.env.adapter; | ||
}, | ||
|
||
afterEach() { | ||
run(this.env.container, 'destroy'); | ||
} | ||
}); | ||
|
||
test('client-side deleted records can be added back from an inverse', function(assert) { | ||
this.adapter.deleteRecord = function (store, modelClass, snapshot) { | ||
if (snapshot.adapterOptions.clientSideDelete) { | ||
return resolve(); | ||
} | ||
|
||
assert.ok(false, 'unreachable'); | ||
} | ||
|
||
run(() => this.store.push({ | ||
data: { | ||
id: '1', | ||
type: 'bookstore', | ||
relationships: { | ||
books: { | ||
data: [{ | ||
id: '1', type: 'book' | ||
}, { | ||
id: '2', type: 'book' | ||
}] | ||
} | ||
} | ||
}, included: [{ | ||
id: '1', | ||
type: 'book' | ||
}, { | ||
id: '2', | ||
type: 'book' | ||
}] | ||
})); | ||
|
||
let bookstore = this.store.peekRecord('bookstore', '1'); | ||
assert.deepEqual(bookstore.get('books').mapBy('id'), ['1', '2'], 'initial hasmany loaded'); | ||
|
||
let book2 = this.store.peekRecord('book', '2'); | ||
return run(() => book2.destroyRecord({ adapterOptions: { clientSideDelete: true } })).then(() => { | ||
run(() => book2.unloadRecord()); | ||
assert.equal(this.store.hasRecordForId('book', '2'), false, 'book 2 unloaded'); | ||
assert.deepEqual(bookstore.get('books').mapBy('id'), ['1'], 'one book client-side deleted'); | ||
|
||
run(() => this.store.push({ | ||
data: { | ||
id: '2', | ||
type: 'book', | ||
relationships: { | ||
bookstore: { | ||
data: { | ||
id: '1', | ||
type: 'bookstore' | ||
} | ||
} | ||
} | ||
} | ||
})); | ||
|
||
assert.deepEqual(bookstore.get('books').mapBy('id'), ['1', '2'], 'the deleted book (with same id) is pushed back into the store'); | ||
}); | ||
}); |