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

Failing test: findRecord should not cache if includes differ #7687

Closed
Closed
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
50 changes: 50 additions & 0 deletions packages/-ember-data/tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,56 @@ module('integration/store - findRecord', function (hooks) {
assert.strictEqual(car1, car2, 'we receive the same car back');
});

test('store#findRecord does not cache the inflight requests when includes differ', async function (assert) {
assert.expect(2);

let calls = 0;
let resolveHandler;
let result = {
data: {
type: 'car',
id: '1',
attributes: {
make: 'BMC',
model: 'Mini',
},
},
};

const testAdapter = DS.JSONAPIAdapter.extend({
shouldReloadRecord(store, type, id, snapshot) {
assert.ok(false, 'shouldReloadRecord should not be called when { reload: true }');
},
async findRecord() {
calls++;

return new Promise((resolve) => {
resolveHandler = resolve;
});
},
});

this.owner.register('adapter:application', testAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
let firstPromise, secondPromise;

run(() => {
firstPromise = store.findRecord('car', '1', { include: 'driver' });
});

run(() => {
secondPromise = store.findRecord('car', '1', { include: 'engine' });
});

assert.strictEqual(calls, 2, 'We made two calls to findRecord');

resolveHandler(result);
let car1 = await firstPromise;
let car2 = await secondPromise;

assert.strictEqual(car1, car2, 'we receive the same car back');
});

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

Expand Down