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

Use string model names in debug adapter #3203

Merged
merged 1 commit into from
Jun 5, 2015
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
18 changes: 13 additions & 5 deletions packages/ember-data/lib/system/debug/debug-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Model from "ember-data/system/model";
var get = Ember.get;
var capitalize = Ember.String.capitalize;
var underscore = Ember.String.underscore;
const { assert } = Ember;

/**
Extend `Ember.DataAdapter` with ED specific code.
Expand Down Expand Up @@ -42,11 +43,18 @@ export default Ember.DataAdapter.extend({
return columns;
},

getRecords: function(modelNameOrFactory) {
// TODO: Ask Teddy what we should do here.
// Ideally this should always get passed a string.

var modelName = typeof modelNameOrFactory === 'string' ? modelNameOrFactory : modelNameOrFactory.modelName;
getRecords: function(modelClass, modelName) {
if (arguments.length < 2) {
// Legacy Ember.js < 1.13 support
let containerKey = modelClass._debugContainerKey;
if (containerKey) {
let match = containerKey.match(/model:(.*)/);
if (match) {
modelName = match[1];
}
}
}
assert("Cannot find model name. Please upgrade to Ember.js >= 1.13 for Ember Inspector support", !!modelName);
return this.get('store').all(modelName);
},

Expand Down
16 changes: 12 additions & 4 deletions packages/ember-data/tests/integration/debug-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ module("DS.DebugAdapter", {
App.Post = DS.Model.extend({
title: DS.attr('string')
});

// TODO: Remove this when Ember is upgraded to >= 1.13
App.Post.reopenClass({
modelName: 'post'
_debugContainerKey: 'model:post'
});

});
Expand All @@ -26,7 +28,7 @@ module("DS.DebugAdapter", {

debugAdapter.reopen({
getModelTypes: function() {
return Ember.A([{ klass: App.__container__.lookupFactory('model:post'), name: 'App.Post' }]);
return Ember.A([{ klass: App.__container__.lookupFactory('model:post'), name: 'post' }]);
}
});
},
Expand All @@ -40,7 +42,7 @@ test("Watching Model Types", function() {

var added = function(types) {
equal(types.length, 1);
equal(types[0].name, 'App.Post');
equal(types[0].name, 'post');
equal(types[0].count, 0);
strictEqual(types[0].object, store.modelFor('post'));
};
Expand Down Expand Up @@ -74,7 +76,13 @@ test("Watching Records", function() {
removedCount = count;
};

debugAdapter.watchRecords(App.__container__.lookupFactory('model:post'), recordsAdded, recordsUpdated, recordsRemoved);
let modelClassOrName;
if (debugAdapter.get('acceptsModelName')) {
modelClassOrName = 'post';
} else {
modelClassOrName = App.__container__.lookupFactory('model:post');
}
debugAdapter.watchRecords(modelClassOrName, recordsAdded, recordsUpdated, recordsRemoved);

equal(get(addedRecords, 'length'), 1);
record = addedRecords[0];
Expand Down