Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT BUGFIX] enable canonical state updates to deleted records #5408

Merged
merged 4 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion addon/-private/system/model/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ const RootState = {
},

willCommit() { },
didCommit() { }
didCommit() { },
pushedData() {}
},

invalid: {
Expand Down
Empty file.
50 changes: 49 additions & 1 deletion tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ module('unit/model - DS.Model', {
beforeEach() {
Person = DS.Model.extend({
name: DS.attr('string'),
isDrugAddict: DS.attr('boolean')
isDrugAddict: DS.attr('boolean'),
isArchived: DS.attr()
});
Person.toString = () => 'person';

env = setupStore({
adapter: DS.JSONAPIAdapter,
person: Person
});
store = env.store;
Expand Down Expand Up @@ -567,6 +569,52 @@ test('supports pushedData in root.deleted.uncommitted', function(assert) {
});
});

test('supports pushedData in root.deleted.saved', function(assert) {
let { adapter } = env;

adapter.shouldBackgroundReloadRecord = () => false;
adapter.deleteRecord = () => {
return Ember.RSVP.resolve();
};

let record = run(() => store.push({
data: {
type: 'person',
id: '1',
attributes: {
isArchived: false
}
}
}));

run(() => {
record.destroyRecord().then(() => {
let currentState = record._internalModel.currentState;

assert.ok(currentState.stateName === 'root.deleted.saved',
'record is in a persisted deleted state');
assert.equal(get(record, 'isDeleted'), true);
assert.ok(store.peekRecord('person', '1') !== null, 'the deleted person is not removed from store (no unload called)');
});
});

run(() => {
try {
store.push({
data: {
type: 'person',
id: '1',
attributes: {
isArchived: true
}
}
})
} catch (e) {
assert.ok(false, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this try/catch achieve?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this try/catch achieve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can use expectAssertion here instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjdivad oh wait, actually, I can't unless there's a corollary? I basically want a "expect no assertion"

}
});
});

test('currentState is accessible when the record is created', function(assert) {
let hash = {
data: {
Expand Down