Skip to content

Commit

Permalink
[DOC beta] Assert that both modelName and id are passed to peekRecord
Browse files Browse the repository at this point in the history
Adds expectAssertion test for the new assertion, as well as an
expectAssertion test for the existing assertion that a model name
(string) must be passed instead of a model class.
  • Loading branch information
bantic committed Jun 26, 2017
1 parent 69cdc9e commit 42b5bf2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,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
18 changes: 18 additions & 0 deletions tests/unit/store/peek-record-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -41,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/);
});
});

0 comments on commit 42b5bf2

Please sign in to comment.