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

adds a more robust test around reload #5416

Merged
merged 1 commit into from
Apr 4, 2018
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
41 changes: 41 additions & 0 deletions tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,47 @@ test("store#findRecord { reload: true } ignores cached record and reloads record
});
});


test("store#findRecord { reload: true } ignores cached record and reloads record from server even after previous findRecord", function(assert) {
assert.expect(5);
let calls = 0;

const testAdapter = DS.JSONAPIAdapter.extend({
shouldReloadRecord(store, type, id, snapshot) {
assert.ok(false, 'shouldReloadRecord should not be called when { reload: true }');
},
findRecord() {
calls++;
return resolve({
data: {
type: 'car',
id: '1',
attributes: {
make: 'BMC',
model: calls === 1 ? 'Mini' : 'Princess'
}
}
});
}
});

initializeStore(testAdapter);

let car = run(() => store.findRecord('car', '1'));

assert.equal(calls, 1, 'We made one call to findRecord');
assert.equal(car.get('model'), 'Mini', 'cached car has expected model');

run(() => {
let promiseCar = store.findRecord('car', 1, { reload: true });

assert.ok(promiseCar.get('model') === undefined, `We don't have early access to local data`);
});

assert.equal(calls, 2, 'We made a second call to findRecord');
assert.equal(car.get('model'), 'Princess', 'cached record ignored, record reloaded via server');
});

test("store#findRecord { backgroundReload: false } returns cached record and does not reload in the background", function(assert) {
assert.expect(2);

Expand Down