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

[DOC beta] Assert that both modelName and id are passed to peekRecord #4998

Merged
merged 2 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ Store = Service.extend({
peekRecord(modelName, id) {
heimdall.increment(peekRecord);
assert(`You need to pass a model name to the store's peekRecord method`, isPresent(modelName));
assert(`You need to pass both a model name and id to the store's peekRecord method`, isPresent(modelName) && isPresent(id));
assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
let normalizedModelName = normalizeModelName(modelName);

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/store/peek-record-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { run } from '@ember/runloop';
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';
import testInDebug from 'dummy/tests/helpers/test-in-debug';

import { module, test } from 'qunit';

Expand Down Expand Up @@ -40,3 +42,20 @@ test('peekRecord should return null if the record is not in the store ', functio
assert.equal(null, store.peekRecord('person', 1), 'peekRecord returns null if the corresponding record is not in the store');
});
});

testInDebug('peekRecord should assert if not passed both model name and id', function(assert) {
run(() => {
assert.expectAssertion(() => {
store.peekRecord('my-id');
}, /You need to pass both a model name and id/);
});
});

testInDebug('peekRecord should assert if passed a model class instead of model name', function(assert) {
run(() => {
assert.expectAssertion(() => {
let modelClass = Ember.Object.extend();
store.peekRecord(modelClass, 'id');
}, /Passing classes to store methods has been removed/);
});
});