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

tests for unload + resurrect + remote relationship state #5040

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 98 additions & 4 deletions tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,25 +508,119 @@ test("after unloading a record, the record can be fetched again immediately", fu
id: '1',
attributes: {
name: 'Adam Sunderland'
},
relationships: {
cars: {
data: [
{
id: 1,
type: 'car'
}
]
}
}
}
},
included: [
{
type: 'car',
id: 1,
attributes: {
make: 'jeep',
model: 'wrangler'
}
}
]
});
});

const internalModel = record._internalModel;
assert.equal(internalModel.currentState.stateName, 'root.loaded.saved', 'We are loaded initially');

// we test that we can sync call unloadRecord followed by findRecord
run(function() {
return run(function() {
assert.equal(record.get('cars.firstObject.make'), 'jeep');
store.unloadRecord(record);
assert.equal(record.isDestroying, true, 'the record is destroying');
assert.equal(internalModel.currentState.stateName, 'root.empty', 'We are unloaded after unloadRecord');
store.findRecord('person', '1');
return store.findRecord('person', '1').then(record => {
assert.equal(record.get('cars.length'), 1);
assert.equal(record._internalModel, internalModel, 'new record, has old internal model');
assert.equal(internalModel.currentState.stateName, 'root.loaded.saved', 'We are loaded after findRecord');
})
});

assert.equal(internalModel.currentState.stateName, 'root.loaded.saved', 'We are loaded after findRecord');
});

test("after unloading a record, the record can be fetched again immediately (purge relationship)", function(assert) {
const store = env.store;
let record;

// stub findRecord
env.adapter.findRecord = () => {
return Ember.RSVP.Promise.resolve({
data: {
type: 'person',
id: '1',
attributes: {
name: 'Adam Sunderland'
},
relationships: {
cars: { data: null }
}
}
});
};

// populate initial record
run(function() {
record = store.push({
data: {
type: 'person',
id: '1',
attributes: {
name: 'Adam Sunderland'
},
relationships: {
cars: {
data: [
{
id: 1,
type: 'car'
}
]
}
}
},
included: [
{
type: 'car',
id: 1,
attributes: {
make: 'jeep',
model: 'wrangler'
}
}
]
});
});

const internalModel = record._internalModel;
assert.equal(internalModel.currentState.stateName, 'root.loaded.saved', 'We are loaded initially');

// we test that we can sync call unloadRecord followed by findRecord
return run(function() {
assert.equal(record.get('cars.firstObject.make'), 'jeep');
store.unloadRecord(record);
assert.equal(record.isDestroying, true, 'the record is destroying');
assert.equal(internalModel.currentState.stateName, 'root.empty', 'We are unloaded after unloadRecord');
return store.findRecord('person', '1').then(record => {
assert.equal(record.get('cars.length'), 0);
assert.equal(record._internalModel, internalModel, 'new record, has old internal model');
assert.equal(internalModel.currentState.stateName, 'root.loaded.saved', 'We are loaded after findRecord');
})
});

});

test("after unloading a record, the record can be fetched again soon there after", function(assert) {
const store = env.store;
Expand Down