diff --git a/packages/activemodel-adapter/lib/system/active-model-serializer.js b/packages/activemodel-adapter/lib/system/active-model-serializer.js index 9ba54166f00..cd41362edc2 100644 --- a/packages/activemodel-adapter/lib/system/active-model-serializer.js +++ b/packages/activemodel-adapter/lib/system/active-model-serializer.js @@ -117,12 +117,12 @@ var ActiveModelSerializer = RESTSerializer.extend({ relationship keys. @method keyForRelationship - @param {String} relationshipTypeKey + @param {String} relationshipModelName @param {String} kind @return String */ - keyForRelationship: function(relationshipTypeKey, kind) { - var key = decamelize(relationshipTypeKey); + keyForRelationship: function(relationshipModelName, kind) { + var key = decamelize(relationshipModelName); if (kind === "belongsTo") { return key + "_id"; } else if (kind === "hasMany") { diff --git a/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-modelname-test.js b/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-modelname-test.js index 27fa5b5cb5c..958281d5ac3 100644 --- a/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-modelname-test.js +++ b/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-modelname-test.js @@ -6,34 +6,35 @@ module("integration/active_model - AMS-namespaced-model-names", { SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), - evilMinions: DS.hasMany("evilMinion") + evilMinions: DS.hasMany('evil-minion') }); EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('superVillain'), + superVillain: DS.belongsTo('super-villain'), name: DS.attr('string') }); YellowMinion = EvilMinion.extend(); DoomsdayDevice = DS.Model.extend({ name: DS.attr('string'), - evilMinion: DS.belongsTo('evilMinion', { polymorphic: true }) + evilMinion: DS.belongsTo('evil-minion', { polymorphic: true }) }); MediocreVillain = DS.Model.extend({ name: DS.attr('string'), - evilMinions: DS.hasMany('evilMinion', { polymorphic: true }) + evilMinions: DS.hasMany('evil-minion', { polymorphic: true }) }); env = setupStore({ superVillain: SuperVillain, evilMinion: EvilMinion, 'evilMinions/yellowMinion': YellowMinion, doomsdayDevice: DoomsdayDevice, - mediocreVillain: MediocreVillain + mediocreVillain: MediocreVillain, + yellowMinion: YellowMinion }); - env.store.modelFor('superVillain'); - env.store.modelFor('evilMinion'); - env.store.modelFor('evilMinions/yellowMinion'); - env.store.modelFor('doomsdayDevice'); - env.store.modelFor('mediocreVillain'); + env.store.modelFor('super-villain'); + env.store.modelFor('evil-minion'); + env.store.modelFor('evil-minions/yellow-minion'); + env.store.modelFor('doomsday-device'); + env.store.modelFor('mediocre-villain'); env.registry.register('serializer:application', DS.ActiveModelSerializer); env.registry.register('serializer:-active-model', DS.ActiveModelSerializer); env.registry.register('adapter:-active-model', DS.ActiveModelAdapter); @@ -49,8 +50,8 @@ module("integration/active_model - AMS-namespaced-model-names", { test("serialize polymorphic", function() { var tom, ray; run(function() { - tom = env.store.createRecord('evilMinions/yellowMinion', { name: "Alex", id: "124" }); - ray = env.store.createRecord(DoomsdayDevice, { evilMinion: tom, name: "DeathRay" }); + tom = env.store.createRecord('evil-minions/yellow-minion', { name: "Alex", id: "124" }); + ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); }); var json = env.amsSerializer.serialize(ray._createSnapshot()); @@ -66,8 +67,8 @@ test("serialize polymorphic when type key is not camelized", function() { YellowMinion.modelName = 'evil-minions/yellow-minion'; var tom, ray; run(function() { - tom = env.store.createRecord(YellowMinion, { name: "Alex", id: "124" }); - ray = env.store.createRecord(DoomsdayDevice, { evilMinion: tom, name: "DeathRay" }); + tom = env.store.createRecord('yellow-minion', { name: "Alex", id: "124" }); + ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); }); var json = env.amsSerializer.serialize(ray._createSnapshot()); diff --git a/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js b/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js index e0a56034a1b..a259615348a 100644 --- a/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js +++ b/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js @@ -7,25 +7,25 @@ module("integration/active_model - ActiveModelSerializer", { SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), - homePlanet: DS.belongsTo("homePlanet"), - evilMinions: DS.hasMany("evilMinion") + homePlanet: DS.belongsTo('home-planet'), + evilMinions: DS.hasMany('evil-minion') }); HomePlanet = DS.Model.extend({ name: DS.attr('string'), - superVillains: DS.hasMany('superVillain', { async: true }) + superVillains: DS.hasMany('super-villain', { async: true }) }); EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('superVillain'), + superVillain: DS.belongsTo('super-villain'), name: DS.attr('string') }); YellowMinion = EvilMinion.extend(); DoomsdayDevice = DS.Model.extend({ name: DS.attr('string'), - evilMinion: DS.belongsTo('evilMinion', { polymorphic: true }) + evilMinion: DS.belongsTo('evil-minion', { polymorphic: true }) }); MediocreVillain = DS.Model.extend({ name: DS.attr('string'), - evilMinions: DS.hasMany('evilMinion', { polymorphic: true }) + evilMinions: DS.hasMany('evil-minion', { polymorphic: true }) }); env = setupStore({ superVillain: SuperVillain, @@ -35,12 +35,12 @@ module("integration/active_model - ActiveModelSerializer", { doomsdayDevice: DoomsdayDevice, mediocreVillain: MediocreVillain }); - env.store.modelFor('superVillain'); - env.store.modelFor('homePlanet'); - env.store.modelFor('evilMinion'); - env.store.modelFor('yellowMinion'); - env.store.modelFor('doomsdayDevice'); - env.store.modelFor('mediocreVillain'); + env.store.modelFor('super-villain'); + env.store.modelFor('home-planet'); + env.store.modelFor('evil-minion'); + env.store.modelFor('yellow-minion'); + env.store.modelFor('doomsday-device'); + env.store.modelFor('mediocre-villain'); env.registry.register('serializer:application', DS.ActiveModelSerializer); env.registry.register('serializer:-active-model', DS.ActiveModelSerializer); env.registry.register('adapter:-active-model', DS.ActiveModelAdapter); @@ -56,8 +56,8 @@ module("integration/active_model - ActiveModelSerializer", { test("serialize", function() { var tom; run(function() { - league = env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }); - tom = env.store.createRecord(SuperVillain, { firstName: "Tom", lastName: "Dale", homePlanet: league }); + league = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); + tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", homePlanet: league }); }); var json = env.amsSerializer.serialize(tom._createSnapshot()); @@ -71,7 +71,7 @@ test("serialize", function() { test("serializeIntoHash", function() { run(function() { - league = env.store.createRecord(HomePlanet, { name: "Umber", id: "123" }); + league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); }); var json = {}; @@ -87,7 +87,7 @@ test("serializeIntoHash", function() { test("serializeIntoHash with decamelized types", function() { HomePlanet.modelName = 'home-planet'; run(function() { - league = env.store.createRecord(HomePlanet, { name: "Umber", id: "123" }); + league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); }); var json = {}; @@ -103,7 +103,7 @@ test("serializeIntoHash with decamelized types", function() { test("normalize", function() { SuperVillain.reopen({ - yellowMinion: DS.belongsTo('yellowMinion') + yellowMinion: DS.belongsTo('yellow-minion') }); var superVillain_hash = { first_name: "Tom", last_name: "Dale", home_planet_id: "123", evil_minion_ids: [1,2] }; @@ -156,7 +156,7 @@ test("extractSingle", function() { }); run(function() { - env.store.find("superVillain", 1).then(function(minion) { + env.store.find('super-villain', 1).then(function(minion) { equal(minion.get('firstName'), "Tom"); }); }); @@ -182,7 +182,7 @@ test("extractArray", function() { }]); run(function() { - env.store.find("superVillain", 1).then(function(minion) { + env.store.find('super-villain', 1).then(function(minion) { equal(minion.get('firstName'), "Tom"); }); }); @@ -191,8 +191,8 @@ test("extractArray", function() { test("serialize polymorphic", function() { var tom, ray; run(function() { - tom = env.store.createRecord(YellowMinion, { name: "Alex", id: "124" }); - ray = env.store.createRecord(DoomsdayDevice, { evilMinion: tom, name: "DeathRay" }); + tom = env.store.createRecord('yellow-minion', { name: "Alex", id: "124" }); + ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); }); var json = env.amsSerializer.serialize(ray._createSnapshot()); @@ -208,8 +208,8 @@ test("serialize polymorphic when type key is not camelized", function() { YellowMinion.modelName = 'yellow-minion'; var tom, ray; run(function() { - tom = env.store.createRecord(YellowMinion, { name: "Alex", id: "124" }); - ray = env.store.createRecord(DoomsdayDevice, { evilMinion: tom, name: "DeathRay" }); + tom = env.store.createRecord('yellow-minion', { name: "Alex", id: "124" }); + ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); }); var json = env.amsSerializer.serialize(ray._createSnapshot()); @@ -220,7 +220,7 @@ test("serialize polymorphic when type key is not camelized", function() { test("serialize polymorphic when associated object is null", function() { var ray, json; run(function() { - ray = env.store.createRecord(DoomsdayDevice, { name: "DeathRay" }); + ray = env.store.createRecord('doomsday-device', { name: "DeathRay" }); json = env.amsSerializer.serialize(ray._createSnapshot()); }); diff --git a/packages/ember-data/lib/serializers/embedded-records-mixin.js b/packages/ember-data/lib/serializers/embedded-records-mixin.js index d0c2be79e37..adc0ddcbc99 100644 --- a/packages/ember-data/lib/serializers/embedded-records-mixin.js +++ b/packages/ember-data/lib/serializers/embedded-records-mixin.js @@ -336,7 +336,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({ var parentRecord = snapshot.type.inverseFor(relationship.key); if (parentRecord) { var name = parentRecord.name; - var embeddedSerializer = this.store.serializerFor(embeddedSnapshot.type); + var embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName); var parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind, 'deserialize'); if (parentKey) { delete json[parentKey]; @@ -423,7 +423,7 @@ function extractEmbeddedHasMany(store, key, embeddedTypeClass, hash) { var embeddedSerializer = store.serializerFor(embeddedTypeClass.modelName); forEach(hash[key], function(data) { var embeddedRecord = embeddedSerializer.normalize(embeddedTypeClass, data, null); - store.push(embeddedTypeClass, embeddedRecord); + store.push(embeddedTypeClass.modelName, embeddedRecord); ids.push(embeddedRecord.id); }); @@ -445,7 +445,7 @@ function extractEmbeddedHasManyPolymorphic(store, key, hash) { var primaryKey = get(embeddedSerializer, 'primaryKey'); var embeddedRecord = embeddedSerializer.normalize(embeddedTypeClass, data, null); - store.push(embeddedTypeClass, embeddedRecord); + store.push(embeddedTypeClass.modelName, embeddedRecord); ids.push({ id: embeddedRecord[primaryKey], type: modelName }); }); @@ -460,7 +460,7 @@ function extractEmbeddedBelongsTo(store, key, embeddedTypeClass, hash) { var embeddedSerializer = store.serializerFor(embeddedTypeClass.modelName); var embeddedRecord = embeddedSerializer.normalize(embeddedTypeClass, hash[key], null); - store.push(embeddedTypeClass, embeddedRecord); + store.push(embeddedTypeClass.modelName, embeddedRecord); hash[key] = embeddedRecord.id; //TODO Need to add a reference to the parent later so relationship works between both `belongsTo` records @@ -479,7 +479,7 @@ function extractEmbeddedBelongsToPolymorphic(store, key, hash) { var primaryKey = get(embeddedSerializer, 'primaryKey'); var embeddedRecord = embeddedSerializer.normalize(embeddedTypeClass, data, null); - store.push(embeddedTypeClass, embeddedRecord); + store.push(embeddedTypeClass.modelName, embeddedRecord); hash[key] = embeddedRecord[primaryKey]; hash[key + 'Type'] = modelName; diff --git a/packages/ember-data/lib/serializers/json-serializer.js b/packages/ember-data/lib/serializers/json-serializer.js index 7a03adaa7d4..e81133c090b 100644 --- a/packages/ember-data/lib/serializers/json-serializer.js +++ b/packages/ember-data/lib/serializers/json-serializer.js @@ -729,7 +729,7 @@ export default Serializer.extend({ @return {Object} json The deserialized payload */ extract: function(store, typeClass, payload, id, requestType) { - this.extractMeta(store, typeClass, payload); + this.extractMeta(store, typeClass.modelName, payload); var specificExtract = "extract" + requestType.charAt(0).toUpperCase() + requestType.substr(1); return this[specificExtract](store, typeClass, payload, id, requestType); diff --git a/packages/ember-data/lib/serializers/rest-serializer.js b/packages/ember-data/lib/serializers/rest-serializer.js index df84c921e97..1b6e8d67ea8 100644 --- a/packages/ember-data/lib/serializers/rest-serializer.js +++ b/packages/ember-data/lib/serializers/rest-serializer.js @@ -267,14 +267,14 @@ var RESTSerializer = JSONSerializer.extend({ var primaryRecord; for (var prop in payload) { - var typeName = this.modelNameFromPayloadKey(prop); + var modelName = this.modelNameFromPayloadKey(prop); - if (!store.modelFactoryFor(typeName)) { - Ember.warn(this.warnMessageNoModelForKey(prop, typeName), false); + if (!store.modelFactoryFor(modelName)) { + Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false); continue; } - var type = store.modelFor(typeName); - var isPrimary = type.modelName === primaryTypeClassName; + var typeClass = store.modelFor(modelName); + var isPrimary = typeClass.modelName === primaryTypeClassName; var value = payload[prop]; if (value === null) { @@ -290,10 +290,9 @@ var RESTSerializer = JSONSerializer.extend({ /*jshint loopfunc:true*/ forEach.call(value, function(hash) { var typeName = this.modelNameFromPayloadKey(prop); - var type = store.modelFor(typeName); - var typeSerializer = store.serializerFor(type); + var typeSerializer = store.serializerFor(typeName); - hash = typeSerializer.normalize(type, hash, prop); + hash = typeSerializer.normalize(typeClass, hash, prop); var isFirstCreatedRecord = isPrimary && !recordId && !primaryRecord; var isUpdatedRecord = isPrimary && coerceId(hash.id) === recordId; @@ -307,7 +306,7 @@ var RESTSerializer = JSONSerializer.extend({ if (isFirstCreatedRecord || isUpdatedRecord) { primaryRecord = hash; } else { - store.push(typeName, hash); + store.push(modelName, hash); } }, this); } @@ -435,7 +434,7 @@ var RESTSerializer = JSONSerializer.extend({ continue; } var type = store.modelFor(typeName); - var typeSerializer = store.serializerFor(type); + var typeSerializer = store.serializerFor(typeName); var isPrimary = (!forcedSecondary && (type.modelName === primaryTypeClassName)); /*jshint loopfunc:true*/ @@ -493,12 +492,12 @@ var RESTSerializer = JSONSerializer.extend({ Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false); continue; } - var type = store.modelFor(modelName); - var typeSerializer = store.serializerFor(type); + var typeClass = store.modelFor(modelName); + var typeSerializer = store.serializerFor(modelName); /*jshint loopfunc:true*/ var normalizedArray = map.call(Ember.makeArray(payload[prop]), function(hash) { - return typeSerializer.normalize(type, hash, prop); + return typeSerializer.normalize(typeClass, hash, prop); }, this); store.pushMany(modelName, normalizedArray); diff --git a/packages/ember-data/lib/system/debug/debug-adapter.js b/packages/ember-data/lib/system/debug/debug-adapter.js index 3b7681466c7..fb81957483a 100644 --- a/packages/ember-data/lib/system/debug/debug-adapter.js +++ b/packages/ember-data/lib/system/debug/debug-adapter.js @@ -42,7 +42,11 @@ export default Ember.DataAdapter.extend({ return columns; }, - getRecords: function(modelName) { + 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; return this.get('store').all(modelName); }, diff --git a/packages/ember-data/lib/system/many-array.js b/packages/ember-data/lib/system/many-array.js index be0ff78d696..e4b3bbf15cc 100644 --- a/packages/ember-data/lib/system/many-array.js +++ b/packages/ember-data/lib/system/many-array.js @@ -228,7 +228,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { Ember.assert("You cannot add '" + type.modelName + "' records to this polymorphic relationship.", !get(this, 'isPolymorphic')); - record = store.createRecord(type, hash); + record = store.createRecord(type.modelName, hash); this.pushObject(record); return record; diff --git a/packages/ember-data/lib/system/model/model.js b/packages/ember-data/lib/system/model/model.js index b55dde5fc6e..1c76637dea4 100644 --- a/packages/ember-data/lib/system/model/model.js +++ b/packages/ember-data/lib/system/model/model.js @@ -29,13 +29,13 @@ var _splitOnDotCache = Ember.create(null); function splitOnDot(name) { return _splitOnDotCache[name] || ( - _splitOnDotCache[name] = name.split('.') + (_splitOnDotCache[name] = name.split('.')) ); } function extractPivotName(name) { return _extractPivotNameCache[name] || ( - _extractPivotNameCache[name] = splitOnDot(name)[0] + (_extractPivotNameCache[name] = splitOnDot(name)[0]) ); } diff --git a/packages/ember-data/lib/system/record-arrays/adapter-populated-record-array.js b/packages/ember-data/lib/system/record-arrays/adapter-populated-record-array.js index 5712a5a142a..1d7a24f00e7 100644 --- a/packages/ember-data/lib/system/record-arrays/adapter-populated-record-array.js +++ b/packages/ember-data/lib/system/record-arrays/adapter-populated-record-array.js @@ -39,8 +39,9 @@ export default RecordArray.extend({ load: function(data) { var store = get(this, 'store'); var type = get(this, 'type'); - var records = store.pushMany(type, data); - var meta = store.metadataFor(type); + var modelName = type.modelName; + var records = store.pushMany(modelName, data); + var meta = store.metadataFor(modelName); this.setProperties({ content: Ember.A(records), diff --git a/packages/ember-data/lib/system/record-arrays/record-array.js b/packages/ember-data/lib/system/record-arrays/record-array.js index da3a0409618..a1c98541f6d 100644 --- a/packages/ember-data/lib/system/record-arrays/record-array.js +++ b/packages/ember-data/lib/system/record-arrays/record-array.js @@ -113,9 +113,9 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { if (get(this, 'isUpdating')) { return; } var store = get(this, 'store'); - var type = get(this, 'type'); + var modelName = get(this, 'type.modelName'); - return store.fetchAll(type, this); + return store.fetchAll(modelName, this); }, /** diff --git a/packages/ember-data/lib/system/relationships/state/relationship.js b/packages/ember-data/lib/system/relationships/state/relationship.js index f17715dc7fb..4dffdee23f1 100644 --- a/packages/ember-data/lib/system/relationships/state/relationship.js +++ b/packages/ember-data/lib/system/relationships/state/relationship.js @@ -2,7 +2,7 @@ import OrderedSet from "ember-data/system/ordered-set"; var forEach = Ember.EnumerableUtils.forEach; -var Relationship = function(store, record, inverseKey, relationshipMeta) { +function Relationship(store, record, inverseKey, relationshipMeta) { this.members = new OrderedSet(); this.canonicalMembers = new OrderedSet(); this.store = store; @@ -13,10 +13,10 @@ var Relationship = function(store, record, inverseKey, relationshipMeta) { this.relationshipMeta = relationshipMeta; //This probably breaks for polymorphic relationship in complex scenarios, due to //multiple possible modelNames - this.inverseKeyForImplicit = this.store.modelFor(this.record.constructor).modelName + this.key; + this.inverseKeyForImplicit = this.record.constructor.modelName + this.key; this.linkPromise = null; this.hasData = false; -}; +} Relationship.prototype = { constructor: Relationship, diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index 3a21b1d43f3..bc84050d148 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -41,9 +41,7 @@ import { import RecordArrayManager from "ember-data/system/record-array-manager"; import Model from "ember-data/system/model"; - -//Stanley told me to do this -var Backburner = Ember.__loader.require('backburner')['default'] || Ember.__loader.require('backburner')['Backburner']; +var Backburner = Ember.Backburner || Ember.__loader.require('backburner')['default'] || Ember.__loader.require('backburner')['Backburner']; //Shim Backburner.join if (!Backburner.prototype.join) { @@ -306,6 +304,7 @@ Store = Service.extend({ @return {DS.Model} record */ createRecord: function(modelName, inputProperties) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var properties = copy(inputProperties) || {}; @@ -315,7 +314,7 @@ Store = Service.extend({ // to avoid conflicts. if (isNone(properties.id)) { - properties.id = this._generateId(typeClass, properties); + properties.id = this._generateId(modelName, properties); } // Coerce ID to a string @@ -512,6 +511,7 @@ Store = Service.extend({ find: function(modelName, id, preload) { Ember.assert("You need to pass a type to the store's find method", arguments.length >= 1); Ember.assert("You may not pass `" + id + "` as id to the store's find method", arguments.length === 1 || !Ember.isNone(id)); + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); if (arguments.length === 1) { return this.findAll(modelName); @@ -552,6 +552,7 @@ Store = Service.extend({ @return {Promise} promise */ fetchById: function(modelName, id, preload) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); if (this.hasRecordForId(modelName, id)) { return this.getById(modelName, id).reload(); } else { @@ -568,6 +569,7 @@ Store = Service.extend({ @return {Promise} promise */ fetchAll: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); return this._fetchAll(typeClass, this.all(modelName)); @@ -582,6 +584,7 @@ Store = Service.extend({ @deprecated Use [fetchById](#method_fetchById) instead */ fetch: function(modelName, id, preload) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); Ember.deprecate('Using store.fetch() has been deprecated. Use store.fetchById for fetching individual records or store.fetchAll for collections'); return this.fetchById(modelName, id, preload); }, @@ -597,9 +600,9 @@ Store = Service.extend({ @return {Promise} promise */ findById: function(modelName, id, preload) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); - var typeClass = this.modelFor(modelName); - var record = this.recordForId(typeClass, id); + var record = this.recordForId(modelName, id); return this._findByRecord(record, preload); }, @@ -632,6 +635,7 @@ Store = Service.extend({ @return {Promise} promise */ findByIds: function(modelName, ids) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var store = this; return promiseArray(Ember.RSVP.all(map(ids, function(id) { @@ -652,7 +656,7 @@ Store = Service.extend({ fetchRecord: function(record) { var typeClass = record.constructor; var id = get(record, 'id'); - var adapter = this.adapterFor(typeClass); + var adapter = this.adapterFor(typeClass.modelName); Ember.assert("You tried to find a record but you have no adapter (for " + typeClass + ")", adapter); Ember.assert("You tried to find a record but your adapter (for " + typeClass + ") does not implement 'find'", typeof adapter.find === 'function'); @@ -700,7 +704,7 @@ Store = Service.extend({ _flushPendingFetchForType: function (recordResolverPairs, typeClass) { var store = this; - var adapter = store.adapterFor(typeClass); + var adapter = store.adapterFor(typeClass.modelName); var shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests; var records = Ember.A(recordResolverPairs).mapBy('record'); @@ -802,13 +806,14 @@ Store = Service.extend({ ``` @method getById - @param {String or subclass of DS.Model} type + @param {String} modelName @param {String|Integer} id @return {DS.Model|null} record */ - getById: function(type, id) { - if (this.hasRecordForId(type, id)) { - return this.recordForId(type, id); + getById: function(modelName, id) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + if (this.hasRecordForId(modelName, id)) { + return this.recordForId(modelName, id); } else { return null; } @@ -828,7 +833,7 @@ Store = Service.extend({ */ reloadRecord: function(record) { var type = record.constructor; - var adapter = this.adapterFor(type); + var adapter = this.adapterFor(type.modelName); var id = get(record, 'id'); Ember.assert("You cannot reload a record without an ID", id); @@ -847,6 +852,7 @@ Store = Service.extend({ @return {Boolean} */ hasRecordForId: function(modelName, inputId) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var id = coerceId(inputId); var record = this.typeMapFor(typeClass).idToRecord[id]; @@ -864,6 +870,7 @@ Store = Service.extend({ @return {DS.Model} record */ recordForId: function(modelName, inputId) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var id = coerceId(inputId); var idToRecord = this.typeMapFor(typeClass).idToRecord; @@ -912,7 +919,7 @@ Store = Service.extend({ @return {Promise} promise */ findHasMany: function(owner, link, type) { - var adapter = this.adapterFor(owner.constructor); + var adapter = this.adapterFor(owner.constructor.modelName); Ember.assert("You tried to load a hasMany relationship but you have no adapter (for " + owner.constructor + ")", adapter); Ember.assert("You tried to load a hasMany relationship from a specified `link` in the original payload but your adapter does not implement `findHasMany`", typeof adapter.findHasMany === 'function'); @@ -929,7 +936,7 @@ Store = Service.extend({ @return {Promise} promise */ findBelongsTo: function(owner, link, relationship) { - var adapter = this.adapterFor(owner.constructor); + var adapter = this.adapterFor(owner.constructor.modelName); Ember.assert("You tried to load a belongsTo relationship but you have no adapter (for " + owner.constructor + ")", adapter); Ember.assert("You tried to load a belongsTo relationship from a specified `link` in the original payload but your adapter does not implement `findBelongsTo`", typeof adapter.findBelongsTo === 'function'); @@ -950,21 +957,22 @@ Store = Service.extend({ @method findQuery @private - @param {String or subclass of DS.Model} type + @param {String} modelName @param {any} query an opaque query to be used by the adapter @return {Promise} promise */ - findQuery: function(typeName, query) { - var type = this.modelFor(typeName); + findQuery: function(modelName, query) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + var typeClass = this.modelFor(modelName); var array = this.recordArrayManager - .createAdapterPopulatedRecordArray(type, query); + .createAdapterPopulatedRecordArray(typeClass, query); - var adapter = this.adapterFor(type); + var adapter = this.adapterFor(modelName); - Ember.assert("You tried to load a query but you have no adapter (for " + type + ")", adapter); + Ember.assert("You tried to load a query but you have no adapter (for " + typeClass + ")", adapter); Ember.assert("You tried to load a query but your adapter does not implement `findQuery`", typeof adapter.findQuery === 'function'); - return promiseArray(_findQuery(adapter, this, type, query, array)); + return promiseArray(_findQuery(adapter, this, typeClass, query, array)); }, /** @@ -978,6 +986,7 @@ Store = Service.extend({ @return {DS.AdapterPopulatedRecordArray} */ findAll: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); return this.fetchAll(modelName); }, @@ -989,7 +998,7 @@ Store = Service.extend({ @return {Promise} promise */ _fetchAll: function(typeClass, array) { - var adapter = this.adapterFor(typeClass); + var adapter = this.adapterFor(typeClass.modelName); var sinceToken = this.typeMapFor(typeClass).metadata.since; set(array, 'isUpdating', true); @@ -1003,6 +1012,7 @@ Store = Service.extend({ /** @method didUpdateAll @param {DS.Model} typeClass + @private */ didUpdateAll: function(typeClass) { var findAllCache = this.typeMapFor(typeClass).findAllCache; @@ -1033,6 +1043,7 @@ Store = Service.extend({ @return {DS.RecordArray} */ all: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var typeMap = this.typeMapFor(typeClass); var findAllCache = typeMap.findAllCache; @@ -1062,6 +1073,7 @@ Store = Service.extend({ @param {String} optional modelName */ unloadAll: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), !modelName || typeof modelName === 'string'); if (arguments.length === 0) { var typeMaps = this.typeMaps; var keys = Ember.keys(typeMaps); @@ -1086,7 +1098,7 @@ Store = Service.extend({ } function byType(entry) { - return typeMaps[entry]['type']; + return typeMaps[entry]['type'].modelName; } }, @@ -1137,12 +1149,13 @@ Store = Service.extend({ ``` @method filter - @param {String or subclass of DS.Model} type + @param {String} modelName @param {Object} query optional query @param {Function} filter @return {DS.PromiseArray} */ - filter: function(type, query, filter) { + filter: function(modelName, query, filter) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var promise; var length = arguments.length; var array; @@ -1150,24 +1163,24 @@ Store = Service.extend({ // allow an optional server query if (hasQuery) { - promise = this.findQuery(type, query); + promise = this.findQuery(modelName, query); } else if (arguments.length === 2) { filter = query; } - type = this.modelFor(type); + modelName = this.modelFor(modelName); if (hasQuery) { - array = this.recordArrayManager.createFilteredRecordArray(type, filter, query); + array = this.recordArrayManager.createFilteredRecordArray(modelName, filter, query); } else { - array = this.recordArrayManager.createFilteredRecordArray(type, filter); + array = this.recordArrayManager.createFilteredRecordArray(modelName, filter); } promise = promise || Promise.cast(array); return promiseArray(promise.then(function() { return array; - }, null, "DS: Store#filter of " + type)); + }, null, "DS: Store#filter of " + modelName)); }, /** @@ -1185,24 +1198,26 @@ Store = Service.extend({ ``` @method recordIsLoaded - @param {String or subclass of DS.Model} type + @param {String} modelName @param {string} id @return {boolean} */ - recordIsLoaded: function(type, id) { - if (!this.hasRecordForId(type, id)) { return false; } - return !get(this.recordForId(type, id), 'isEmpty'); + recordIsLoaded: function(modelName, id) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + if (!this.hasRecordForId(modelName, id)) { return false; } + return !get(this.recordForId(modelName, id), 'isEmpty'); }, /** This method returns the metadata for a specific type. @method metadataFor - @param {String or subclass of DS.Model} typeName + @param {String or subclass of DS.Model} modelName @return {object} */ - metadataFor: function(typeName) { - var typeClass = this.modelFor(typeName); + metadataFor: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + var typeClass = this.modelFor(modelName); return this.typeMapFor(typeClass).metadata; }, @@ -1210,12 +1225,13 @@ Store = Service.extend({ This method sets the metadata for a specific type. @method setMetadataFor - @param {String or subclass of DS.Model} typeName + @param {String} modelName @param {Object} metadata metadata to set @return {object} */ - setMetadataFor: function(typeName, metadata) { - var typeClass = this.modelFor(typeName); + setMetadataFor: function(modelName, metadata) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + var typeClass = this.modelFor(modelName); Ember.merge(this.typeMapFor(typeClass).metadata, metadata); }, @@ -1273,7 +1289,7 @@ Store = Service.extend({ forEach(pending, function(tuple) { var record = tuple[0]; var resolver = tuple[1]; - var adapter = this.adapterFor(record.constructor); + var adapter = this.adapterFor(record.constructor.modelName); var operation; if (get(record, 'currentState.stateName') === 'root.deleted.saved') { @@ -1429,14 +1445,14 @@ Store = Service.extend({ */ _modelForMixin: function(modelName) { - var normalizedTypeKey = normalizeModelName(modelName); + var normalizedModelName = normalizeModelName(modelName); var registry = this.container._registry ? this.container._registry : this.container; - var mixin = registry.resolve('mixin:' + normalizedTypeKey); + var mixin = registry.resolve('mixin:' + normalizedModelName); if (mixin) { //Cache the class as a model - registry.register('model:' + normalizedTypeKey, DS.Model.extend(mixin)); + registry.register('model:' + normalizedModelName, DS.Model.extend(mixin)); } - var factory = this.modelFactoryFor(normalizedTypeKey); + var factory = this.modelFactoryFor(normalizedModelName); if (factory) { factory.__isMixin = true; factory.__mixin = mixin; @@ -1451,29 +1467,21 @@ Store = Service.extend({ etc.) @method modelFor - @param {String or subclass of DS.Model} key + @param {String} modelName @return {subclass of DS.Model} */ - modelFor: function(key) { - var factory; - - if (typeof key === 'string') { - factory = this.modelFactoryFor(key); - if (!factory) { - //Support looking up mixins as base types for polymorphic relationships - factory = this._modelForMixin(key); - } - if (!factory) { - throw new Ember.Error("No model was found for '" + key + "'"); - } - factory.modelName = factory.modelName || normalizeModelName(key); - } else { - // A factory already supplied. Ensure it has a normalized key. - factory = key; - if (factory.modelName) { - factory.modelName = normalizeModelName(factory.modelName); - } + modelFor: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + + var factory = this.modelFactoryFor(modelName); + if (!factory) { + //Support looking up mixins as base types for polymorphic relationships + factory = this._modelForMixin(modelName); } + if (!factory) { + throw new Ember.Error("No model was found for '" + modelName + "'"); + } + factory.modelName = factory.modelName || normalizeModelName(modelName); // deprecate typeKey if (!('typeKey' in factory)) { @@ -1494,8 +1502,9 @@ Store = Service.extend({ return factory; }, - modelFactoryFor: function(key) { - var normalizedKey = normalizeModelName(key); + modelFactoryFor: function(modelName) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + var normalizedKey = normalizeModelName(modelName); return this.container.lookupFactory('model:' + normalizedKey); }, @@ -1561,12 +1570,13 @@ Store = Service.extend({ records, as well as to update existing records. @method push - @param {String or subclass of DS.Model} modelName + @param {String} modelName @param {Object} data @return {DS.Model} the record that was created or updated. */ push: function(modelName, data) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); Ember.assert("Expected an object as `data` in a call to `push` for " + modelName + " , but was " + data, Ember.typeOf(data) === 'object'); Ember.assert("You must include an `id` for " + modelName + " in an object passed to `push`", data.id != null && data.id !== ''); @@ -1588,9 +1598,9 @@ Store = Service.extend({ // Actually load the record into the store. - this._load(type, data); + this._load(modelName, data); - var record = this.recordForId(type, data.id); + var record = this.recordForId(modelName, data.id); var store = this; this._backburner.join(function() { @@ -1656,19 +1666,20 @@ Store = Service.extend({ ``` @method pushPayload - @param {String} type Optionally, a model used to determine which serializer will be used + @param {String} modelName Optionally, a model type used to determine which serializer will be used @param {Object} payload */ - pushPayload: function (type, inputPayload) { + pushPayload: function (modelName, inputPayload) { var serializer; var payload; if (!inputPayload) { - payload = type; + payload = modelName; serializer = defaultSerializer(this.container); - Ember.assert("You cannot use `store#pushPayload` without a type unless your default serializer defines `pushPayload`", typeof serializer.pushPayload === 'function'); + Ember.assert("You cannot use `store#pushPayload` without a modelName unless your default serializer defines `pushPayload`", typeof serializer.pushPayload === 'function'); } else { payload = inputPayload; - serializer = this.serializerFor(type); + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + serializer = this.serializerFor(modelName); } var store = this; this._adapterRun(function() { @@ -1691,26 +1702,28 @@ Store = Service.extend({ ``` @method normalize - @param {String} type The name of the model type for this payload + @param {String} modelName The name of the model type for this payload @param {Object} payload @return {Object} The normalized payload */ - normalize: function (type, payload) { - var serializer = this.serializerFor(type); - var model = this.modelFor(type); + normalize: function (modelName, payload) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + var serializer = this.serializerFor(modelName); + var model = this.modelFor(modelName); return serializer.normalize(model, payload); }, /** @method update - @param {String} type + @param {String} modelName @param {Object} data @return {DS.Model} the record that was updated. @deprecated Use [push](#method_push) instead */ - update: function(type, data) { + update: function(modelName, data) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); Ember.deprecate('Using store.update() has been deprecated since store.push() now handles partial updates. You should use store.push() instead.'); - return this.push(type, data); + return this.push(modelName, data); }, /** @@ -1719,16 +1732,17 @@ Store = Service.extend({ call `push` repeatedly for you. @method pushMany - @param {String or subclass of DS.Model} type + @param {String} modelName @param {Array} datas @return {Array} */ - pushMany: function(type, datas) { + pushMany: function(modelName, datas) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var length = datas.length; var result = new Array(length); for (var i = 0; i < length; i++) { - result[i] = this.push(type, datas[i]); + result[i] = this.push(modelName, datas[i]); } return result; @@ -1736,13 +1750,14 @@ Store = Service.extend({ /** @method metaForType - @param {String or subclass of DS.Model} typeName + @param {String or subclass of DS.Model} modelName @param {Object} metadata @deprecated Use [setMetadataFor](#method_setMetadataFor) instead */ - metaForType: function(typeName, metadata) { + metaForType: function(modelName, metadata) { + Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); Ember.deprecate('Using store.metaForType() has been deprecated. Use store.setMetadataFor() to set metadata for a specific type.'); - this.setMetadataFor(typeName, metadata); + this.setMetadataFor(modelName, metadata); }, /** @@ -1847,15 +1862,21 @@ Store = Service.extend({ @method adapterFor @private - @param {String or subclass of DS.Model} type + @param {String} modelName @return DS.Adapter */ - adapterFor: function(type) { - if (type !== 'application') { - type = this.modelFor(type); + adapterFor: function(modelOrClass) { + var modelName; + + Ember.deprecate('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelOrClass === 'string'); + + if (typeof modelOrClass !== 'string') { + modelName = modelOrClass.modelName; + } else { + modelName = modelOrClass; } - var adapter = this.lookupAdapter(type.modelName) || this.lookupAdapter('application'); + var adapter = this.lookupAdapter(modelName) || this.lookupAdapter('application'); return adapter || get(this, 'defaultAdapter'); }, @@ -1886,18 +1907,23 @@ Store = Service.extend({ @method serializerFor @private - @param {String or subclass of DS.Model} type the record to serialize + @param {String} modelName the record to serialize @return {DS.Serializer} */ - serializerFor: function(type) { - if (type !== 'application') { - type = this.modelFor(type); + serializerFor: function(modelOrClass) { + var modelName; + + Ember.deprecate('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelOrClass === 'string'); + if (typeof modelOrClass !== 'string') { + modelName = modelOrClass.modelName; + } else { + modelName = modelOrClass; } - var serializer = this.lookupSerializer(type.modelName) || this.lookupSerializer('application'); + var serializer = this.lookupSerializer(modelName) || this.lookupSerializer('application'); if (!serializer) { - var adapter = this.adapterFor(type); + var adapter = this.adapterFor(modelName); serializer = this.lookupSerializer(get(adapter, 'defaultSerializer')); } @@ -1986,7 +2012,7 @@ function deserializeRecordId(store, data, key, relationship, id) { if (typeof id === 'number' || typeof id === 'string') { type = typeFor(relationship, key, data); - data[key] = store.recordForId(type, id); + data[key] = store.recordForId(typeof type === 'string' ? type : type.modelName, id); } else if (typeof id === 'object') { // hasMany polymorphic Ember.assert('Ember Data expected a number or string to represent the record(s) in the `' + relationship.key + '` relationship instead it found an object. If this is a polymorphic relationship please specify a `type` key. If this is an embedded relationship please include the `DS.EmbeddedRecordsMixin` and specify the `' + relationship.key +'` property in your serializer\'s attrs object.', id.type); @@ -2024,9 +2050,10 @@ function defaultSerializer(container) { function _commit(adapter, store, operation, record) { var type = record.constructor; + var modelName = type.modelName; var snapshot = record._createSnapshot(); var promise = adapter[operation](store, type, snapshot); - var serializer = serializerForAdapter(store, adapter, type); + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Extract and notify about " + operation + " completion of " + record; Ember.assert("Your adapter's '" + operation + "' method must return a value, but it returned `undefined", promise !==undefined); diff --git a/packages/ember-data/lib/system/store/finders.js b/packages/ember-data/lib/system/store/finders.js index 4697be92462..c633f5f3252 100644 --- a/packages/ember-data/lib/system/store/finders.js +++ b/packages/ember-data/lib/system/store/finders.js @@ -13,9 +13,10 @@ var get = Ember.get; var Promise = Ember.RSVP.Promise; export function _find(adapter, store, typeClass, id, record) { + var modelName = typeClass.modelName; var snapshot = record._createSnapshot(); var promise = adapter.find(store, typeClass, id, snapshot); - var serializer = serializerForAdapter(store, adapter, typeClass); + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Handle Adapter#find of " + typeClass + " with id: " + id; promise = Promise.cast(promise, label); @@ -26,7 +27,7 @@ export function _find(adapter, store, typeClass, id, record) { return store._adapterRun(function() { var payload = serializer.extract(store, typeClass, adapterPayload, id, 'find'); - return store.push(typeClass, payload); + return store.push(modelName, payload); }); }, function(error) { record.notFound(); @@ -40,9 +41,10 @@ export function _find(adapter, store, typeClass, id, record) { export function _findMany(adapter, store, typeClass, ids, records) { + var modelName = typeClass.modelName; var snapshots = Ember.A(records).invoke('_createSnapshot'); var promise = adapter.findMany(store, typeClass, ids, snapshots); - var serializer = serializerForAdapter(store, adapter, typeClass); + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Handle Adapter#findMany of " + typeClass; if (promise === undefined) { @@ -58,15 +60,16 @@ export function _findMany(adapter, store, typeClass, ids, records) { Ember.assert("The response from a findMany must be an Array, not " + Ember.inspect(payload), Ember.typeOf(payload) === 'array'); - return store.pushMany(typeClass, payload); + return store.pushMany(modelName, payload); }); }, null, "DS: Extract payload of " + typeClass); } export function _findHasMany(adapter, store, record, link, relationship) { var snapshot = record._createSnapshot(); + var modelName = relationship.type.modelName; var promise = adapter.findHasMany(store, snapshot, link, relationship); - var serializer = serializerForAdapter(store, adapter, relationship.type); + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Handle Adapter#findHasMany of " + record + " : " + relationship.type; promise = Promise.cast(promise, label); @@ -79,16 +82,17 @@ export function _findHasMany(adapter, store, record, link, relationship) { Ember.assert("The response from a findHasMany must be an Array, not " + Ember.inspect(payload), Ember.typeOf(payload) === 'array'); - var records = store.pushMany(relationship.type, payload); + var records = store.pushMany(modelName, payload); return records; }); }, null, "DS: Extract payload of " + record + " : hasMany " + relationship.type); } export function _findBelongsTo(adapter, store, record, link, relationship) { + var modelName = relationship.type.modelName; var snapshot = record._createSnapshot(); var promise = adapter.findBelongsTo(store, snapshot, link, relationship); - var serializer = serializerForAdapter(store, adapter, relationship.type); + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Handle Adapter#findBelongsTo of " + record + " : " + relationship.type; promise = Promise.cast(promise, label); @@ -103,7 +107,7 @@ export function _findBelongsTo(adapter, store, record, link, relationship) { return null; } - var record = store.push(relationship.type, payload); + var record = store.push(modelName, payload); return record; }); }, null, "DS: Extract payload of " + record + " : " + relationship.type); @@ -111,7 +115,8 @@ export function _findBelongsTo(adapter, store, record, link, relationship) { export function _findAll(adapter, store, typeClass, sinceToken) { var promise = adapter.findAll(store, typeClass, sinceToken); - var serializer = serializerForAdapter(store, adapter, typeClass); + var modelName = typeClass.modelName; + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Handle Adapter#findAll of " + typeClass; promise = Promise.cast(promise, label); @@ -123,17 +128,18 @@ export function _findAll(adapter, store, typeClass, sinceToken) { Ember.assert("The response from a findAll must be an Array, not " + Ember.inspect(payload), Ember.typeOf(payload) === 'array'); - store.pushMany(typeClass, payload); + store.pushMany(modelName, payload); }); store.didUpdateAll(typeClass); - return store.all(typeClass); + return store.all(modelName); }, null, "DS: Extract payload of findAll " + typeClass); } export function _findQuery(adapter, store, typeClass, query, recordArray) { + var modelName = typeClass.modelName; var promise = adapter.findQuery(store, typeClass, query, recordArray); - var serializer = serializerForAdapter(store, adapter, typeClass); + var serializer = serializerForAdapter(store, adapter, modelName); var label = "DS: Handle Adapter#findQuery of " + typeClass; promise = Promise.cast(promise, label); diff --git a/packages/ember-data/tests/integration/adapter/build-url-mixin-test.js b/packages/ember-data/tests/integration/adapter/build-url-mixin-test.js index 7fcc08726b2..e5e54f64e60 100644 --- a/packages/ember-data/tests/integration/adapter/build-url-mixin-test.js +++ b/packages/ember-data/tests/integration/adapter/build-url-mixin-test.js @@ -28,6 +28,10 @@ module("integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter", { store = env.store; adapter = env.adapter; + Post = store.modelFor('post'); + Comment = store.modelFor('comment'); + SuperUser = store.modelFor('super-user'); + passedUrl = null; } }); @@ -154,7 +158,7 @@ test('buildURL - with camelized names', function() { ajaxResponse({ superUsers: [{ id: 1 }] }); run(function() { - store.find('superUser', 1).then(async(function(post) { + store.find('super-user', 1).then(async(function(post) { equal(passedUrl, "/super_users/1"); })); }); diff --git a/packages/ember-data/tests/integration/adapter/find-all-test.js b/packages/ember-data/tests/integration/adapter/find-all-test.js index b870cd536e1..a0541631765 100644 --- a/packages/ember-data/tests/integration/adapter/find-all-test.js +++ b/packages/ember-data/tests/integration/adapter/find-all-test.js @@ -1,6 +1,7 @@ var get = Ember.get; var Person, store, allRecords; var run = Ember.run; +var env; module("integration/adapter/find_all - Finding All Records of a Type", { setup: function() { @@ -12,6 +13,11 @@ module("integration/adapter/find_all - Finding All Records of a Type", { }); allRecords = null; + + env = setupStore({ + person: Person + }); + store = env.store; }, teardown: function() { @@ -25,20 +31,19 @@ module("integration/adapter/find_all - Finding All Records of a Type", { test("When all records for a type are requested, the store should call the adapter's `findAll` method.", function() { expect(5); - store = createStore({ adapter: DS.Adapter.extend({ - findAll: function(store, type, since) { - // this will get called twice - ok(true, "the adapter's findAll method should be invoked"); + env.registry.register('adapter:person', DS.Adapter.extend({ + findAll: function(store, type, since) { + // this will get called twice + ok(true, "the adapter's findAll method should be invoked"); - return Ember.RSVP.resolve([{ id: 1, name: "Braaaahm Dale" }]); - } - }) - }); + return Ember.RSVP.resolve([{ id: 1, name: "Braaaahm Dale" }]); + } + })); var allRecords; run(function() { - store.find(Person).then(function(all) { + store.find('person').then(function(all) { allRecords = all; equal(get(all, 'length'), 1, "the record array's length is 1 after a record is loaded into it"); equal(all.objectAt(0).get('name'), "Braaaahm Dale", "the first item in the record array is Braaaahm Dale"); @@ -46,7 +51,7 @@ test("When all records for a type are requested, the store should call the adapt }); run(function() { - store.find(Person).then(function(all) { + store.find('person').then(function(all) { // Only one record array per type should ever be created (identity map) strictEqual(allRecords, all, "the same record array is returned every time all records of a type are requested"); }); @@ -57,27 +62,25 @@ test("When all records for a type are requested, a rejection should reject the p expect(5); var count = 0; - store = createStore({ - adapter: DS.Adapter.extend({ - findAll: function(store, type, since) { - // this will get called twice - ok(true, "the adapter's findAll method should be invoked"); - - if (count++ === 0) { - return Ember.RSVP.reject(); - } else { - return Ember.RSVP.resolve([{ id: 1, name: "Braaaahm Dale" }]); - } + env.registry.register('adapter:person', DS.Adapter.extend({ + findAll: function(store, type, since) { + // this will get called twice + ok(true, "the adapter's findAll method should be invoked"); + + if (count++ === 0) { + return Ember.RSVP.reject(); + } else { + return Ember.RSVP.resolve([{ id: 1, name: "Braaaahm Dale" }]); } - }) - }); + } + })); var allRecords; run(function() { - store.find(Person).then(null, function() { + store.find('person').then(null, function() { ok(true, "The rejection should get here"); - return store.find(Person); + return store.find('person'); }).then(function(all) { allRecords = all; equal(get(all, 'length'), 1, "the record array's length is 1 after a record is loaded into it"); @@ -88,16 +91,15 @@ test("When all records for a type are requested, a rejection should reject the p test("When all records for a type are requested, records that are already loaded should be returned immediately.", function() { expect(3); - store = createStore({ adapter: DS.Adapter.extend() }); run(function() { // Load a record from the server - store.push(Person, { id: 1, name: "Jeremy Ashkenas" }); + store.push('person', { id: 1, name: "Jeremy Ashkenas" }); // Create a new, unsaved record in the store - store.createRecord(Person, { name: "Alex MacCaw" }); + store.createRecord('person', { name: "Alex MacCaw" }); }); - allRecords = store.all(Person); + allRecords = store.all('person'); equal(get(allRecords, 'length'), 2, "the record array's length is 2"); equal(allRecords.objectAt(0).get('name'), "Jeremy Ashkenas", "the first item in the record array is Jeremy Ashkenas"); @@ -107,14 +109,12 @@ test("When all records for a type are requested, records that are already loaded test("When all records for a type are requested, records that are created on the client should be added to the record array.", function() { expect(3); - store = createStore({ adapter: DS.Adapter.extend() }); - - allRecords = store.all(Person); + allRecords = store.all('person'); equal(get(allRecords, 'length'), 0, "precond - the record array's length is zero before any records are loaded"); run(function() { - store.createRecord(Person, { name: "Carsten Nielsen" }); + store.createRecord('person', { name: "Carsten Nielsen" }); }); equal(get(allRecords, 'length'), 1, "the record array's length is 1"); diff --git a/packages/ember-data/tests/integration/adapter/find-test.js b/packages/ember-data/tests/integration/adapter/find-test.js index 8d76e27f496..d07614e0ed4 100644 --- a/packages/ember-data/tests/integration/adapter/find-test.js +++ b/packages/ember-data/tests/integration/adapter/find-test.js @@ -1,4 +1,4 @@ -var Person, store; +var Person, store, env; var run = Ember.run; module("integration/adapter/find - Finding Records", { @@ -9,6 +9,11 @@ module("integration/adapter/find - Finding Records", { firstName: DS.attr('string'), lastName: DS.attr('string') }); + + env = setupStore({ + person: Person + }); + store = env.store; }, teardown: function() { @@ -17,7 +22,6 @@ module("integration/adapter/find - Finding Records", { }); test("It raises an assertion when no type is passed", function() { - store = createStore(); expectAssertion(function() { store.find(); @@ -25,14 +29,13 @@ test("It raises an assertion when no type is passed", function() { }); test("It raises an assertion when `undefined` is passed as id (#1705)", function() { - store = createStore(); expectAssertion(function() { - store.find(Person, undefined); + store.find('person', undefined); }, "You may not pass `undefined` as id to the store's find method"); expectAssertion(function() { - store.find(Person, null); + store.find('person', null); }, "You may not pass `null` as id to the store's find method"); }); @@ -41,35 +44,33 @@ test("When a single record is requested, the adapter's find method should be cal var count = 0; - store = createStore({ adapter: DS.Adapter.extend({ - find: function(store, type, id, snapshot) { - equal(type, Person, "the find method is called with the correct type"); - equal(count, 0, "the find method is only called once"); + env.registry.register('adapter:person', DS.Adapter.extend({ + find: function(store, type, id, snapshot) { + equal(type, Person, "the find method is called with the correct type"); + equal(count, 0, "the find method is only called once"); - count++; - return { id: 1, name: "Braaaahm Dale" }; - } - }) - }); + count++; + return { id: 1, name: "Braaaahm Dale" }; + } + })); run(function() { - store.find(Person, 1); - store.find(Person, 1); + store.find('person', 1); + store.find('person', 1); }); }); test("When a single record is requested multiple times, all .find() calls are resolved after the promise is resolved", function() { var deferred = Ember.RSVP.defer(); - store = createStore({ adapter: DS.Adapter.extend({ - find: function(store, type, id, snapshot) { - return deferred.promise; - } - }) - }); + env.registry.register('adapter:person', DS.Adapter.extend({ + find: function(store, type, id, snapshot) { + return deferred.promise; + } + })); run(function() { - store.find(Person, 1).then(async(function(person) { + store.find('person', 1).then(async(function(person) { equal(person.get('id'), "1"); equal(person.get('name'), "Braaaahm Dale"); @@ -85,7 +86,7 @@ test("When a single record is requested multiple times, all .find() calls are re }); run(function() { - store.find(Person, 1).then(async(function(post) { + store.find('person', 1).then(async(function(post) { equal(post.get('id'), "1"); equal(post.get('name'), "Braaaahm Dale"); @@ -107,15 +108,14 @@ test("When a single record is requested multiple times, all .find() calls are re }); test("When a single record is requested, and the promise is rejected, .find() is rejected.", function() { - store = createStore({ adapter: DS.Adapter.extend({ - find: function(store, type, id, snapshot) { - return Ember.RSVP.reject(); - } - }) - }); + env.registry.register('adapter:person', DS.Adapter.extend({ + find: function(store, type, id, snapshot) { + return Ember.RSVP.reject(); + } + })); run(function() { - store.find(Person, 1).then(null, async(function(reason) { + store.find('person', 1).then(null, async(function(reason) { ok(true, "The rejection handler was called"); })); }); @@ -124,18 +124,17 @@ test("When a single record is requested, and the promise is rejected, .find() is test("When a single record is requested, and the promise is rejected, the record should be unloaded.", function() { expect(2); - store = createStore({ adapter: DS.Adapter.extend({ - find: function(store, type, id, snapshot) { - return Ember.RSVP.reject(); - } - }) - }); + env.registry.register('adapter:person', DS.Adapter.extend({ + find: function(store, type, id, snapshot) { + return Ember.RSVP.reject(); + } + })); run(function() { - store.find(Person, 1).then(null, async(function(reason) { + store.find('person', 1).then(null, async(function(reason) { ok(true, "The rejection handler was called"); })); }); - ok(!store.hasRecordForId(Person, 1), "The record has been unloaded"); + ok(!store.hasRecordForId('person', 1), "The record has been unloaded"); }); diff --git a/packages/ember-data/tests/integration/adapter/store-adapter-test.js b/packages/ember-data/tests/integration/adapter/store-adapter-test.js index 50e854e3eb1..605b13c9f1a 100644 --- a/packages/ember-data/tests/integration/adapter/store-adapter-test.js +++ b/packages/ember-data/tests/integration/adapter/store-adapter-test.js @@ -664,7 +664,7 @@ test("if a updated record is marked as erred by the server, it enters an error s }; var person = run(function() { - return store.push(Person, { id: 1, name: "John Doe" }); + return store.push('person', { id: 1, name: "John Doe" }); }); run(store, 'find', 'person', 1).then(async(function(record) { diff --git a/packages/ember-data/tests/integration/debug-adapter-test.js b/packages/ember-data/tests/integration/debug-adapter-test.js index 3471c665065..53ec9a313ab 100644 --- a/packages/ember-data/tests/integration/debug-adapter-test.js +++ b/packages/ember-data/tests/integration/debug-adapter-test.js @@ -15,6 +15,9 @@ module("DS.DebugAdapter", { App.Post = DS.Model.extend({ title: DS.attr('string') }); + App.Post.reopenClass({ + modelName: 'post' + }); }); @@ -23,7 +26,7 @@ module("DS.DebugAdapter", { debugAdapter.reopen({ getModelTypes: function() { - return Ember.A([{ klass: App.Post, name: 'App.Post' }]); + return Ember.A([{ klass: App.__container__.lookupFactory('model:post'), name: 'App.Post' }]); } }); }, @@ -39,7 +42,7 @@ test("Watching Model Types", function() { equal(types.length, 1); equal(types[0].name, 'App.Post'); equal(types[0].count, 0); - strictEqual(types[0].object, App.Post); + strictEqual(types[0].object, store.modelFor('post')); }; var updated = function(types) { @@ -71,7 +74,7 @@ test("Watching Records", function() { removedCount = count; }; - debugAdapter.watchRecords(App.Post, recordsAdded, recordsUpdated, recordsRemoved); + debugAdapter.watchRecords(App.__container__.lookupFactory('model:post'), recordsAdded, recordsUpdated, recordsRemoved); equal(get(addedRecords, 'length'), 1); record = addedRecords[0]; diff --git a/packages/ember-data/tests/integration/filter-test.js b/packages/ember-data/tests/integration/filter-test.js index 8196c4ff526..e59721e90ee 100644 --- a/packages/ember-data/tests/integration/filter-test.js +++ b/packages/ember-data/tests/integration/filter-test.js @@ -193,7 +193,7 @@ test("a Record Array can update its filter", function() { asyncBryn = store.find('person', 3); }); - store.filter(Person, function(hash) { + store.filter('person', function(hash) { if (hash.get('name').match(/Scumbag [KD]/)) { return true; } }).then(async(function(recordArray) { @@ -253,7 +253,7 @@ test("a Record Array can update its filter and notify array observers", function asyncBryn = store.find('person', 3); }); - store.filter(Person, function(hash) { + store.filter('person', function(hash) { if (hash.get('name').match(/Scumbag [KD]/)) { return true; } }).then(async(function(recordArray) { @@ -378,7 +378,7 @@ test("filter with query persists query on the resulting filteredRecordArray", fu var filter; run(function() { - filter = store.filter(Person, { foo: 1 }, function(person) { + filter = store.filter('person', { foo: 1 }, function(person) { return true; }); }); @@ -400,7 +400,7 @@ test("it is possible to filter by state flags", function() { } })); - filter = store.filter(Person, function(person) { + filter = store.filter('person', function(person) { return person.get('isLoaded'); }); }); diff --git a/packages/ember-data/tests/integration/inverse-test.js b/packages/ember-data/tests/integration/inverse-test.js index 107adffc71c..e55f15ec4b9 100644 --- a/packages/ember-data/tests/integration/inverse-test.js +++ b/packages/ember-data/tests/integration/inverse-test.js @@ -26,7 +26,7 @@ module('integration/inverse_test - inverseFor', { Job.toString = stringify('job'); ReflexiveModel = DS.Model.extend({ - reflexiveProp: belongsTo('reflexiveModel') + reflexiveProp: belongsTo('reflexive-model') }); ReflexiveModel.toString = stringify('reflexiveModel'); @@ -143,7 +143,7 @@ test("Errors out if you do not define an inverse for a reflexive relationship", warns(function() { var reflexiveModel; run(function() { - reflexiveModel = store.push('reflexiveModel', { id: 1 }); + reflexiveModel = store.push('reflexive-model', { id: 1 }); }); }, /Detected a reflexive relationship by the name of 'reflexiveProp'/); }); diff --git a/packages/ember-data/tests/integration/lifecycle-hooks-test.js b/packages/ember-data/tests/integration/lifecycle-hooks-test.js index dab3da4c7a6..3625e35c9e0 100644 --- a/packages/ember-data/tests/integration/lifecycle-hooks-test.js +++ b/packages/ember-data/tests/integration/lifecycle-hooks-test.js @@ -28,7 +28,7 @@ asyncTest("When the adapter acknowledges that a record has been created, a `didC var person; run(function() { - person = env.store.createRecord(Person, { name: "Yehuda Katz" }); + person = env.store.createRecord('person', { name: "Yehuda Katz" }); }); person.on('didCreate', function() { @@ -50,7 +50,7 @@ test("When the adapter acknowledges that a record has been created without a new var person; run(function() { - person = env.store.createRecord(Person, { id: 99, name: "Yehuda Katz" }); + person = env.store.createRecord('person', { id: 99, name: "Yehuda Katz" }); }); person.on('didCreate', function() { diff --git a/packages/ember-data/tests/integration/multiple_stores_test.js b/packages/ember-data/tests/integration/multiple_stores_test.js index 09210a6db6b..badc61087e4 100644 --- a/packages/ember-data/tests/integration/multiple_stores_test.js +++ b/packages/ember-data/tests/integration/multiple_stores_test.js @@ -7,15 +7,15 @@ module("integration/multiple_stores - Multiple Stores Tests", { SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), - homePlanet: DS.belongsTo("homePlanet", { inverse: 'villains' }), - evilMinions: DS.hasMany("evilMinion") + homePlanet: DS.belongsTo('home-planet', { inverse: 'villains' }), + evilMinions: DS.hasMany('evil-minion') }); HomePlanet = DS.Model.extend({ name: DS.attr('string'), - villains: DS.hasMany('superVillain', { inverse: 'homePlanet' }) + villains: DS.hasMany('super-villain', { inverse: 'homePlanet' }) }); EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('superVillain'), + superVillain: DS.belongsTo('super-villain'), name: DS.attr('string') }); @@ -77,9 +77,9 @@ test("embedded records should be created in multiple stores", function() { } })); - var serializer_main = env.store.serializerFor("homePlanet"); - var serializer_a = env.store_a.serializerFor("homePlanet"); - var serializer_b = env.store_b.serializerFor("homePlanet"); + var serializer_main = env.store.serializerFor('home-planet'); + var serializer_a = env.store_a.serializerFor('home-planet'); + var serializer_b = env.store_b.serializerFor('home-planet'); var json_hash_main = { home_planet: { @@ -117,18 +117,18 @@ test("embedded records should be created in multiple stores", function() { var json_main, json_a, json_b; run(function() { - json_main = serializer_main.extractSingle(env.store, HomePlanet, json_hash_main); - equal(env.store.hasRecordForId("superVillain", "1"), true, "superVillain should exist in store:main"); + json_main = serializer_main.extractSingle(env.store, env.store.modelFor('home-planet'), json_hash_main); + equal(env.store.hasRecordForId('super-villain', "1"), true, "superVillain should exist in store:main"); }); run(function() { - json_a = serializer_a.extractSingle(env.store_a, HomePlanet, json_hash_a); - equal(env.store_a.hasRecordForId("superVillain", "1"), true, "superVillain should exist in store:store-a"); + json_a = serializer_a.extractSingle(env.store_a, env.store_a.modelFor('home-planet'), json_hash_a); + equal(env.store_a.hasRecordForId("super-villain", "1"), true, "superVillain should exist in store:store-a"); }); run(function() { - json_b = serializer_b.extractSingle(env.store_b, HomePlanet, json_hash_b); - equal(env.store_b.hasRecordForId("superVillain", "1"), true, "superVillain should exist in store:store-b"); + json_b = serializer_b.extractSingle(env.store_b, env.store_a.modelFor('home-planet'), json_hash_b); + equal(env.store_b.hasRecordForId("super-villain", "1"), true, "superVillain should exist in store:store-b"); }); }); diff --git a/packages/ember-data/tests/integration/records/load-test.js b/packages/ember-data/tests/integration/records/load-test.js index 368e4641ff4..b13d373b196 100644 --- a/packages/ember-data/tests/integration/records/load-test.js +++ b/packages/ember-data/tests/integration/records/load-test.js @@ -27,13 +27,13 @@ test("When loading a record fails, the isLoading is set to false", function() { }; run(function() { - env.store.find('post', 1).then(null, function() { + env.store.find('post', 1).then(null, async(function() { // store.recordForId is private, but there is currently no other way to // get the specific record instance, since it is not passed to this // rejection handler var post = env.store.recordForId('post', 1); equal(post.get("isLoading"), false, "post is not loading anymore"); - }); + })); }); }); diff --git a/packages/ember-data/tests/integration/relationships/belongs-to-test.js b/packages/ember-data/tests/integration/relationships/belongs-to-test.js index a906968a355..9679be315a2 100644 --- a/packages/ember-data/tests/integration/relationships/belongs-to-test.js +++ b/packages/ember-data/tests/integration/relationships/belongs-to-test.js @@ -380,7 +380,7 @@ test("relationshipsByName does not cache a factory", function() { // A model is looked up in the store based on a string, via user input var messageModelFromStore = store.modelFor('message'); // And the model is lookup up internally via the relationship type - var messageModelFromRelationType = store.modelFor(messageType); + var messageModelFromRelationType = store.modelFor(messageType.modelName); equal(messageModelFromRelationType, messageModelFromStore, "model factory based on relationship type matches the model based on store.modelFor"); diff --git a/packages/ember-data/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/packages/ember-data/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js index 261517873e2..f3977b596b2 100644 --- a/packages/ember-data/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js +++ b/packages/ember-data/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -90,7 +90,7 @@ test("Setting the polymorphic belongsTo with an object that does not implement t var user, video; run(function() { user = store.push('user', { id: 1, name: 'Stanley' }); - video = store.push('notMessage', { id: 2, video: 'Here comes Youtube' }); + video = store.push('not-message', { id: 2, video: 'Here comes Youtube' }); }); run(function() { @@ -135,7 +135,7 @@ test("Setting the polymorphic belongsTo with an object that does not implement t var user, video; run(function() { user = store.push('user', { id: 1, name: 'Stanley' }); - video = store.push('notMessage', { id: 2, video: 'Here comes Youtube' }); + video = store.push('not-message', { id: 2, video: 'Here comes Youtube' }); }); run(function() { diff --git a/packages/ember-data/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/packages/ember-data/tests/integration/relationships/polymorphic-mixins-has-many-test.js index 3d84bb2f642..5cd8d528b60 100644 --- a/packages/ember-data/tests/integration/relationships/polymorphic-mixins-has-many-test.js +++ b/packages/ember-data/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -93,7 +93,7 @@ test("Pushing a an object that does not implement the mixin to the mixin accepti var user,notMessage; run(function() { user = store.push('user', { id: 1, name: 'Stanley', messages: [] }); - notMessage = store.push('notMessage', { id: 2, video: 'Here comes Youtube' }); + notMessage = store.push('not-message', { id: 2, video: 'Here comes Youtube' }); }); run(function() { @@ -140,7 +140,7 @@ test("Pushing a an object that does not implement the mixin to the mixin accepti var user,notMessage; run(function() { user = store.push('user', { id: 1, name: 'Stanley', messages: [] }); - notMessage = store.push('notMessage', { id: 2, video: 'Here comes Youtube' }); + notMessage = store.push('not-message', { id: 2, video: 'Here comes Youtube' }); }); run(function() { diff --git a/packages/ember-data/tests/integration/serializers/embedded-records-mixin-test.js b/packages/ember-data/tests/integration/serializers/embedded-records-mixin-test.js index 8606df6b8a8..0c4f1e99a71 100644 --- a/packages/ember-data/tests/integration/serializers/embedded-records-mixin-test.js +++ b/packages/ember-data/tests/integration/serializers/embedded-records-mixin-test.js @@ -10,32 +10,32 @@ module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), - homePlanet: DS.belongsTo("homePlanet", { inverse: 'villains' }), - secretLab: DS.belongsTo("secretLab"), - secretWeapons: DS.hasMany("secretWeapon"), - evilMinions: DS.hasMany("evilMinion") + homePlanet: DS.belongsTo('home-planet', { inverse: 'villains' }), + secretLab: DS.belongsTo('secret-lab'), + secretWeapons: DS.hasMany('secret-weapon'), + evilMinions: DS.hasMany('evil-minion') }); HomePlanet = DS.Model.extend({ name: DS.attr('string'), - villains: DS.hasMany('superVillain', { inverse: 'homePlanet' }) + villains: DS.hasMany('super-villain', { inverse: 'homePlanet' }) }); SecretLab = DS.Model.extend({ minionCapacity: DS.attr('number'), vicinity: DS.attr('string'), - superVillain: DS.belongsTo('superVillain') + superVillain: DS.belongsTo('super-villain') }); BatCave = SecretLab.extend({ infiltrated: DS.attr('boolean') }); SecretWeapon = DS.Model.extend({ name: DS.attr('string'), - superVillain: DS.belongsTo('superVillain') + superVillain: DS.belongsTo('super-villain') }); LightSaber = SecretWeapon.extend({ color: DS.attr('string') }); EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('superVillain'), + superVillain: DS.belongsTo('super-villain'), name: DS.attr('string') }); Comment = DS.Model.extend({ @@ -53,13 +53,13 @@ module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { evilMinion: EvilMinion, comment: Comment }); - env.store.modelFor('superVillain'); - env.store.modelFor('homePlanet'); - env.store.modelFor('secretLab'); - env.store.modelFor('batCave'); - env.store.modelFor('secretWeapon'); - env.store.modelFor('lightSaber'); - env.store.modelFor('evilMinion'); + env.store.modelFor('super-villain'); + env.store.modelFor('home-planet'); + env.store.modelFor('secret-lab'); + env.store.modelFor('bat-cave'); + env.store.modelFor('secret-weapon'); + env.store.modelFor('light-saber'); + env.store.modelFor('evil-minion'); env.store.modelFor('comment'); env.registry.register('serializer:application', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin)); env.registry.register('serializer:-active-model', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin)); @@ -105,7 +105,7 @@ test("extractSingle with embedded objects", function() { villains: ["1"] }); run(function() { - env.store.find("superVillain", 1).then(function(minion) { + env.store.find('super-villain', 1).then(function(minion) { equal(minion.get('firstName'), "Tom"); }); }); @@ -152,14 +152,14 @@ test("extractSingle with embedded objects inside embedded objects", function() { villains: ["1"] }); run(function() { - env.store.find("superVillain", 1).then(async(function(villain) { + env.store.find('super-villain', 1).then(function(villain) { equal(villain.get('firstName'), "Tom"); equal(villain.get('evilMinions.length'), 1, "Should load the embedded child"); equal(villain.get('evilMinions.firstObject.name'), "Alex", "Should load the embedded child"); - })); - env.store.find("evilMinion", 1).then(async(function(minion) { + }); + env.store.find('evil-minion', 1).then(function(minion) { equal(minion.get('name'), "Alex"); - })); + }); }); }); @@ -200,8 +200,8 @@ test("extractSingle with embedded objects of same type", function() { root: true, children: ["2", "3"] }, "Primary record was correct"); - equal(env.store.recordForId("comment", "2").get("body"), "World", "Secondary records found in the store"); - equal(env.store.recordForId("comment", "3").get("body"), "Foo", "Secondary records found in the store"); + equal(env.store.recordForId('comment', "2").get("body"), "World", "Secondary records found in the store"); + equal(env.store.recordForId('comment', "3").get("body"), "Foo", "Secondary records found in the store"); }); test("extractSingle with embedded objects inside embedded objects of same type", function() { @@ -246,16 +246,16 @@ test("extractSingle with embedded objects inside embedded objects of same type", root: true, children: ["2", "3"] }, "Primary record was correct"); - equal(env.store.recordForId("comment", "2").get("body"), "World", "Secondary records found in the store"); - equal(env.store.recordForId("comment", "3").get("body"), "Foo", "Secondary records found in the store"); - equal(env.store.recordForId("comment", "4").get("body"), "Another", "Secondary records found in the store"); - equal(env.store.recordForId("comment", "2").get("children.length"), 1, "Should have one embedded record"); - equal(env.store.recordForId("comment", "2").get("children.firstObject.body"), "Another", "Should have one embedded record"); + equal(env.store.recordForId('comment', "2").get("body"), "World", "Secondary records found in the store"); + equal(env.store.recordForId('comment', "3").get("body"), "Foo", "Secondary records found in the store"); + equal(env.store.recordForId('comment', "4").get("body"), "Another", "Secondary records found in the store"); + equal(env.store.recordForId('comment', "2").get("children.length"), 1, "Should have one embedded record"); + equal(env.store.recordForId('comment', "2").get("children.firstObject.body"), "Another", "Should have one embedded record"); }); test("extractSingle with embedded objects of same type, but from separate attributes", function() { HomePlanet.reopen({ - reformedVillains: DS.hasMany('superVillain', { inverse: null }) + reformedVillains: DS.hasMany('super-villain', { inverse: null }) }); env.registry.register('adapter:home-planet', DS.ActiveModelAdapter); @@ -299,10 +299,10 @@ test("extractSingle with embedded objects of same type, but from separate attrib reformedVillains: ["2", "4"] }, "Primary hash was correct"); - equal(env.store.recordForId("superVillain", "1").get("firstName"), "Tom", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "2").get("firstName"), "Alex", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "3").get("firstName"), "Yehuda", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "4").get("firstName"), "Erik", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "1").get("firstName"), "Tom", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "2").get("firstName"), "Alex", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "3").get("firstName"), "Yehuda", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "4").get("firstName"), "Erik", "Secondary records found in the store"); }); test("extractArray with embedded objects", function() { @@ -339,7 +339,7 @@ test("extractArray with embedded objects", function() { }]); run(function() { - env.store.find("superVillain", 1).then(function(minion) { + env.store.find('super-villain', 1).then(function(minion) { equal(minion.get('firstName'), "Tom"); }); }); @@ -383,8 +383,8 @@ test("extractArray with embedded objects with custom primary key", function() { }]); run(function() { - return env.store.find("superVillain", 1).then(function(minion) { - env.registry.unregister('serializer:super-villain'); + return env.store.find('super-villain', 1).then(function(minion) { + env.registry.unregister('serializer:superVillain'); equal(minion.get('firstName'), "Alex"); }); }); @@ -428,7 +428,7 @@ test("extractArray with embedded objects with identical relationship and attribu }]); run(function() { - env.store.find("superVillain", 1).then(function(minion) { + env.store.find('super-villain', 1).then(function(minion) { equal(minion.get('firstName'), "Alex"); }); }); @@ -473,13 +473,13 @@ test("extractArray with embedded objects of same type as primary type", function children: ["2", "3"] }], "Primary array is correct"); - equal(env.store.recordForId("comment", "2").get("body"), "World", "Secondary record found in the store"); - equal(env.store.recordForId("comment", "3").get("body"), "Foo", "Secondary record found in the store"); + equal(env.store.recordForId('comment', "2").get("body"), "World", "Secondary record found in the store"); + equal(env.store.recordForId('comment', "3").get("body"), "Foo", "Secondary record found in the store"); }); test("extractArray with embedded objects of same type, but from separate attributes", function() { HomePlanet.reopen({ - reformedVillains: DS.hasMany('superVillain') + reformedVillains: DS.hasMany('super-villain') }); env.registry.register('adapter:home-planet', DS.ActiveModelAdapter); @@ -545,18 +545,18 @@ test("extractArray with embedded objects of same type, but from separate attribu reformedVillains: ["5", "6"] }], "Primary array was correct"); - equal(env.store.recordForId("superVillain", "1").get("firstName"), "Tom", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "2").get("firstName"), "Alex", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "3").get("firstName"), "Yehuda", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "4").get("firstName"), "Erik", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "5").get("firstName"), "Peter", "Secondary records found in the store"); - equal(env.store.recordForId("superVillain", "6").get("firstName"), "Trek", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "1").get("firstName"), "Tom", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "2").get("firstName"), "Alex", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "3").get("firstName"), "Yehuda", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "4").get("firstName"), "Erik", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "5").get("firstName"), "Peter", "Secondary records found in the store"); + equal(env.store.recordForId('super-villain', "6").get("firstName"), "Trek", "Secondary records found in the store"); }); test("serialize supports serialize:false on non-relationship properties", function() { var tom; run(function() { - tom = env.store.createRecord(SuperVillain, { firstName: "Tom", lastName: "Dale", id: '1' }); + tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", id: '1' }); }); env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { @@ -580,8 +580,8 @@ test("serialize supports serialize:false on non-relationship properties", functi test("serialize with embedded objects (hasMany relationship)", function() { var tom, league; run(function() { - league = env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }); - tom = env.store.createRecord(SuperVillain, { firstName: "Tom", lastName: "Dale", homePlanet: league, id: '1' }); + league = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); + tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", homePlanet: league, id: '1' }); }); env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { @@ -611,8 +611,8 @@ test("serialize with embedded objects (hasMany relationship)", function() { test("serialize with embedded objects (hasMany relationship) supports serialize:false", function() { run(function() { - league = env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }); - env.store.createRecord(SuperVillain, { firstName: "Tom", lastName: "Dale", homePlanet: league, id: '1' }); + league = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); + env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", homePlanet: league, id: '1' }); }); env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { @@ -634,8 +634,8 @@ test("serialize with embedded objects (hasMany relationship) supports serialize: test("serialize with (new) embedded objects (hasMany relationship)", function() { run(function() { - league = env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }); - env.store.createRecord(SuperVillain, { firstName: "Tom", lastName: "Dale", homePlanet: league }); + league = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); + env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", homePlanet: league }); }); env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { @@ -662,9 +662,9 @@ test("serialize with (new) embedded objects (hasMany relationship)", function() test("serialize with embedded objects (hasMany relationships, including related objects not embedded)", function() { run(function() { - superVillain = env.store.createRecord(SuperVillain, { id: 1, firstName: "Super", lastName: "Villian" }); - evilMinion = env.store.createRecord(EvilMinion, { id: 1, name: "Evil Minion", superVillian: superVillain }); - secretWeapon = env.store.createRecord(SecretWeapon, { id: 1, name: "Secret Weapon", superVillain: superVillain }); + superVillain = env.store.createRecord('super-villain', { id: 1, firstName: "Super", lastName: "Villian" }); + evilMinion = env.store.createRecord('evil-minion', { id: 1, name: "Evil Minion", superVillian: superVillain }); + secretWeapon = env.store.createRecord('secret-weapon', { id: 1, name: "Secret Weapon", superVillain: superVillain }); superVillain.get('evilMinions').pushObject(evilMinion); superVillain.get('secretWeapons').pushObject(secretWeapon); }); @@ -738,7 +738,7 @@ test("extractSingle with embedded object (belongsTo relationship)", function() { }); run(function() { - env.store.find("secretLab", 101).then(function(secretLab) { + env.store.find('secret-lab', 101).then(function(secretLab) { equal(secretLab.get('id'), '101'); equal(secretLab.get('minionCapacity'), 5000); equal(secretLab.get('vicinity'), 'California, USA'); @@ -760,10 +760,10 @@ test("serialize with embedded object (belongsTo relationship)", function() { // records with an id, persisted tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - secretLab: env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -803,7 +803,7 @@ test("serialize with embedded object (belongsTo relationship) works with differe run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) @@ -842,10 +842,10 @@ test("serialize with embedded object (belongsTo relationship, new no id)", funct run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", - secretLab: env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA" }), - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -879,10 +879,10 @@ test("serialize with embedded object (belongsTo relationship) supports serialize run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - secretLab: env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -914,10 +914,10 @@ test("serialize with embedded object (belongsTo relationship) supports serialize run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - secretLab: env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -949,10 +949,10 @@ test("serialize with embedded object (belongsTo relationship) supports serialize run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - secretLab: env.store.createRecord('secretLab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), - homePlanet: env.store.createRecord('homePlanet', { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -982,10 +982,10 @@ test("serialize with embedded object (belongsTo relationship) supports serialize var tom, json; run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - secretLab: env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -1012,10 +1012,10 @@ test("serialize with embedded object (belongsTo relationship) serializes the id run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - secretLab: env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + secretLab: env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }), + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -1044,9 +1044,9 @@ test("when related record is not present, serialize embedded record (with a belo run(function() { tom = env.store.createRecord( - SuperVillain, + 'super-villain', { firstName: "Tom", lastName: "Dale", id: "1", - homePlanet: env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }) + homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" }) } ); }); @@ -1106,13 +1106,13 @@ test("extractSingle with multiply-nested belongsTo", function() { superVillain: "1" }, "Primary hash was correct"); - equal(env.store.recordForId("superVillain", "1").get("firstName"), "Tom", "Secondary record, Tom, found in the steore"); - equal(env.store.recordForId("homePlanet", "1").get("name"), "Umber", "Nested Secondary record, Umber, found in the store"); + equal(env.store.recordForId('super-villain', "1").get("firstName"), "Tom", "Secondary record, Tom, found in the steore"); + equal(env.store.recordForId('home-planet', "1").get("name"), "Umber", "Nested Secondary record, Umber, found in the store"); }); test("extractSingle with polymorphic hasMany", function() { SuperVillain.reopen({ - secretWeapons: DS.hasMany("secretWeapon", { polymorphic: true }) + secretWeapons: DS.hasMany('secret-weapon', { polymorphic: true }) }); env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); @@ -1159,8 +1159,8 @@ test("extractSingle with polymorphic hasMany", function() { ] }, "Primary hash was correct"); - equal(env.store.recordForId("secretWeapon", "1").get("name"), "The Death Star", "Embedded polymorphic SecretWeapon found"); - equal(env.store.recordForId("lightSaber", "1").get("name"), "Tom's LightSaber", "Embedded polymorphic LightSaber found"); + equal(env.store.recordForId('secret-weapon', "1").get("name"), "The Death Star", "Embedded polymorphic SecretWeapon found"); + equal(env.store.recordForId('light-saber', "1").get("name"), "Tom's LightSaber", "Embedded polymorphic LightSaber found"); }); @@ -1169,7 +1169,7 @@ test("extractSingle with polymorphic belongsTo", function() { expect(2); SuperVillain.reopen({ - secretLab: DS.belongsTo("secretLab", { polymorphic: true }) + secretLab: DS.belongsTo('secret-lab', { polymorphic: true }) }); env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); @@ -1207,20 +1207,20 @@ test("extractSingle with polymorphic belongsTo", function() { secretLabType: "bat-cave" }, "Primary has was correct"); - equal(env.store.recordForId("batCave", "1").get("infiltrated"), true, "Embedded polymorphic BatCave was found"); + equal(env.store.recordForId('bat-cave', "1").get("infiltrated"), true, "Embedded polymorphic BatCave was found"); }); test("Mixin can be used with RESTSerializer which does not define keyForAttribute", function() { run(function() { - homePlanet = env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }); - secretLab = env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }); - superVillain = env.store.createRecord(SuperVillain, { + homePlanet = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); + secretLab = env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }); + superVillain = env.store.createRecord('super-villain', { id: "1", firstName: "Super", lastName: "Villian", homePlanet: homePlanet, secretLab: secretLab }); - secretWeapon = env.store.createRecord(SecretWeapon, { id: "1", name: "Secret Weapon", superVillain: superVillain }); + secretWeapon = env.store.createRecord('secret-weapon', { id: "1", name: "Secret Weapon", superVillain: superVillain }); superVillain.get('secretWeapons').pushObject(secretWeapon); - evilMinion = env.store.createRecord(EvilMinion, { id: "1", name: "Evil Minion", superVillian: superVillain }); + evilMinion = env.store.createRecord('evil-minion', { id: "1", name: "Evil Minion", superVillian: superVillain }); superVillain.get('evilMinions').pushObject(evilMinion); }); @@ -1288,19 +1288,19 @@ test("normalize with custom belongsTo primary key", function() { superVillain: "1" }, "Primary hash was correct"); - equal(env.store.recordForId("superVillain", "1").get("firstName"), "Tom", "Secondary record, Tom, found in the steore"); + equal(env.store.recordForId('super-villain', "1").get("firstName"), "Tom", "Secondary record, Tom, found in the steore"); }); test("serializing relationships with an embedded and without calls super when not attr not present", function() { run(function() { - homePlanet = env.store.createRecord(HomePlanet, { name: "Villain League", id: "123" }); - secretLab = env.store.createRecord(SecretLab, { minionCapacity: 5000, vicinity: "California, USA", id: "101" }); - superVillain = env.store.createRecord(SuperVillain, { + homePlanet = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); + secretLab = env.store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }); + superVillain = env.store.createRecord('super-villain', { id: "1", firstName: "Super", lastName: "Villian", homePlanet: homePlanet, secretLab: secretLab }); - secretWeapon = env.store.createRecord(SecretWeapon, { id: "1", name: "Secret Weapon", superVillain: superVillain }); + secretWeapon = env.store.createRecord('secret-weapon', { id: "1", name: "Secret Weapon", superVillain: superVillain }); superVillain.get('secretWeapons').pushObject(secretWeapon); - evilMinion = env.store.createRecord(EvilMinion, { id: "1", name: "Evil Minion", superVillian: superVillain }); + evilMinion = env.store.createRecord('evil-minion', { id: "1", name: "Evil Minion", superVillian: superVillain }); superVillain.get('evilMinions').pushObject(evilMinion); }); diff --git a/packages/ember-data/tests/integration/serializers/json-serializer-test.js b/packages/ember-data/tests/integration/serializers/json-serializer-test.js index d9be2147f05..be5c04ee057 100644 --- a/packages/ember-data/tests/integration/serializers/json-serializer-test.js +++ b/packages/ember-data/tests/integration/serializers/json-serializer-test.js @@ -31,7 +31,7 @@ module("integration/serializer/json - JSONSerializer", { test("serializeAttribute", function() { run(function() { - post = env.store.createRecord("post", { title: "Rails is omakase" }); + post = env.store.createRecord('post', { title: "Rails is omakase" }); }); var json = {}; @@ -50,7 +50,7 @@ test("serializeAttribute respects keyForAttribute", function() { })); run(function() { - post = env.store.createRecord("post", { title: "Rails is omakase" }); + post = env.store.createRecord('post', { title: "Rails is omakase" }); }); var json = {}; @@ -61,8 +61,8 @@ test("serializeAttribute respects keyForAttribute", function() { test("serializeBelongsTo", function() { run(function() { - post = env.store.createRecord(Post, { title: "Rails is omakase", id: "1" }); - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: post }); + post = env.store.createRecord('post', { title: "Rails is omakase", id: "1" }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: post }); }); var json = {}; @@ -74,7 +74,7 @@ test("serializeBelongsTo", function() { test("serializeBelongsTo with null", function() { run(function() { - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: null }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: null }); }); var json = {}; @@ -90,7 +90,7 @@ test("async serializeBelongsTo with null", function() { post: DS.belongsTo('post', { async: true }) }); run(function() { - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: null }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: null }); }); var json = {}; @@ -108,8 +108,8 @@ test("serializeBelongsTo respects keyForRelationship", function() { } })); run(function() { - post = env.store.createRecord(Post, { title: "Rails is omakase", id: "1" }); - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: post }); + post = env.store.createRecord('post', { title: "Rails is omakase", id: "1" }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: post }); }); var json = {}; @@ -128,8 +128,8 @@ test("serializeHasMany respects keyForRelationship", function() { })); run(function() { - post = env.store.createRecord(Post, { title: "Rails is omakase", id: "1" }); - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: post, id: "1" }); + post = env.store.createRecord('post', { title: "Rails is omakase", id: "1" }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: post, id: "1" }); }); var json = {}; @@ -143,7 +143,7 @@ test("serializeHasMany respects keyForRelationship", function() { test("serializeIntoHash", function() { run(function() { - post = env.store.createRecord("post", { title: "Rails is omakase" }); + post = env.store.createRecord('post', { title: "Rails is omakase" }); }); var json = {}; @@ -191,8 +191,8 @@ test("serializePolymorphicType async", function() { })); run(function() { - post = env.store.createRecord(Post, { title: 'Rails is omakase', id: 1 }); - comment = env.store.createRecord(Comment, { body: 'Omakase is delicious', post: post }); + post = env.store.createRecord('post', { title: 'Rails is omakase', id: 1 }); + comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); }); env.container.lookup('serializer:comment').serializeBelongsTo(comment._createSnapshot(), {}, { key: 'post', options: { async: true, polymorphic: true } }); @@ -250,8 +250,8 @@ test('Serializer should respect the attrs hash when serializing records', functi var parentPost; run(function() { - parentPost = env.store.push("post", { id: 2, title: "Rails is omakase" }); - post = env.store.createRecord("post", { title: "Rails is omakase", parentPost: parentPost }); + parentPost = env.store.push('post', { id: 2, title: "Rails is omakase" }); + post = env.store.createRecord('post', { title: "Rails is omakase", parentPost: parentPost }); }); var payload = env.container.lookup("serializer:post").serialize(post._createSnapshot()); @@ -269,7 +269,7 @@ test('Serializer respects `serialize: false` on the attrs hash', function() { })); run(function() { - post = env.store.createRecord("post", { title: "Rails is omakase" }); + post = env.store.createRecord('post', { title: "Rails is omakase" }); }); var payload = env.container.lookup("serializer:post").serialize(post._createSnapshot()); @@ -287,8 +287,8 @@ test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` p })); run(function() { - post = env.store.createRecord("post", { title: "Rails is omakase" }); - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: post }); + post = env.store.createRecord('post', { title: "Rails is omakase" }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: post }); }); var serializer = env.container.lookup("serializer:post"); @@ -307,8 +307,8 @@ test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` })); run(function() { - post = env.store.createRecord("post", { title: "Rails is omakase" }); - comment = env.store.createRecord(Comment, { body: "Omakase is delicious", post: post }); + post = env.store.createRecord('post', { title: "Rails is omakase" }); + comment = env.store.createRecord('comment', { body: "Omakase is delicious", post: post }); }); var serializer = env.container.lookup("serializer:comment"); @@ -370,7 +370,7 @@ test("Serializer should respect the primaryKey attribute when serializing record })); run(function() { - post = env.store.createRecord("post", { id: "1", title: "Rails is omakase" }); + post = env.store.createRecord('post', { id: "1", title: "Rails is omakase" }); }); var payload = env.container.lookup("serializer:post").serialize(post._createSnapshot(), { includeId: true }); @@ -477,8 +477,8 @@ test('serializeBelongsTo with async polymorphic', function() { })); run(function() { - post = env.store.createRecord(Post, { title: 'Kitties are omakase', id: '1' }); - favorite = env.store.createRecord(Favorite, { post: post, id: '3' }); + post = env.store.createRecord('post', { title: 'Kitties are omakase', id: '1' }); + favorite = env.store.createRecord('favorite', { post: post, id: '3' }); }); env.container.lookup('serializer:favorite').serializeBelongsTo(favorite._createSnapshot(), json, { key: 'post', options: { polymorphic: true, async: true } }); diff --git a/packages/ember-data/tests/integration/serializers/rest-serializer-test.js b/packages/ember-data/tests/integration/serializers/rest-serializer-test.js index fc5abc29ccb..b433611cb08 100644 --- a/packages/ember-data/tests/integration/serializers/rest-serializer-test.js +++ b/packages/ember-data/tests/integration/serializers/rest-serializer-test.js @@ -6,22 +6,22 @@ module("integration/serializer/rest - RESTSerializer", { setup: function() { HomePlanet = DS.Model.extend({ name: DS.attr('string'), - superVillains: DS.hasMany('superVillain') + superVillains: DS.hasMany('super-villain') }); SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), - homePlanet: DS.belongsTo("homePlanet"), - evilMinions: DS.hasMany("evilMinion") + homePlanet: DS.belongsTo('home-planet'), + evilMinions: DS.hasMany('evil-minion') }); EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('superVillain'), + superVillain: DS.belongsTo('super-villain'), name: DS.attr('string') }); YellowMinion = EvilMinion.extend(); DoomsdayDevice = DS.Model.extend({ name: DS.attr('string'), - evilMinion: DS.belongsTo('evilMinion', { polymorphic: true }) + evilMinion: DS.belongsTo('evil-minion', { polymorphic: true }) }); Comment = DS.Model.extend({ body: DS.attr('string'), @@ -36,11 +36,11 @@ module("integration/serializer/rest - RESTSerializer", { doomsdayDevice: DoomsdayDevice, comment: Comment }); - env.store.modelFor('superVillain'); - env.store.modelFor('homePlanet'); - env.store.modelFor('evilMinion'); - env.store.modelFor('yellowMinion'); - env.store.modelFor('doomsdayDevice'); + env.store.modelFor('super-villain'); + env.store.modelFor('home-planet'); + env.store.modelFor('evil-minion'); + env.store.modelFor('yellow-minion'); + env.store.modelFor('doomsday-device'); env.store.modelFor('comment'); }, @@ -80,7 +80,7 @@ test("extractArray with custom modelNameFromPayloadKey", function() { }]); run(function() { - env.store.find("superVillain", 1).then(function(minion) { + env.store.find('super-villain', 1).then(function(minion) { equal(minion.get('firstName'), "Tom"); }); }); @@ -179,18 +179,18 @@ test("pushPayload - single record payload - warning with custom modelNameFromPay warns(function() { run(function() { - env.store.pushPayload("homePlanet", jsonHash); + env.store.pushPayload('home-planet', jsonHash); }); }, /Encountered "home_planet" in payload, but no model was found for model name "garbage"/); // assert non-warned records get pushed into store correctly - var superVillain = env.store.getById("superVillain", "1"); + var superVillain = env.store.getById('super-villain', "1"); equal(get(superVillain, "firstName"), "Stanley"); // Serializers are singletons, so that"s why we use the store which // looks at the container to look it up - env.store.serializerFor("homePlanet").reopen({ + env.store.serializerFor('home-planet').reopen({ modelNameFromPayloadKey: function(root) { // should not warn if a model is found. return Ember.String.camelize(Ember.String.singularize(root)); @@ -204,8 +204,8 @@ test("pushPayload - single record payload - warning with custom modelNameFromPay noWarns(function() { run(function() { - env.store.pushPayload("homePlanet", jsonHash); - homePlanet = env.store.getById("homePlanet", "1"); + env.store.pushPayload('home-planet', jsonHash); + homePlanet = env.store.getById('home-planet', "1"); }); }); @@ -235,17 +235,17 @@ test("pushPayload - multiple record payload (extractArray) - warning with custom warns(function() { run(function() { - env.store.pushPayload("homePlanet", jsonHash); + env.store.pushPayload('home-planet', jsonHash); }); }, /Encountered "home_planets" in payload, but no model was found for model name "garbage"/); // assert non-warned records get pushed into store correctly - var superVillain = env.store.getById("superVillain", "1"); + var superVillain = env.store.getById('super-villain', "1"); equal(get(superVillain, "firstName"), "Stanley"); // Serializers are singletons, so that"s why we use the store which // looks at the container to look it up - env.store.serializerFor("homePlanet").reopen({ + env.store.serializerFor('home-planet').reopen({ modelNameFromPayloadKey: function(root) { // should not warn if a model is found. return Ember.String.camelize(Ember.String.singularize(root)); @@ -259,8 +259,8 @@ test("pushPayload - multiple record payload (extractArray) - warning with custom noWarns(function() { run(function() { - env.store.pushPayload("homePlanet", jsonHash); - homePlanet = env.store.getById("homePlanet", "1"); + env.store.pushPayload('home-planet', jsonHash); + homePlanet = env.store.getById('home-planet', "1"); }); }); @@ -271,8 +271,8 @@ test("pushPayload - multiple record payload (extractArray) - warning with custom test("serialize polymorphicType", function() { var tom, ray; run(function() { - tom = env.store.createRecord(YellowMinion, { name: "Alex", id: "124" }); - ray = env.store.createRecord(DoomsdayDevice, { evilMinion: tom, name: "DeathRay" }); + tom = env.store.createRecord('yellow-minion', { name: "Alex", id: "124" }); + ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); }); var json = env.restSerializer.serialize(ray._createSnapshot()); @@ -288,8 +288,8 @@ test("serialize polymorphicType with decamelized modelName", function() { YellowMinion.modelName = 'yellow-minion'; var tom, ray; run(function() { - tom = env.store.createRecord(YellowMinion, { name: "Alex", id: "124" }); - ray = env.store.createRecord(DoomsdayDevice, { evilMinion: tom, name: "DeathRay" }); + tom = env.store.createRecord('yellow-minion', { name: "Alex", id: "124" }); + ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); }); var json = env.restSerializer.serialize(ray._createSnapshot()); @@ -324,7 +324,7 @@ test("normalizePayload is called during extractSingle", function() { test("serialize polymorphic when associated object is null", function() { var ray; run(function() { - ray = env.store.createRecord(DoomsdayDevice, { name: "DeathRay" }); + ray = env.store.createRecord('doomsday-device', { name: "DeathRay" }); }); var json = env.restSerializer.serialize(ray._createSnapshot()); @@ -355,8 +355,8 @@ test("extractArray can load secondary records of the same type without affecting equal(array.length, 1, "The query count is unaffected"); - equal(env.store.recordForId("comment", "2").get("body"), "Child Comment 1", "Secondary records are in the store"); - equal(env.store.recordForId("comment", "3").get("body"), "Child Comment 2", "Secondary records are in the store"); + equal(env.store.recordForId('comment', "2").get("body"), "Child Comment 1", "Secondary records are in the store"); + equal(env.store.recordForId('comment', "3").get("body"), "Child Comment 2", "Secondary records are in the store"); }); test("extractSingle loads secondary records with correct serializer", function() { @@ -511,7 +511,7 @@ test('normalize should allow for different levels of normalization', function() test("serializeIntoHash", function() { run(function() { - league = env.store.createRecord(HomePlanet, { name: "Umber", id: "123" }); + league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); }); var json = {}; @@ -527,7 +527,7 @@ test("serializeIntoHash", function() { test("serializeIntoHash with decamelized modelName", function() { HomePlanet.modelName = 'home-planet'; run(function() { - league = env.store.createRecord(HomePlanet, { name: "Umber", id: "123" }); + league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); }); var json = {}; @@ -546,8 +546,8 @@ test('serializeBelongsTo with async polymorphic', function() { var expected = { evilMinion: '1', evilMinionType: 'evilMinion' }; run(function() { - evilMinion = env.store.createRecord('evilMinion', { id: 1, name: 'Tomster' }); - doomsdayDevice = env.store.createRecord('doomsdayDevice', { id: 2, name: 'Yehuda', evilMinion: evilMinion }); + evilMinion = env.store.createRecord('evil-minion', { id: 1, name: 'Tomster' }); + doomsdayDevice = env.store.createRecord('doomsday-device', { id: 2, name: 'Yehuda', evilMinion: evilMinion }); }); env.restSerializer.serializeBelongsTo(doomsdayDevice._createSnapshot(), json, { key: 'evilMinion', options: { polymorphic: true, async: true } }); @@ -557,7 +557,7 @@ test('serializeBelongsTo with async polymorphic', function() { test('serializeIntoHash uses payloadKeyFromModelName to normalize the payload root key', function() { run(function() { - league = env.store.createRecord(HomePlanet, { name: "Umber", id: "123" }); + league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); }); var json = {}; env.registry.register('serializer:home-planet', DS.RESTSerializer.extend({ diff --git a/packages/ember-data/tests/integration/store-test.js b/packages/ember-data/tests/integration/store-test.js index 864c464c9b8..8ede49bf876 100644 --- a/packages/ember-data/tests/integration/store-test.js +++ b/packages/ember-data/tests/integration/store-test.js @@ -57,7 +57,7 @@ asyncTest("destroying record during find doesn't cause error", function() { find: function(store, type, id, snapshot) { return new Ember.RSVP.Promise(function(resolve, reject) { Ember.run.next(function() { - store.unloadAll(type); + store.unloadAll(type.modelName); reject(); }); }); diff --git a/packages/ember-data/tests/unit/adapter-populated-record-array-test.js b/packages/ember-data/tests/unit/adapter-populated-record-array-test.js index 9de3a89ea5b..74a1a9c6652 100644 --- a/packages/ember-data/tests/unit/adapter-populated-record-array-test.js +++ b/packages/ember-data/tests/unit/adapter-populated-record-array-test.js @@ -9,24 +9,24 @@ var adapter = DS.Adapter.extend({ module("unit/adapter_populated_record_array - DS.AdapterPopulatedRecordArray", { setup: function() { + Person = DS.Model.extend({ + name: DS.attr('string') + }); store = createStore({ - adapter: adapter + adapter: adapter, + person: Person }); - array = [{ id: '1', name: "Scumbag Dale" }, { id: '2', name: "Scumbag Katz" }, { id: '3', name: "Scumbag Bryn" }]; - Person = DS.Model.extend({ - name: DS.attr('string') - }); } }); test("when a record is deleted in an adapter populated record array, it should be removed", function() { var recordArray = store.recordArrayManager - .createAdapterPopulatedRecordArray(Person, null); + .createAdapterPopulatedRecordArray(store.modelFor('person'), null); run(function() { recordArray.load(array); diff --git a/packages/ember-data/tests/unit/debug-test.js b/packages/ember-data/tests/unit/debug-test.js index f4906b99460..95589a6d696 100644 --- a/packages/ember-data/tests/unit/debug-test.js +++ b/packages/ember-data/tests/unit/debug-test.js @@ -16,7 +16,7 @@ test("_debugInfo groups the attributes and relationships correctly", function() var User = DS.Model.extend({ name: DS.attr('string'), isDrugAddict: DS.attr('boolean'), - maritalStatus: DS.belongsTo('maritalStatus'), + maritalStatus: DS.belongsTo('marital-status'), posts: DS.hasMany('post') }); @@ -29,7 +29,7 @@ test("_debugInfo groups the attributes and relationships correctly", function() var record; run(function() { - record = store.createRecord(User); + record = store.createRecord('user'); }); var propertyInfo = record._debugInfo().propertyInfo; diff --git a/packages/ember-data/tests/unit/model-test.js b/packages/ember-data/tests/unit/model-test.js index d6b76fa0ccf..8063ea1dde8 100644 --- a/packages/ember-data/tests/unit/model-test.js +++ b/packages/ember-data/tests/unit/model-test.js @@ -2,16 +2,19 @@ var get = Ember.get; var set = Ember.set; var run = Ember.run; -var Person, store, array; +var Person, store, array, env; module("unit/model - DS.Model", { setup: function() { - store = createStore(); - Person = DS.Model.extend({ name: DS.attr('string'), isDrugAddict: DS.attr('boolean') }); + + env = setupStore({ + person: Person + }); + store = env.store; }, teardown: function() { @@ -26,7 +29,7 @@ module("unit/model - DS.Model", { test("can have a property set on it", function() { var record; run(function() { - record = store.createRecord(Person); + record = store.createRecord('person'); set(record, 'name', 'bar'); }); @@ -37,8 +40,8 @@ test("setting a property on a record that has not changed does not cause it to b expect(2); run(function() { - store.push(Person, { id: 1, name: "Peter", isDrugAddict: true }); - store.find(Person, 1).then(function(person) { + store.push('person', { id: 1, name: "Peter", isDrugAddict: true }); + store.find('person', 1).then(function(person) { equal(person.get('isDirty'), false, "precond - person record should not be dirty"); person.set('name', "Peter"); @@ -53,8 +56,8 @@ test("resetting a property on a record cause it to become clean again", function expect(3); run(function() { - store.push(Person, { id: 1, name: "Peter", isDrugAddict: true }); - store.find(Person, 1).then(function(person) { + store.push('person', { id: 1, name: "Peter", isDrugAddict: true }); + store.find('person', 1).then(function(person) { equal(person.get('isDirty'), false, "precond - person record should not be dirty"); person.set('isDrugAddict', false); equal(person.get('isDirty'), true, "record becomes dirty after setting property to a new value"); @@ -68,8 +71,8 @@ test("a record becomes clean again only if all changed properties are reset", fu expect(5); run(function() { - store.push(Person, { id: 1, name: "Peter", isDrugAddict: true }); - store.find(Person, 1).then(function(person) { + store.push('person', { id: 1, name: "Peter", isDrugAddict: true }); + store.find('person', 1).then(function(person) { equal(person.get('isDirty'), false, "precond - person record should not be dirty"); person.set('isDrugAddict', false); equal(person.get('isDirty'), true, "record becomes dirty after setting one property to a new value"); @@ -87,8 +90,8 @@ test("a record reports its unique id via the `id` property", function() { expect(1); run(function() { - store.push(Person, { id: 1 }); - store.find(Person, 1).then(function(record) { + store.push('person', { id: 1 }); + store.find('person', 1).then(function(record) { equal(get(record, 'id'), 1, "reports id as id by default"); }); }); @@ -98,8 +101,8 @@ test("a record's id is included in its toString representation", function() { expect(1); run(function() { - store.push(Person, { id: 1 }); - store.find(Person, 1).then(function(record) { + store.push('person', { id: 1 }); + store.find('person', 1).then(function(record) { equal(record.toString(), '<(subclass of DS.Model):'+Ember.guidFor(record)+':1>', "reports id in toString"); }); }); @@ -111,10 +114,14 @@ test("trying to set an `id` attribute should raise", function() { name: DS.attr('string') }); + var store = createStore({ + person: Person + }); + expectAssertion(function() { run(function() { - store.push(Person, { id: 1, name: "Scumdale" }); - store.find(Person, 1); + store.push('person', { id: 1, name: "Scumdale" }); + store.find('person', 1); }); }, /You may not set `id`/); }); @@ -128,8 +135,8 @@ test("a collision of a record's id with object function's name", function() { Object.prototype.watch = function() {}; } run(function() { - store.push(Person, { id: 'watch' }); - store.find(Person, 'watch').then(function(record) { + store.push('person', { id: 'watch' }); + store.find('person', 'watch').then(function(record) { equal(get(record, 'id'), 'watch', "record is successfully created and could be found by its id"); }); }); @@ -144,9 +151,9 @@ test("it should use `_reference` and not `reference` to store its reference", fu expect(1); run(function() { - store.push(Person, { id: 1 }); + store.push('person', { id: 1 }); - store.find(Person, 1).then(function(record) { + store.find('person', 1).then(function(record) { equal(record.get('reference'), undefined, "doesn't shadow reference key"); }); }); @@ -155,18 +162,20 @@ test("it should use `_reference` and not `reference` to store its reference", fu test("it should cache attributes", function() { expect(2); - var store = createStore(); - var Post = DS.Model.extend({ updatedAt: DS.attr('string') }); + var store = createStore({ + post: Post + }); + var dateString = "Sat, 31 Dec 2011 00:08:16 GMT"; var date = new Date(dateString); run(function() { - store.push(Post, { id: 1 }); - store.find(Post, 1).then(function(record) { + store.push('post', { id: 1 }); + store.find('post', 1).then(function(record) { run(function() { record.set('updatedAt', date); }); @@ -187,11 +196,16 @@ test("changedAttributes() return correct values", function() { likes: DS.attr('string'), isMascot: DS.attr('boolean') }); + + var store = createStore({ + mascot: Mascot + }); + var mascot; run(function() { - mascot = store.push(Mascot, { id: 1, likes: 'JavaScript', isMascot: true }); + mascot = store.push('mascot', { id: 1, likes: 'JavaScript', isMascot: true }); }); deepEqual({}, mascot.changedAttributes(), 'there are no initial changes'); @@ -212,10 +226,15 @@ test("a DS.Model does not require an attribute type", function() { var Tag = DS.Model.extend({ name: DS.attr() }); + + var store = createStore({ + tag: Tag + }); + var tag; run(function() { - tag = store.createRecord(Tag, { name: "test" }); + tag = store.createRecord('tag', { name: "test" }); }); equal(get(tag, 'name'), "test", "the value is persisted"); @@ -225,10 +244,14 @@ test("a DS.Model can have a defaultValue without an attribute type", function() var Tag = DS.Model.extend({ name: DS.attr({ defaultValue: "unknown" }) }); + + var store = createStore({ + tag: Tag + }); var tag; run(function() { - tag = store.createRecord(Tag); + tag = store.createRecord('tag'); }); equal(get(tag, 'name'), "unknown", "the default value is found"); @@ -241,7 +264,9 @@ test("Calling attr(), belongsTo() or hasMany() throws a warning", function() { name: DS.attr('string') }); - var store = createStore({ person: Person }); + var store = createStore({ + person: Person + }); run(function() { var person = store.createRecord('person', { id: 1, name: 'TomHuda' }); @@ -264,9 +289,9 @@ test("supports pushedData in root.deleted.uncommitted", function() { var record; var hash = { id: 1 }; run(function() { - record = store.push(Person, hash); + record = store.push('person', hash); record.deleteRecord(); - store.push(Person, hash); + store.push('person', hash); equal(get(record, 'currentState.stateName'), 'root.deleted.uncommitted', 'record accepts pushedData is in root.deleted.uncommitted state'); }); @@ -277,9 +302,12 @@ module("unit/model - DS.Model updating", { setup: function() { array = [{ id: 1, name: "Scumbag Dale" }, { id: 2, name: "Scumbag Katz" }, { id: 3, name: "Scumbag Bryn" }]; Person = DS.Model.extend({ name: DS.attr('string') }); - store = createStore(); + env = setupStore({ + person: Person + }); + store = env.store; run(function() { - store.pushMany(Person, array); + store.pushMany('person', array); }); }, teardown: function() { @@ -296,7 +324,7 @@ test("a DS.Model can update its attributes", function() { expect(1); run(function() { - store.find(Person, 2).then(function(person) { + store.find('person', 2).then(function(person) { set(person, 'name', "Brohuda Katz"); equal(get(person, 'name'), "Brohuda Katz", "setting took hold"); }); @@ -309,8 +337,12 @@ test("a DS.Model can have a defaultValue", function() { }); var tag; + var store = createStore({ + tag: Tag + }); + run(function() { - tag = store.createRecord(Tag); + tag = store.createRecord('tag'); }); equal(get(tag, 'name'), "unknown", "the default value is found"); @@ -334,8 +366,12 @@ test("a DS.model can define 'setUnknownProperty'", function() { } }); + var store = createStore({ + tag: Tag + }); + run(function() { - tag = store.createRecord(Tag, { name: "old" }); + tag = store.createRecord('tag', { name: "old" }); set(tag, "title", "new"); }); @@ -352,8 +388,12 @@ test("a defaultValue for an attribute can be a function", function() { }); var tag; + var store = createStore({ + tag: Tag + }); + run(function() { - tag = store.createRecord(Tag); + tag = store.createRecord('tag'); }); equal(get(tag, 'createdAt'), "le default value", "the defaultValue function is evaluated"); }); @@ -370,10 +410,14 @@ test("a defaultValue function gets the record, options, and key", function() { } }) }); + + var store = createStore({ + tag: Tag + }); var tag; run(function() { - tag = store.createRecord(Tag); + tag = store.createRecord('tag'); }); get(tag, 'createdAt'); @@ -383,10 +427,15 @@ test("setting a property to undefined on a newly created record should not impac var Tag = DS.Model.extend({ name: DS.attr('string') }); + + var store = createStore({ + tag: Tag + }); + var tag; run(function() { - tag = store.createRecord(Tag); + tag = store.createRecord('tag'); set(tag, 'name', 'testing'); set(tag, 'name', undefined); }); @@ -394,7 +443,7 @@ test("setting a property to undefined on a newly created record should not impac equal(get(tag, 'currentState.stateName'), "root.loaded.created.uncommitted"); run(function() { - tag = store.createRecord(Tag, { name: undefined }); + tag = store.createRecord('tag', { name: undefined }); }); equal(get(tag, 'currentState.stateName'), "root.loaded.created.uncommitted"); @@ -406,7 +455,7 @@ test("setting a property back to its original value removes the property from th expect(3); run(function() { - store.find(Person, 1).then(function(person) { + store.find('person', 1).then(function(person) { equal(person._attributes.name, undefined, "the `_attributes` hash is clean"); set(person, 'name', "Niceguy Dale"); @@ -434,7 +483,7 @@ module("unit/model - with a simple Person model", { person: Person }); run(function() { - store.pushMany(Person, array); + store.pushMany('person', array); }); }, teardown: function() { @@ -448,9 +497,9 @@ module("unit/model - with a simple Person model", { }); test("can ask if record with a given id is loaded", function() { - equal(store.recordIsLoaded(Person, 1), true, 'should have person with id 1'); equal(store.recordIsLoaded('person', 1), true, 'should have person with id 1'); - equal(store.recordIsLoaded(Person, 4), false, 'should not have person with id 4'); + equal(store.recordIsLoaded('person', 1), true, 'should have person with id 1'); + equal(store.recordIsLoaded('person', 4), false, 'should not have person with id 4'); equal(store.recordIsLoaded('person', 4), false, 'should not have person with id 4'); }); @@ -460,7 +509,7 @@ test("a listener can be added to a record", function() { var record; run(function() { - record = store.createRecord(Person); + record = store.createRecord('person'); }); record.on('event!', F); @@ -483,7 +532,7 @@ test("when an event is triggered on a record the method with the same name is in var record; run(function() { - record = store.createRecord(Person); + record = store.createRecord('person'); }); record.eventNamedMethod = F; @@ -503,7 +552,7 @@ test("when a method is invoked from an event with the same name the arguments ar var record; run(function() { - record = store.createRecord(Person); + record = store.createRecord('person'); }); record.eventThatTriggersMethod = F; @@ -536,8 +585,8 @@ var converts = function(type, provided, expected) { }); run(function() { - testStore.push(Model, serializer.normalize(Model, { id: 1, name: provided })); - testStore.push(Model, serializer.normalize(Model, { id: 2 })); + testStore.push('model', serializer.normalize(Model, { id: 1, name: provided })); + testStore.push('model', serializer.normalize(Model, { id: 2 })); testStore.find('model', 1).then(function(record) { deepEqual(get(record, 'name'), expected, type + " coerces " + provided + " to " + expected); }); @@ -569,7 +618,7 @@ var convertsFromServer = function(type, provided, expected) { }); run(function() { - testStore.push(Model, serializer.normalize(Model, { id: "1", name: provided })); + testStore.push('model', serializer.normalize(Model, { id: "1", name: provided })); testStore.find('model', 1).then(function(record) { deepEqual(get(record, 'name'), expected, type + " coerces " + provided + " to " + expected); }); @@ -584,7 +633,7 @@ var convertsWhenSet = function(type, provided, expected) { var testStore = createStore({ model: Model }); run(function() { - testStore.push(Model, { id: 2 }); + testStore.push('model', { id: 2 }); testStore.find('model', 2).then(function(record) { set(record, 'name', provided); deepEqual(record.serialize().name, expected, type + " saves " + provided + " as " + expected); @@ -638,15 +687,18 @@ test("a DS.Model can describe Date attributes", function() { var dateString = "2011-12-31T00:08:16.000Z"; var date = new Date(Ember.Date.parse(dateString)); - var store = createStore(); var Person = DS.Model.extend({ updatedAt: DS.attr('date') }); + var store = createStore({ + person: Person + }); + run(function() { - store.push(Person, { id: 1 }); - store.find(Person, 1).then(function(record) { + store.push('person', { id: 1 }); + store.find('person', 1).then(function(record) { run(function() { record.set('updatedAt', date); }); @@ -658,13 +710,15 @@ test("a DS.Model can describe Date attributes", function() { }); test("don't allow setting", function() { - var store = createStore(); - var Person = DS.Model.extend(); var record; + var store = createStore({ + person: Person + }); + run(function() { - record = store.createRecord(Person); + record = store.createRecord('person'); }); raises(function() { @@ -682,11 +736,12 @@ test("ensure model exits loading state, materializes data and fulfills promise o find: function(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "John" }); } - }) + }), + person: Person }); run(function() { - store.find(Person, 1).then(function(person) { + store.find('person', 1).then(function(person) { equal(get(person, 'currentState.stateName'), 'root.loaded.saved', 'model is in loaded state'); equal(get(person, 'isLoaded'), true, 'model is loaded'); }); diff --git a/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js b/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js index 219f5998716..45cbd32c730 100644 --- a/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js +++ b/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js @@ -20,11 +20,12 @@ test("a record receives a didLoad callback when it has finished loading", functi }); var store = createStore({ - adapter: adapter + adapter: adapter, + person: Person }); run(function() { - store.find(Person, 1).then(function(person) { + store.find('person', 1).then(function(person) { equal(person.get('id'), "1", "The person's ID is available"); equal(person.get('name'), "Foo", "The person's properties are available"); }); @@ -60,12 +61,13 @@ test("a record receives a didUpdate callback when it has finished updating", fun }); var store = createStore({ - adapter: adapter + adapter: adapter, + person: Person }); var asyncPerson; run(function() { - asyncPerson = store.find(Person, 1); + asyncPerson = store.find('person', 1); }); equal(callCount, 0, "precond - didUpdate callback was not called yet"); @@ -103,14 +105,15 @@ test("a record receives a didCreate callback when it has finished updating", fun }); var store = createStore({ - adapter: adapter + adapter: adapter, + person: Person }); equal(callCount, 0, "precond - didCreate callback was not called yet"); var person; run(function() { - person = store.createRecord(Person, { id: 69, name: "Newt Gingrich" }); + person = store.createRecord('person', { id: 69, name: "Newt Gingrich" }); }); @@ -151,12 +154,13 @@ test("a record receives a didDelete callback when it has finished deleting", fun }); var store = createStore({ - adapter: adapter + adapter: adapter, + person: Person }); var asyncPerson; run(function() { - asyncPerson = store.find(Person, 1); + asyncPerson = store.find('person', 1); }); equal(callCount, 0, "precond - didDelete callback was not called yet"); @@ -190,12 +194,13 @@ test("an uncommited record also receives a didDelete callback when it is deleted }); var store = createStore({ - adapter: DS.Adapter.extend() + adapter: DS.Adapter.extend(), + person: Person }); var person; run(function() { - person = store.createRecord(Person, { name: 'Tomster' }); + person = store.createRecord('person', { name: 'Tomster' }); }); equal(callCount, 0, "precond - didDelete callback was not called yet"); @@ -237,12 +242,13 @@ test("a record receives a becameInvalid callback when it became invalid", functi }); var store = createStore({ - adapter: adapter + adapter: adapter, + person: Person }); var asyncPerson; run(function() { - asyncPerson = store.find(Person, 1); + asyncPerson = store.find('person', 1); }); equal(callCount, 0, "precond - becameInvalid callback was not called yet"); @@ -261,15 +267,18 @@ test("a record receives a becameInvalid callback when it became invalid", functi }); test("an ID of 0 is allowed", function() { - var store = createStore(); var Person = DS.Model.extend({ name: DS.attr('string') }); + var store = createStore({ + person: Person + }); + run(function() { - store.push(Person, { id: 0, name: "Tom Dale" }); + store.push('person', { id: 0, name: "Tom Dale" }); }); - equal(store.all(Person).objectAt(0).get('name'), "Tom Dale", "found record with id 0"); + equal(store.all('person').objectAt(0).get('name'), "Tom Dale", "found record with id 0"); }); diff --git a/packages/ember-data/tests/unit/model/merge-test.js b/packages/ember-data/tests/unit/model/merge-test.js index bd84896158b..353099942a3 100644 --- a/packages/ember-data/tests/unit/model/merge-test.js +++ b/packages/ember-data/tests/unit/model/merge-test.js @@ -19,10 +19,13 @@ test("When a record is in flight, changes can be made", function() { } }); var person; - var store = createStore({ adapter: adapter }); + var store = createStore({ + adapter: adapter, + person: Person + }); run(function() { - person = store.createRecord(Person, { name: "Tom Dale" }); + person = store.createRecord('person', { name: "Tom Dale" }); }); // Make sure saving isn't resolved synchronously @@ -52,11 +55,14 @@ test("When a record is in flight, pushes are applied underneath the in flight ch } }); - var store = createStore({ adapter: adapter }); + var store = createStore({ + adapter: adapter, + person: Person + }); var person; run(function() { - person = store.push(Person, { id: 1, name: "Tom" }); + person = store.push('person', { id: 1, name: "Tom" }); person.set('name', "Thomas Dale"); }); @@ -67,7 +73,7 @@ test("When a record is in flight, pushes are applied underneath the in flight ch person.set('name', "Tomasz Dale"); - store.push(Person, { id: 1, name: "Tommy Dale", city: "PDX" }); + store.push('person', { id: 1, name: "Tommy Dale", city: "PDX" }); equal(person.get('name'), "Tomasz Dale", "the local changes applied on top"); equal(person.get('city'), "PDX", "the pushed change is available"); @@ -81,11 +87,14 @@ test("When a record is in flight, pushes are applied underneath the in flight ch }); test("When a record is dirty, pushes are overridden by local changes", function() { - var store = createStore({ adapter: DS.Adapter }); + var store = createStore({ + adapter: DS.Adapter, + person: Person + }); var person; run(function() { - person = store.push(Person, { id: 1, name: "Tom Dale", city: "San Francisco" }); + person = store.push('person', { id: 1, name: "Tom Dale", city: "San Francisco" }); person.set('name', "Tomasz Dale"); }); @@ -94,7 +103,7 @@ test("When a record is dirty, pushes are overridden by local changes", function( equal(person.get('city'), "San Francisco", "the original data applies"); run(function() { - store.push(Person, { id: 1, name: "Thomas Dale", city: "Portland" }); + store.push('person', { id: 1, name: "Thomas Dale", city: "Portland" }); }); equal(person.get('isDirty'), true, "the local changes are reapplied"); @@ -111,11 +120,14 @@ test("A record with no changes can still be saved", function() { } }); - var store = createStore({ adapter: adapter }); + var store = createStore({ + adapter: adapter, + person: Person + }); var person; run(function() { - person = store.push(Person, { id: 1, name: "Tom Dale" }); + person = store.push('person', { id: 1, name: "Tom Dale" }); }); run(function() { @@ -134,11 +146,14 @@ test("A dirty record can be reloaded", function() { } }); - var store = createStore({ adapter: adapter }); + var store = createStore({ + adapter: adapter, + person: Person + }); var person; run(function() { - person = store.push(Person, { id: 1, name: "Tom Dale" }); + person = store.push('person', { id: 1, name: "Tom Dale" }); person.set('name', "Tomasz Dale"); }); diff --git a/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js b/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js index 0b788e23ff0..65e5cdc2c44 100644 --- a/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js +++ b/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js @@ -134,7 +134,7 @@ test("calling createRecord and passing in an undefined value for a relationship }); run(function() { - store.find(Person, 1).then(async(function(person) { + store.find('person', 1).then(async(function(person) { strictEqual(person.get('tag'), null, "undefined values should return null relationships"); })); }); @@ -249,7 +249,7 @@ test("belongsTo supports relationships to models with id 0", function() { equal(get(person, 'tag.name'), "friendly", "the tag should have name"); strictEqual(get(person, 'tag'), get(person, 'tag'), "the returned object is always the same"); - asyncEqual(get(person, 'tag'), store.find(Tag, 0), "relationship object is the same as object retrieved directly"); + asyncEqual(get(person, 'tag'), store.find('tag', 0), "relationship object is the same as object retrieved directly"); })); }); }); diff --git a/packages/ember-data/tests/unit/model/relationships/has-many-test.js b/packages/ember-data/tests/unit/model/relationships/has-many-test.js index dad161ea1b3..a637bcab2f9 100644 --- a/packages/ember-data/tests/unit/model/relationships/has-many-test.js +++ b/packages/ember-data/tests/unit/model/relationships/has-many-test.js @@ -64,7 +64,7 @@ test("hasMany handles pre-loaded relationships", function() { equal(get(get(person, 'tags'), 'length'), 2, "the length is updated after new data is loaded"); strictEqual(get(person, 'tags').objectAt(0), get(person, 'tags').objectAt(0), "the returned object is always the same"); - asyncEqual(get(person, 'tags').objectAt(0), store.find(Tag, 5), "relationship objects are the same as objects retrieved directly"); + asyncEqual(get(person, 'tags').objectAt(0), store.find('tag', 5), "relationship objects are the same as objects retrieved directly"); run(function() { store.push('person', { id: 3, name: "KSelden" }); @@ -86,7 +86,7 @@ test("hasMany handles pre-loaded relationships", function() { equal(get(pets.objectAt(0), 'name'), "fluffy", "the first pet should be correct"); run(function() { - store.push(Person, { id: 4, name: "Cyvid Hamluck", pets: [4, 12] }); + store.push('person', { id: 4, name: "Cyvid Hamluck", pets: [4, 12] }); }); equal(pets, get(cyvid, 'pets'), "a relationship returns the same object every time"); @@ -152,13 +152,13 @@ test("hasMany lazily loads async relationships", function() { equal(get(records.tags.objectAt(0), 'name'), "oohlala", "the first tag should be a Tag"); strictEqual(records.tags.objectAt(0), records.tags.objectAt(0), "the returned object is always the same"); - asyncEqual(records.tags.objectAt(0), store.find(Tag, 12), "relationship objects are the same as objects retrieved directly"); + asyncEqual(records.tags.objectAt(0), store.find('tag', 12), "relationship objects are the same as objects retrieved directly"); return get(wycats, 'tags'); }).then(function(tags) { var newTag; run(function() { - newTag = store.createRecord(Tag); + newTag = store.createRecord('tag'); tags.pushObject(newTag); }); }); @@ -335,12 +335,12 @@ test("it is possible to add a new item to a relationship", function() { }); run(function() { - store.find(Person, 1).then(function(person) { + store.find('person', 1).then(function(person) { var tag = get(person, 'tags').objectAt(0); equal(get(tag, 'name'), "ember", "precond - relationships work"); - tag = store.createRecord(Tag, { name: "js" }); + tag = store.createRecord('tag', { name: "js" }); get(person, 'tags').pushObject(tag); equal(get(person, 'tags').objectAt(1), tag, "newly added relationship works"); diff --git a/packages/ember-data/tests/unit/record-array-test.js b/packages/ember-data/tests/unit/record-array-test.js index 8f59201e64d..2992d8b98a9 100644 --- a/packages/ember-data/tests/unit/record-array-test.js +++ b/packages/ember-data/tests/unit/record-array-test.js @@ -16,13 +16,15 @@ module("unit/record_array - DS.RecordArray", { test("a record array is backed by records", function() { expect(3); - var store = createStore(); + var store = createStore({ + person: Person + }); run(function() { - store.pushMany(Person, array); + store.pushMany('person', array); }); run(function() { - store.findByIds(Person, [1,2,3]).then(function(records) { + store.findByIds('person', [1,2,3]).then(function(records) { for (var i=0, l=get(array, 'length'); i