diff --git a/Brocfile.js b/Brocfile.js index 41219d529c5..7510f7981d1 100644 --- a/Brocfile.js +++ b/Brocfile.js @@ -59,7 +59,6 @@ var yuidocTree = yuidoc('packages', { "options": { "paths": [ "packages/ember-data/lib", - "packages/activemodel-adapter/lib", "packages/ember-inflector/addon" ], "exclude": "vendor", @@ -89,7 +88,6 @@ function packageAddon(packagePath, vendorPath) { var packages = merge([ packageAddon('ember-inflector', 'node_modules/'), package('ember-data'), - package('activemodel-adapter'), package('ember') ]); diff --git a/lib/test-tree.js b/lib/test-tree.js index eff7cfc54e4..27d8211e187 100644 --- a/lib/test-tree.js +++ b/lib/test-tree.js @@ -7,7 +7,7 @@ var merge = require('broccoli-merge-trees'); module.exports = function testTree(sourceTree, compiled) { var emberDataFiles = pickFiles(sourceTree, { - files: ['**/{ember-data,activemodel-adapter}/**/*.{js,map}'], + files: ['**/ember-data/**/*.{js,map}'], srcDir: '/', destDir: '/' }); diff --git a/packages/activemodel-adapter/lib/main.js b/packages/activemodel-adapter/lib/main.js deleted file mode 100644 index 95fa5f1bfd9..00000000000 --- a/packages/activemodel-adapter/lib/main.js +++ /dev/null @@ -1,9 +0,0 @@ -import { - ActiveModelAdapter, - ActiveModelSerializer -} from "activemodel-adapter/system"; - -export { - ActiveModelAdapter, - ActiveModelSerializer -}; diff --git a/packages/activemodel-adapter/lib/setup-container.js b/packages/activemodel-adapter/lib/setup-container.js deleted file mode 100644 index 83f906e8606..00000000000 --- a/packages/activemodel-adapter/lib/setup-container.js +++ /dev/null @@ -1,14 +0,0 @@ -import ContainerProxy from "ember-data/system/container-proxy"; -import ActiveModelSerializer from "activemodel-adapter/system/active-model-serializer"; -import ActiveModelAdapter from "activemodel-adapter/system/active-model-adapter"; - -export default function setupActiveModelAdapter(registry, application) { - var proxy = new ContainerProxy(registry); - proxy.registerDeprecations([ - { deprecated: 'serializer:_ams', valid: 'serializer:-active-model' }, - { deprecated: 'adapter:_ams', valid: 'adapter:-active-model' } - ]); - - registry.register('serializer:-active-model', ActiveModelSerializer); - registry.register('adapter:-active-model', ActiveModelAdapter); -} diff --git a/packages/activemodel-adapter/lib/system.js b/packages/activemodel-adapter/lib/system.js deleted file mode 100644 index e4143515827..00000000000 --- a/packages/activemodel-adapter/lib/system.js +++ /dev/null @@ -1,7 +0,0 @@ -import ActiveModelAdapter from "activemodel-adapter/system/active-model-adapter"; -import ActiveModelSerializer from "activemodel-adapter/system/active-model-serializer"; - -export { - ActiveModelAdapter, - ActiveModelSerializer -}; diff --git a/packages/activemodel-adapter/lib/system/active-model-adapter.js b/packages/activemodel-adapter/lib/system/active-model-adapter.js deleted file mode 100644 index 3a3d206964b..00000000000 --- a/packages/activemodel-adapter/lib/system/active-model-adapter.js +++ /dev/null @@ -1,154 +0,0 @@ -import {RESTAdapter} from "ember-data/adapters"; -import {pluralize} from "ember-inflector"; -import { - InvalidError, - errorsHashToArray -} from "ember-data/adapters/errors"; - -/** - @module ember-data -*/ - -var decamelize = Ember.String.decamelize; -var underscore = Ember.String.underscore; - -/** - The ActiveModelAdapter is a subclass of the RESTAdapter designed to integrate - with a JSON API that uses an underscored naming convention instead of camelCasing. - It has been designed to work out of the box with the - [active\_model\_serializers](http://github.com/rails-api/active_model_serializers) - Ruby gem. This Adapter expects specific settings using ActiveModel::Serializers, - `embed :ids, embed_in_root: true` which sideloads the records. - - This adapter extends the DS.RESTAdapter by making consistent use of the camelization, - decamelization and pluralization methods to normalize the serialized JSON into a - format that is compatible with a conventional Rails backend and Ember Data. - - ## JSON Structure - - The ActiveModelAdapter expects the JSON returned from your server to follow - the REST adapter conventions substituting underscored keys for camelcased ones. - - Unlike the DS.RESTAdapter, async relationship keys must be the singular form - of the relationship name, followed by "_id" for DS.belongsTo relationships, - or "_ids" for DS.hasMany relationships. - - ### Conventional Names - - Attribute names in your JSON payload should be the underscored versions of - the attributes in your Ember.js models. - - For example, if you have a `Person` model: - - ```js - App.FamousPerson = DS.Model.extend({ - firstName: DS.attr('string'), - lastName: DS.attr('string'), - occupation: DS.attr('string') - }); - ``` - - The JSON returned should look like this: - - ```js - { - "famous_person": { - "id": 1, - "first_name": "Barack", - "last_name": "Obama", - "occupation": "President" - } - } - ``` - - Let's imagine that `Occupation` is just another model: - - ```js - App.Person = DS.Model.extend({ - firstName: DS.attr('string'), - lastName: DS.attr('string'), - occupation: DS.belongsTo('occupation') - }); - - App.Occupation = DS.Model.extend({ - name: DS.attr('string'), - salary: DS.attr('number'), - people: DS.hasMany('person') - }); - ``` - - The JSON needed to avoid extra server calls, should look like this: - - ```js - { - "people": [{ - "id": 1, - "first_name": "Barack", - "last_name": "Obama", - "occupation_id": 1 - }], - - "occupations": [{ - "id": 1, - "name": "President", - "salary": 100000, - "person_ids": [1] - }] - } - ``` - - @class ActiveModelAdapter - @constructor - @namespace DS - @extends DS.RESTAdapter -**/ - -var ActiveModelAdapter = RESTAdapter.extend({ - defaultSerializer: '-active-model', - /** - The ActiveModelAdapter overrides the `pathForType` method to build - underscored URLs by decamelizing and pluralizing the object type name. - - ```js - this.pathForType("famousPerson"); - //=> "famous_people" - ``` - - @method pathForType - @param {String} modelName - @return String - */ - pathForType: function(modelName) { - var decamelized = decamelize(modelName); - var underscored = underscore(decamelized); - return pluralize(underscored); - }, - - /** - The ActiveModelAdapter overrides the `handleResponse` method - to format errors passed to a DS.InvalidError for all - 422 Unprocessable Entity responses. - - A 422 HTTP response from the server generally implies that the request - was well formed but the API was unable to process it because the - content was not semantically correct or meaningful per the API. - - For more information on 422 HTTP Error code see 11.2 WebDAV RFC 4918 - https://tools.ietf.org/html/rfc4918#section-11.2 - - @method ajaxError - @param {Object} jqXHR - @return error - */ - handleResponse: function(status, headers, payload) { - if (this.isInvalid(status, headers, payload)) { - let errors = errorsHashToArray(payload.errors); - - return new InvalidError(errors); - } else { - return this._super(...arguments); - } - } -}); - -export default ActiveModelAdapter; diff --git a/packages/activemodel-adapter/lib/system/active-model-serializer.js b/packages/activemodel-adapter/lib/system/active-model-serializer.js deleted file mode 100644 index f14eb031fae..00000000000 --- a/packages/activemodel-adapter/lib/system/active-model-serializer.js +++ /dev/null @@ -1,301 +0,0 @@ -import { singularize } from "ember-inflector"; -import RESTSerializer from "ember-data/serializers/rest-serializer"; -import normalizeModelName from "ember-data/system/normalize-model-name"; -/** - @module ember-data -*/ - -var camelize = Ember.String.camelize; -var classify = Ember.String.classify; -var decamelize = Ember.String.decamelize; -var underscore = Ember.String.underscore; - -/** - The ActiveModelSerializer is a subclass of the RESTSerializer designed to integrate - with a JSON API that uses an underscored naming convention instead of camelCasing. - It has been designed to work out of the box with the - [active\_model\_serializers](http://github.com/rails-api/active_model_serializers) - Ruby gem. This Serializer expects specific settings using ActiveModel::Serializers, - `embed :ids, embed_in_root: true` which sideloads the records. - - This serializer extends the DS.RESTSerializer by making consistent - use of the camelization, decamelization and pluralization methods to - normalize the serialized JSON into a format that is compatible with - a conventional Rails backend and Ember Data. - - ## JSON Structure - - The ActiveModelSerializer expects the JSON returned from your server - to follow the REST adapter conventions substituting underscored keys - for camelcased ones. - - ### Conventional Names - - Attribute names in your JSON payload should be the underscored versions of - the attributes in your Ember.js models. - - For example, if you have a `Person` model: - - ```js - App.FamousPerson = DS.Model.extend({ - firstName: DS.attr('string'), - lastName: DS.attr('string'), - occupation: DS.attr('string') - }); - ``` - - The JSON returned should look like this: - - ```js - { - "famous_person": { - "id": 1, - "first_name": "Barack", - "last_name": "Obama", - "occupation": "President" - } - } - ``` - - Let's imagine that `Occupation` is just another model: - - ```js - App.Person = DS.Model.extend({ - firstName: DS.attr('string'), - lastName: DS.attr('string'), - occupation: DS.belongsTo('occupation') - }); - - App.Occupation = DS.Model.extend({ - name: DS.attr('string'), - salary: DS.attr('number'), - people: DS.hasMany('person') - }); - ``` - - The JSON needed to avoid extra server calls, should look like this: - - ```js - { - "people": [{ - "id": 1, - "first_name": "Barack", - "last_name": "Obama", - "occupation_id": 1 - }], - - "occupations": [{ - "id": 1, - "name": "President", - "salary": 100000, - "person_ids": [1] - }] - } - ``` - - @class ActiveModelSerializer - @namespace DS - @extends DS.RESTSerializer -*/ -var ActiveModelSerializer = RESTSerializer.extend({ - // SERIALIZE - - /** - Converts camelCased attributes to underscored when serializing. - - @method keyForAttribute - @param {String} attribute - @return String - */ - keyForAttribute: function(attr) { - return decamelize(attr); - }, - - /** - Underscores relationship names and appends "_id" or "_ids" when serializing - relationship keys. - - @method keyForRelationship - @param {String} relationshipModelName - @param {String} kind - @return String - */ - keyForRelationship: function(relationshipModelName, kind) { - var key = decamelize(relationshipModelName); - if (kind === "belongsTo") { - return key + "_id"; - } else if (kind === "hasMany") { - return singularize(key) + "_ids"; - } else { - return key; - } - }, - - /** - `keyForLink` can be used to define a custom key when deserializing link - properties. The `ActiveModelSerializer` camelizes link keys by default. - - @method keyForLink - @param {String} key - @param {String} kind `belongsTo` or `hasMany` - @return {String} normalized key - */ - keyForLink: function(key, relationshipKind) { - return camelize(key); - }, - - /* - Does not serialize hasMany relationships by default. - */ - serializeHasMany: Ember.K, - - /** - Underscores the JSON root keys when serializing. - - @method payloadKeyFromModelName - @param {String} modelName - @return {String} - */ - payloadKeyFromModelName: function(modelName) { - return underscore(decamelize(modelName)); - }, - - /** - Serializes a polymorphic type as a fully capitalized model name. - - @method serializePolymorphicType - @param {DS.Snapshot} snapshot - @param {Object} json - @param {Object} relationship - */ - serializePolymorphicType: function(snapshot, json, relationship) { - var key = relationship.key; - var belongsTo = snapshot.belongsTo(key); - var jsonKey = underscore(key + "_type"); - - if (Ember.isNone(belongsTo)) { - json[jsonKey] = null; - } else { - json[jsonKey] = classify(belongsTo.modelName).replace('/', '::'); - } - }, - - // EXTRACT - - /** - Add extra step to `DS.RESTSerializer.normalize` so links are normalized. - - If your payload looks like: - - ```js - { - "post": { - "id": 1, - "title": "Rails is omakase", - "links": { "flagged_comments": "api/comments/flagged" } - } - } - ``` - - The normalized version would look like this - - ```js - { - "post": { - "id": 1, - "title": "Rails is omakase", - "links": { "flaggedComments": "api/comments/flagged" } - } - } - ``` - - @method normalize - @param {subclass of DS.Model} typeClass - @param {Object} hash - @param {String} prop - @return Object - */ - normalize: function(typeClass, hash, prop) { - this.normalizeLinks(hash); - return this._super(typeClass, hash, prop); - }, - - /** - Convert `snake_cased` links to `camelCase` - - @method normalizeLinks - @param {Object} data - */ - - normalizeLinks: function(data) { - if (data.links) { - var links = data.links; - - for (var link in links) { - var camelizedLink = camelize(link); - - if (camelizedLink !== link) { - links[camelizedLink] = links[link]; - delete links[link]; - } - } - } - }, - - /** - Normalize the polymorphic type from the JSON. - - Normalize: - ```js - { - id: "1" - minion: { type: "evil_minion", id: "12"} - } - ``` - - To: - ```js - { - id: "1" - minion: { type: "evilMinion", id: "12"} - } - ``` - - @param {Subclass of DS.Model} typeClass - @method normalizeRelationships - @private - */ - normalizeRelationships: function(typeClass, hash) { - - if (this.keyForRelationship) { - typeClass.eachRelationship(function(key, relationship) { - var payloadKey, payload; - if (relationship.options.polymorphic) { - payloadKey = this.keyForAttribute(key, "deserialize"); - payload = hash[payloadKey]; - if (payload && payload.type) { - payload.type = this.modelNameFromPayloadKey(payload.type); - } else if (payload && relationship.kind === "hasMany") { - payload.forEach((single) => single.type = this.modelNameFromPayloadKey(single.type)); - } - } else { - payloadKey = this.keyForRelationship(key, relationship.kind, "deserialize"); - if (!hash.hasOwnProperty(payloadKey)) { return; } - payload = hash[payloadKey]; - } - - hash[key] = payload; - - if (key !== payloadKey) { - delete hash[payloadKey]; - } - }, this); - } - }, - modelNameFromPayloadKey: function(key) { - var convertedFromRubyModule = singularize(key.replace('::', '/')); - return normalizeModelName(convertedFromRubyModule); - } -}); - -export default ActiveModelSerializer; diff --git a/packages/activemodel-adapter/tests/integration/active-model-adapter-serializer-test.js b/packages/activemodel-adapter/tests/integration/active-model-adapter-serializer-test.js deleted file mode 100644 index 58a6f7c475d..00000000000 --- a/packages/activemodel-adapter/tests/integration/active-model-adapter-serializer-test.js +++ /dev/null @@ -1,55 +0,0 @@ -var env, store, adapter, User; -var originalAjax; - -module("integration/active_model_adapter_serializer - AMS Adapter and Serializer", { - setup: function() { - originalAjax = Ember.$.ajax; - - User = DS.Model.extend({ - firstName: DS.attr() - }); - - env = setupStore({ - user: User, - adapter: DS.ActiveModelAdapter - }); - - store = env.store; - adapter = env.adapter; - - env.registry.register('serializer:application', DS.ActiveModelSerializer); - }, - - teardown: function() { - Ember.$.ajax = originalAjax; - } -}); - -test('errors are camelCased and are expected under the `errors` property of the payload', function() { - var jqXHR = { - status: 422, - getAllResponseHeaders: function() { return ''; }, - responseText: JSON.stringify({ - errors: { - first_name: ["firstName error"] - } - }) - }; - - Ember.$.ajax = function(hash) { - hash.error(jqXHR); - }; - - var user; - Ember.run(function() { - user = store.push('user', { id: 1 }); - }); - - Ember.run(function() { - user.save().then(null, function() { - var errors = user.get('errors'); - ok(errors.has('firstName'), "there are errors for the firstName attribute"); - deepEqual(errors.errorsFor('firstName').getEach('message'), ['firstName error']); - }); - }); -}); diff --git a/packages/activemodel-adapter/tests/integration/active-model-adapter-test.js b/packages/activemodel-adapter/tests/integration/active-model-adapter-test.js deleted file mode 100644 index f6cc7cfc7b1..00000000000 --- a/packages/activemodel-adapter/tests/integration/active-model-adapter-test.js +++ /dev/null @@ -1,47 +0,0 @@ -var env, store, adapter, SuperUser; -var passedUrl, passedVerb, passedHash; -module("integration/active_model_adapter - AMS Adapter", { - setup: function() { - SuperUser = DS.Model.extend(); - - env = setupStore({ - superUser: SuperUser, - adapter: DS.ActiveModelAdapter - }); - - store = env.store; - adapter = env.adapter; - - passedUrl = passedVerb = passedHash = null; - } -}); - -test('buildURL - decamelizes names', function() { - equal(adapter.buildURL('superUser', 1), "/super_users/1"); -}); - -test('handleResponse - returns invalid error if 422 response', function() { - - var jqXHR = { - status: 422, - responseText: JSON.stringify({ errors: { name: "can't be blank" } }) - }; - - var json = adapter.parseErrorResponse(jqXHR.responseText); - - var error = adapter.handleResponse(jqXHR.status, {}, json).errors[0]; - - equal(error.details, "can't be blank"); - equal(error.source.pointer, "data/attributes/name"); -}); - -test('handleResponse - returns ajax response if not 422 response', function() { - var jqXHR = { - status: 500, - responseText: "Something went wrong" - }; - - var json = adapter.parseErrorResponse(jqXHR.responseText); - - ok(adapter.handleResponse(jqXHR.status, {}, json) instanceof DS.AdapterError, 'must be a DS.AdapterError'); -}); diff --git a/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-model-name-test.js b/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-model-name-test.js deleted file mode 100644 index 0469e1d39ce..00000000000 --- a/packages/activemodel-adapter/tests/integration/active-model-serializer-namespaced-model-name-test.js +++ /dev/null @@ -1,149 +0,0 @@ -var SuperVillain, EvilMinion, YellowMinion, DoomsdayDevice, MediocreVillain, env; -var run = Ember.run; - -module("integration/active_model - AMS-namespaced-model-names", { - setup: function() { - SuperVillain = DS.Model.extend({ - firstName: DS.attr('string'), - lastName: DS.attr('string'), - evilMinions: DS.hasMany('evil-minion') - }); - - EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('super-villain'), - name: DS.attr('string') - }); - YellowMinion = EvilMinion.extend(); - DoomsdayDevice = DS.Model.extend({ - name: DS.attr('string'), - evilMinion: DS.belongsTo('evil-minion', { polymorphic: true }) - }); - MediocreVillain = DS.Model.extend({ - name: DS.attr('string'), - evilMinions: DS.hasMany('evil-minion', { polymorphic: true }) - }); - env = setupStore({ - superVillain: SuperVillain, - evilMinion: EvilMinion, - 'evilMinions/yellowMinion': YellowMinion, - doomsdayDevice: DoomsdayDevice, - mediocreVillain: MediocreVillain, - yellowMinion: YellowMinion - }); - 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); - env.amsSerializer = env.container.lookup("serializer:-active-model"); - env.amsAdapter = env.container.lookup("adapter:-active-model"); - }, - - teardown: function() { - run(env.store, 'destroy'); - } -}); - -test("serialize polymorphic", function() { - var tom, ray; - run(function() { - 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()); - - deepEqual(json, { - name: "DeathRay", - evil_minion_type: "EvilMinions::YellowMinion", - evil_minion_id: "124" - }); -}); - -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('yellow-minion', { name: "Alex", id: "124" }); - ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: "DeathRay" }); - }); - - var json = env.amsSerializer.serialize(ray._createSnapshot()); - - deepEqual(json["evil_minion_type"], "EvilMinions::YellowMinion"); -}); - -test("extractPolymorphic hasMany", function() { - var json_hash = { - mediocre_villain: { id: 1, name: "Dr Horrible", evil_minion_ids: [{ type: "EvilMinions::YellowMinion", id: 12 }] }, - "evil-minions/yellow-minion": [{ id: 12, name: "Alex", doomsday_device_ids: [1] }] - }; - var json; - - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json_hash, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "mediocre-villain", - "attributes": { - "name": "Dr Horrible" - }, - "relationships": { - "evilMinions": { - "data": [ - { "id": "12", "type": "evil-minions/yellow-minion" } - ] - } - } - }, - "included": [{ - "id": "12", - "type": "evil-minions/yellow-minion", - "attributes": { - "name": "Alex" - }, - "relationships": {} - }] - }); -}); - -test("extractPolymorphic belongsTo", function() { - var json_hash = { - doomsday_device: { id: 1, name: "DeathRay", evil_minion_id: { type: "EvilMinions::YellowMinion", id: 12 } }, - "evil-minions/yellow-minion": [{ id: 12, name: "Alex", doomsday_device_ids: [1] }] - }; - var json; - - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json_hash, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "doomsday-device", - "attributes": { - "name": "DeathRay" - }, - "relationships": { - "evilMinion": { - "data": { "id": "12", "type": "evil-minions/yellow-minion" } - } - } - }, - "included": [{ - "id": "12", - "type": "evil-minions/yellow-minion", - "attributes": { - "name": "Alex" - }, - "relationships": {} - }] - }); -}); diff --git a/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js b/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js deleted file mode 100644 index dbe261d1bc0..00000000000 --- a/packages/activemodel-adapter/tests/integration/active-model-serializer-test.js +++ /dev/null @@ -1,465 +0,0 @@ -var get = Ember.get; -var HomePlanet, league, SuperVillain, EvilMinion, YellowMinion, DoomsdayDevice, MediocreVillain, env; -var run = Ember.run; - -module("integration/active_model - ActiveModelSerializer", { - setup: function() { - SuperVillain = DS.Model.extend({ - firstName: DS.attr('string'), - lastName: DS.attr('string'), - homePlanet: DS.belongsTo('home-planet'), - evilMinions: DS.hasMany('evil-minion') - }); - HomePlanet = DS.Model.extend({ - name: DS.attr('string'), - superVillains: DS.hasMany('super-villain', { async: true }) - }); - EvilMinion = DS.Model.extend({ - superVillain: DS.belongsTo('super-villain'), - name: DS.attr('string') - }); - YellowMinion = EvilMinion.extend(); - DoomsdayDevice = DS.Model.extend({ - name: DS.attr('string'), - evilMinion: DS.belongsTo('evil-minion', { polymorphic: true }) - }); - MediocreVillain = DS.Model.extend({ - name: DS.attr('string'), - evilMinions: DS.hasMany('evil-minion', { polymorphic: true }) - }); - env = setupStore({ - superVillain: SuperVillain, - homePlanet: HomePlanet, - evilMinion: EvilMinion, - yellowMinion: YellowMinion, - doomsdayDevice: DoomsdayDevice, - mediocreVillain: 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); - env.amsSerializer = env.container.lookup("serializer:-active-model"); - env.amsAdapter = env.container.lookup("adapter:-active-model"); - }, - - teardown: function() { - run(env.store, 'destroy'); - } -}); - -test("serialize", function() { - var tom; - run(function() { - 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()); - - deepEqual(json, { - first_name: "Tom", - last_name: "Dale", - home_planet_id: get(league, "id") - }); -}); - -test("serializeIntoHash", function() { - run(function() { - league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); - }); - var json = {}; - - env.amsSerializer.serializeIntoHash(json, HomePlanet, league._createSnapshot()); - - deepEqual(json, { - home_planet: { - name: "Umber" - } - }); -}); - -test("serializeIntoHash with decamelized types", function() { - HomePlanet.modelName = 'home-planet'; - run(function() { - league = env.store.createRecord('home-planet', { name: "Umber", id: "123" }); - }); - var json = {}; - - env.amsSerializer.serializeIntoHash(json, HomePlanet, league._createSnapshot()); - - deepEqual(json, { - home_planet: { - name: "Umber" - } - }); -}); - - -test("normalize", function() { - SuperVillain.reopen({ - yellowMinion: DS.belongsTo('yellowMinion') - }); - - var superVillain_hash = { - id: "1", - first_name: "Tom", - last_name: "Dale", - home_planet_id: "123", - evil_minion_ids: [1, 2] - }; - - var json = env.amsSerializer.normalize(SuperVillain, superVillain_hash, "superVillain"); - - deepEqual(json, { - "data": { - "id": "1", - "type": "super-villain", - "attributes": { - "firstName": "Tom", - "lastName": "Dale" - }, - "relationships": { - "evilMinions": { - "data": [ - { "id": "1", "type": "evil-minion" }, - { "id": "2", "type": "evil-minion" } - ] - }, - "homePlanet": { - "data": { "id": "123", "type": "home-planet" } - } - } - } - }); -}); - -test("normalize links", function() { - var home_planet = { - id: "1", - name: "Umber", - links: { super_villains: "/api/super_villians/1" } - }; - - var json = env.amsSerializer.normalize(HomePlanet, home_planet, "homePlanet"); - - equal(json.data.relationships.superVillains.links.related, "/api/super_villians/1", "normalize links"); -}); - -test("normalizeResponse", function() { - env.registry.register('adapter:superVillain', DS.ActiveModelAdapter); - - var json_hash = { - home_planet: { id: "1", name: "Umber", super_villain_ids: [1] }, - super_villains: [{ - id: "1", - first_name: "Tom", - last_name: "Dale", - home_planet_id: "1" - }] - }; - - var json; - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, HomePlanet, json_hash, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "home-planet", - "attributes": { - "name": "Umber" - }, - "relationships": { - "superVillains": { - "data": [ - { "id": "1", "type": "super-villain" } - ] - } - } - }, - "included": [{ - "id": "1", - "type": "super-villain", - "attributes": { - "firstName": "Tom", - "lastName": "Dale" - }, - "relationships": { - "homePlanet": { - "data": { "id": "1", "type": "home-planet" } - } - } - }] - }); -}); - -test("normalizeResponse", function() { - env.registry.register('adapter:superVillain', DS.ActiveModelAdapter); - var array; - - var json_hash = { - home_planets: [{ id: "1", name: "Umber", super_villain_ids: [1] }], - super_villains: [{ id: "1", first_name: "Tom", last_name: "Dale", home_planet_id: "1" }] - }; - - run(function() { - array = env.amsSerializer.normalizeResponse(env.store, HomePlanet, json_hash, null, 'findAll'); - }); - - deepEqual(array, { - "data": [{ - "id": "1", - "type": "home-planet", - "attributes": { - "name": "Umber" - }, - "relationships": { - "superVillains": { - "data": [ - { "id": "1", "type": "super-villain" } - ] - } - } - }], - "included": [{ - "id": "1", - "type": "super-villain", - "attributes": { - "firstName": "Tom", - "lastName": "Dale" - }, - "relationships": { - "homePlanet": { - "data": { "id": "1", "type": "home-planet" } - } - } - }] - }); -}); - -test("serialize polymorphic", function() { - var tom, ray; - run(function() { - 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()); - - deepEqual(json, { - name: "DeathRay", - evil_minion_type: "YellowMinion", - evil_minion_id: "124" - }); -}); - -test("serialize polymorphic when type key is not camelized", function() { - YellowMinion.modelName = 'yellow-minion'; - var tom, ray; - run(function() { - 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()); - - deepEqual(json["evil_minion_type"], "YellowMinion"); -}); - -test("serialize polymorphic when associated object is null", function() { - var ray, json; - run(function() { - ray = env.store.createRecord('doomsday-device', { name: "DeathRay" }); - json = env.amsSerializer.serialize(ray._createSnapshot()); - }); - - deepEqual(json["evil_minion_type"], null); -}); - -test("extractPolymorphic hasMany", function() { - env.registry.register('adapter:yellowMinion', DS.ActiveModelAdapter); - MediocreVillain.toString = function() { return "MediocreVillain"; }; - YellowMinion.toString = function() { return "YellowMinion"; }; - - var json_hash = { - mediocre_villain: { id: 1, name: "Dr Horrible", evil_minion_ids: [{ type: "yellow_minion", id: 12 }] }, - yellow_minions: [{ id: 12, name: "Alex" }] - }; - var json; - - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json_hash, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "mediocre-villain", - "attributes": { - "name": "Dr Horrible" - }, - "relationships": { - "evilMinions": { - "data": [ - { "id": "12", "type": "yellow-minion" } - ] - } - } - }, - "included": [{ - "id": "12", - "type": "yellow-minion", - "attributes": { - "name": "Alex" - }, - "relationships": {} - }] - }); -}); - -test("extractPolymorphic belongsTo", function() { - env.registry.register('adapter:yellowMinion', DS.ActiveModelAdapter); - EvilMinion.toString = function() { return "EvilMinion"; }; - YellowMinion.toString = function() { return "YellowMinion"; }; - - var json_hash = { - doomsday_device: { id: 1, name: "DeathRay", evil_minion_id: { type: "yellow_minion", id: 12 } }, - yellow_minions: [{ id: 12, name: "Alex", doomsday_device_ids: [1] }] - }; - var json; - - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json_hash, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "doomsday-device", - "attributes": { - "name": "DeathRay" - }, - "relationships": { - "evilMinion": { - "data": { "id": "12", "type": "yellow-minion" } - } - } - }, - "included": [{ - "id": "12", - "type": "yellow-minion", - "attributes": { - "name": "Alex" - }, - "relationships": {} - }] - }); -}); - -test("extractPolymorphic when the related data is not specified", function() { - var json = { - doomsday_device: { id: 1, name: "DeathRay" }, - evil_minions: [{ id: 12, name: "Alex", doomsday_device_ids: [1] }] - }; - - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, DoomsdayDevice, json, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "doomsday-device", - "attributes": { - "name": "DeathRay" - }, - "relationships": {} - }, - "included": [{ - "id": "12", - "type": "evil-minion", - "attributes": { - "name": "Alex" - }, - "relationships": {} - }] - }); -}); - -test("extractPolymorphic hasMany when the related data is not specified", function() { - var json = { - mediocre_villain: { id: 1, name: "Dr Horrible" } - }; - - run(function() { - json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "mediocre-villain", - "attributes": { - "name": "Dr Horrible" - }, - "relationships": {} - }, - "included": [] - }); -}); - -test("extractPolymorphic does not break hasMany relationships", function() { - var json = { - mediocre_villain: { id: 1, name: "Dr. Evil", evil_minion_ids: [] } - }; - - run(function () { - json = env.amsSerializer.normalizeResponse(env.store, MediocreVillain, json, '1', 'findRecord'); - }); - - deepEqual(json, { - "data": { - "id": "1", - "type": "mediocre-villain", - "attributes": { - "name": "Dr. Evil" - }, - "relationships": { - "evilMinions": { - "data": [] - } - } - }, - "included": [] - }); -}); - -test("extractErrors camelizes keys", function() { - var error = { - errors: [ - { - source: { - pointer: 'data/attributes/first_name' - }, - details: "firstName not evil enough" - } - ] - }; - - var payload; - - run(function() { - payload = env.amsSerializer.extractErrors(env.store, SuperVillain, error); - }); - - deepEqual(payload, { - firstName: ["firstName not evil enough"] - }); -}); diff --git a/packages/activemodel-adapter/tests/unit/adapter/path-for-type-test.js b/packages/activemodel-adapter/tests/unit/adapter/path-for-type-test.js deleted file mode 100644 index 6e533376cae..00000000000 --- a/packages/activemodel-adapter/tests/unit/adapter/path-for-type-test.js +++ /dev/null @@ -1,22 +0,0 @@ -var env, adapter; -module("unit/adapter/path_for_type - DS.ActiveModelAdapter#pathForType", { - setup: function() { - env = setupStore({ - adapter: DS.ActiveModelAdapter - }); - - adapter = env.adapter; - } -}); - -test('pathForType - works with camelized types', function() { - equal(adapter.pathForType('superUser'), "super_users"); -}); - -test('pathForType - works with dasherized types', function() { - equal(adapter.pathForType('super-user'), "super_users"); -}); - -test('pathForType - works with underscored types', function() { - equal(adapter.pathForType('super_user'), "super_users"); -}); diff --git a/packages/ember-data/lib/ember-initializer.js b/packages/ember-data/lib/ember-initializer.js index 5520b118aa3..0f1a98b95b7 100644 --- a/packages/ember-data/lib/ember-initializer.js +++ b/packages/ember-data/lib/ember-initializer.js @@ -67,12 +67,6 @@ Ember.onLoad('Ember.Application', function(Application) { initialize: K }); - Application.initializer({ - name: "activeModelAdapter", - before: "store", - initialize: K - }); - Application.initializer({ name: "transforms", before: "store", diff --git a/packages/ember-data/lib/main.js b/packages/ember-data/lib/main.js index d339704cd83..2654bb93d10 100644 --- a/packages/ember-data/lib/main.js +++ b/packages/ember-data/lib/main.js @@ -69,10 +69,6 @@ import { } from "ember-data/serializers"; import "ember-inflector"; import EmbeddedRecordsMixin from "ember-data/serializers/embedded-records-mixin"; -import { - ActiveModelAdapter, - ActiveModelSerializer -} from "activemodel-adapter"; import { Transform, @@ -139,40 +135,6 @@ DS.StringTransform = StringTransform; DS.NumberTransform = NumberTransform; DS.BooleanTransform = BooleanTransform; -var _ActiveModelAdapter = ActiveModelAdapter; -var _ActiveModelSerializer = ActiveModelSerializer; - -if (Ember.platform.hasPropertyAccessors) { - Ember.defineProperty(DS, 'ActiveModelAdapter', { - get: function() { - if (_ActiveModelSerializer === ActiveModelAdapter) { - Ember.deprecate('The ActiveModelAdapter has been moved into a plugin. It will not be bundled with Ember Data in 2.0', false, { - url: 'https://github.com/ember-data/active-model-adapter' - }); - } - return _ActiveModelAdapter; - }, - set: function(ActiveModelAdapter) { - _ActiveModelAdapter = ActiveModelAdapter; - } - }); - Ember.defineProperty(DS, 'ActiveModelSerializer', { - get: function() { - if (_ActiveModelSerializer === ActiveModelSerializer) { - Ember.deprecate('The ActiveModelSerializer has been moved into a plugin. It will not be bundled with Ember Data in 2.0', false, { - url: 'https://github.com/ember-data/active-model-adapter' - }); - } - return _ActiveModelSerializer; - }, - set: function(ActiveModelSerializer) { - _ActiveModelSerializer = ActiveModelSerializer; - } - }); -} else { - DS.ActiveModelAdapter = ActiveModelAdapter; - DS.ActiveModelSerializer = ActiveModelSerializer; -} DS.EmbeddedRecordsMixin = EmbeddedRecordsMixin; DS.belongsTo = belongsTo; diff --git a/packages/ember-data/lib/setup-container.js b/packages/ember-data/lib/setup-container.js index 359d1bd6e7d..6ea2734146b 100644 --- a/packages/ember-data/lib/setup-container.js +++ b/packages/ember-data/lib/setup-container.js @@ -2,7 +2,6 @@ import initializeStore from 'ember-data/initializers/store'; import initializeTransforms from 'ember-data/initializers/transforms'; import initializeStoreInjections from 'ember-data/initializers/store-injections'; import initializeDataAdapter from 'ember-data/initializers/data-adapter'; -import setupActiveModelContainer from 'activemodel-adapter/setup-container'; import initializeStoreService from 'ember-data/instance-initializers/initialize-store-service'; export default function setupContainer(registry, application) { @@ -19,6 +18,5 @@ export function initializeInjects(registry, application) { initializeDataAdapter(registry, application); initializeTransforms(registry, application); initializeStoreInjections(registry, application); - setupActiveModelContainer(registry, application); initializeStore(registry, application); } diff --git a/packages/ember-data/tests/integration/application-test.js b/packages/ember-data/tests/integration/application-test.js index 3c2bfd7f974..53e4065d14a 100644 --- a/packages/ember-data/tests/integration/application-test.js +++ b/packages/ember-data/tests/integration/application-test.js @@ -210,18 +210,3 @@ test("transforms initializer is run (DEPRECATED)", function() { ok(ran, 'transforms initializer was found'); }); - -test("activeModelAdapter initializer is run (DEPRECATED)", function() { - var ran = false; - App.initializer({ - name: "after-store", - after: 'activeModelAdapter', - initialize: function() { ran = true; } - }); - - run(function() { - app = App.create(); - }); - - ok(ran, 'activeModelAdapter initializer was found'); -}); diff --git a/packages/ember-data/tests/integration/multiple_stores_test.js b/packages/ember-data/tests/integration/multiple_stores_test.js index 259657e41d9..15b383fd854 100644 --- a/packages/ember-data/tests/integration/multiple_stores_test.js +++ b/packages/ember-data/tests/integration/multiple_stores_test.js @@ -25,9 +25,8 @@ module("integration/multiple_stores - Multiple Stores Tests", { evilMinion: EvilMinion }); - env.registry.register('serializer:application', DS.ActiveModelSerializer); - env.registry.register('serializer:-active-model', DS.ActiveModelSerializer); - env.registry.register('adapter:-active-model', DS.ActiveModelAdapter); + env.registry.register('adapter:application', DS.RESTAdapter); + env.registry.register('serializer:application', DS.RESTSerializer); env.registry.register('store:store-a', DS.Store); env.registry.register('store:store-b', DS.Store); @@ -42,36 +41,32 @@ module("integration/multiple_stores - Multiple Stores Tests", { }); test("should be able to push into multiple stores", function() { - env.registry.register('adapter:home-planet', DS.ActiveModelAdapter); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer); - var home_planet_main = { id: '1', name: 'Earth' }; var home_planet_a = { id: '1', name: 'Mars' }; var home_planet_b = { id: '1', name: 'Saturn' }; - run(env.store, 'push', 'homePlanet', home_planet_main); - run(env.store_a, 'push', 'homePlanet', home_planet_a); - run(env.store_b, 'push', 'homePlanet', home_planet_b); + run(function() { + env.store.push(env.store.normalize('home-planet', home_planet_main)); + env.store_a.push(env.store_a.normalize('home-planet', home_planet_a)); + env.store_b.push(env.store_b.normalize('home-planet', home_planet_b)); + }); - run(env.store, 'find', 'homePlanet', 1).then(async(function(homePlanet) { + run(env.store, 'find', 'home-planet', 1).then(async(function(homePlanet) { equal(homePlanet.get('name'), "Earth"); })); - run(env.store_a, 'find', 'homePlanet', 1).then(async(function(homePlanet) { + run(env.store_a, 'find', 'home-planet', 1).then(async(function(homePlanet) { equal(homePlanet.get('name'), "Mars"); })); - run(env.store_b, 'find', 'homePlanet', 1).then(async(function(homePlanet) { + run(env.store_b, 'find', 'home-planet', 1).then(async(function(homePlanet) { equal(homePlanet.get('name'), "Saturn"); })); }); test("embedded records should be created in multiple stores", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('adapter:home-planet', DS.ActiveModelAdapter); - - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } @@ -82,35 +77,35 @@ test("embedded records should be created in multiple stores", function() { var serializer_b = env.store_b.serializerFor('home-planet'); var json_hash_main = { - home_planet: { + homePlanet: { id: "1", name: "Earth", villains: [{ id: "1", - first_name: "Tom", - last_name: "Dale" + firstName: "Tom", + lastName: "Dale" }] } }; var json_hash_a = { - home_planet: { + homePlanet: { id: "1", name: "Mars", villains: [{ id: "1", - first_name: "James", - last_name: "Murphy" + firstName: "James", + lastName: "Murphy" }] } }; var json_hash_b = { - home_planet: { + homePlanet: { id: "1", name: "Saturn", villains: [{ id: "1", - first_name: "Jade", - last_name: "John" + firstName: "Jade", + lastName: "John" }] } }; 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 8407092907e..85644fa4b3c 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 @@ -60,11 +60,12 @@ module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { 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)); - env.registry.register('adapter:-active-model', DS.ActiveModelAdapter); - env.amsSerializer = env.container.lookup("serializer:-active-model"); - env.amsAdapter = env.container.lookup("adapter:-active-model"); + + env.registry.register('adapter:application', DS.RESTAdapter); + env.registry.register('serializer:application', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin)); + + //env.amsSerializer = env.container.lookup("serializer:-active-model"); + //env.amsAdapter = env.container.lookup("adapter:-active-model"); }, teardown: function() { @@ -73,7 +74,7 @@ module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { }); test("normalizeResponse with embedded objects", function() { - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } @@ -86,8 +87,8 @@ test("normalizeResponse with embedded objects", function() { name: "Umber", villains: [{ id: "2", - first_name: "Tom", - last_name: "Dale" + firstName: "Tom", + lastName: "Dale" }] } }; @@ -127,18 +128,16 @@ test("normalizeResponse with embedded objects", function() { }); test("normalizeResponse with embedded objects inside embedded objects", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { evilMinions: { embedded: 'always' } } })); - env.registry.register('serializer:evil-minion', DS.ActiveModelSerializer); var serializer = env.container.lookup("serializer:home-planet"); var json_hash = { @@ -147,9 +146,9 @@ test("normalizeResponse with embedded objects inside embedded objects", function name: "Umber", villains: [{ id: "2", - first_name: "Tom", - last_name: "Dale", - evil_minions: [{ + firstName: "Tom", + lastName: "Dale", + evilMinions: [{ id: "3", name: "Alex" }] @@ -203,8 +202,7 @@ test("normalizeResponse with embedded objects inside embedded objects", function }); test("normalizeResponse with embedded objects of same type", function() { - env.registry.register('adapter:comment', DS.ActiveModelAdapter); - env.registry.register('serializer:comment', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:comment', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { children: { embedded: 'always' } } @@ -220,12 +218,11 @@ test("normalizeResponse with embedded objects of same type", function() { id: "2", body: "World", root: false - }, - { - id: "3", - body: "Foo", - root: false - }] + }, { + id: "3", + body: "Foo", + root: false + }] } }; var json; @@ -271,8 +268,7 @@ test("normalizeResponse with embedded objects of same type", function() { }); test("normalizeResponse with embedded objects inside embedded objects of same type", function() { - env.registry.register('adapter:comment', DS.ActiveModelAdapter); - env.registry.register('serializer:comment', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:comment', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { children: { embedded: 'always' } } @@ -293,12 +289,11 @@ test("normalizeResponse with embedded objects inside embedded objects of same ty body: "Another", root: false }] - }, - { - id: "3", - body: "Foo", - root: false - }] + }, { + id: "3", + body: "Foo", + root: false + }] } }; var json; @@ -362,14 +357,12 @@ test("normalizeResponse with embedded objects of same type, but from separate at reformedVillains: DS.hasMany('superVillain', { inverse: null, async: false }) }); - env.registry.register('adapter:home-planet', DS.ActiveModelAdapter); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' }, reformedVillains: { embedded: 'always' } } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer); var serializer = env.container.lookup("serializer:home-planet"); var json_hash = { @@ -378,17 +371,17 @@ test("normalizeResponse with embedded objects of same type, but from separate at name: "Earth", villains: [{ id: "1", - first_name: "Tom" + firstName: "Tom" }, { id: "3", - first_name: "Yehuda" + firstName: "Yehuda" }], - reformed_villains: [{ + reformedVillains: [{ id: "2", - first_name: "Alex" + firstName: "Alex" },{ id: "4", - first_name: "Erik" + firstName: "Erik" }] } }; @@ -452,13 +445,11 @@ test("normalizeResponse with embedded objects of same type, but from separate at }); test("normalizeResponse with embedded objects", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer); var serializer = env.container.lookup("serializer:home-planet"); @@ -468,8 +459,8 @@ test("normalizeResponse with embedded objects", function() { name: "Umber", villains: [{ id: "1", - first_name: "Tom", - last_name: "Dale" + firstName: "Tom", + lastName: "Dale" }] }] }; @@ -508,11 +499,10 @@ test("normalizeResponse with embedded objects", function() { test("normalizeResponse with embedded objects with custom primary key", function() { expect(1); - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend({ + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend({ primaryKey: 'villain_id' })); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } @@ -526,8 +516,8 @@ test("normalizeResponse with embedded objects with custom primary key", function name: "Umber", villains: [{ villain_id: "2", - first_name: "Alex", - last_name: "Baizeau" + firstName: "Alex", + lastName: "Baizeau" }] }] }; @@ -566,8 +556,7 @@ test("normalizeResponse with embedded objects with custom primary key", function test("normalizeResponse with embedded objects with identical relationship and attribute key ", function() { expect(1); - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } }, @@ -576,7 +565,6 @@ test("normalizeResponse with embedded objects with identical relationship and at return this.keyForAttribute(key, type); } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer); var serializer = env.container.lookup("serializer:home-planet"); @@ -586,8 +574,8 @@ test("normalizeResponse with embedded objects with identical relationship and at name: "Umber", villains: [{ id: "1", - first_name: "Alex", - last_name: "Baizeau" + firstName: "Alex", + lastName: "Baizeau" }] }] }; @@ -625,8 +613,7 @@ test("normalizeResponse with embedded objects with identical relationship and at }); test("normalizeResponse with embedded objects of same type as primary type", function() { - env.registry.register('adapter:comment', DS.ActiveModelAdapter); - env.registry.register('serializer:comment', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:comment', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { children: { embedded: 'always' } } @@ -643,12 +630,11 @@ test("normalizeResponse with embedded objects of same type as primary type", fun id: "2", body: "World", root: false - }, - { - id: "3", - body: "Foo", - root: false - }] + }, { + id: "3", + body: "Foo", + root: false + }] }] }; var array; @@ -699,14 +685,12 @@ test("normalizeResponse with embedded objects of same type, but from separate at reformedVillains: DS.hasMany('superVillain', { async: false }) }); - env.registry.register('adapter:home-planet', DS.ActiveModelAdapter); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' }, reformedVillains: { embedded: 'always' } } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer); var serializer = env.container.lookup("serializer:home-planet"); var json_hash = { @@ -715,34 +699,34 @@ test("normalizeResponse with embedded objects of same type, but from separate at name: "Earth", villains: [{ id: "1", - first_name: "Tom" + firstName: "Tom" },{ id: "3", - first_name: "Yehuda" + firstName: "Yehuda" }], - reformed_villains: [{ + reformedVillains: [{ id: "2", - first_name: "Alex" + firstName: "Alex" },{ id: "4", - first_name: "Erik" + firstName: "Erik" }] },{ id: "2", name: "Mars", villains: [{ id: "1", - first_name: "Tom" + firstName: "Tom" },{ id: "3", - first_name: "Yehuda" + firstName: "Yehuda" }], - reformed_villains: [{ + reformedVillains: [{ id: "5", - first_name: "Peter" + firstName: "Peter" },{ id: "6", - first_name: "Trek" + firstName: "Trek" }] }] }; @@ -860,7 +844,7 @@ test("serialize supports serialize:false on non-relationship properties", functi tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", id: '1' }); }); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { firstName: { serialize: false } } @@ -872,9 +856,9 @@ test("serialize supports serialize:false on non-relationship properties", functi }); deepEqual(json, { - last_name: "Dale", - home_planet_id: null, - secret_lab_id: null + lastName: "Dale", + homePlanet: null, + secretLab: null }); }); @@ -885,7 +869,7 @@ test("serialize with embedded objects (hasMany relationship)", function() { 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, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } @@ -902,10 +886,10 @@ test("serialize with embedded objects (hasMany relationship)", function() { name: "Villain League", villains: [{ id: get(tom, "id"), - first_name: "Tom", - last_name: "Dale", - home_planet_id: get(league, "id"), - secret_lab_id: null + firstName: "Tom", + lastName: "Dale", + homePlanet: get(league, "id"), + secretLab: null }] }); }); @@ -916,7 +900,7 @@ test("serialize with embedded objects (unknown hasMany relationship)", function( league = env.store.push('home-planet', { name: "Villain League", id: "123" }); }); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } @@ -939,10 +923,10 @@ test("serialize with embedded objects (unknown hasMany relationship)", function( test("serialize with embedded objects (hasMany relationship) supports serialize:false", function() { run(function() { league = env.store.createRecord('home-planet', { name: "Villain League", id: "123" }); - env.store.createRecord('super-villain', { first_name: "Tom", last_name: "Dale", homePlanet: league, id: '1' }); + env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", homePlanet: league, id: '1' }); }); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { serialize: false } } @@ -965,7 +949,7 @@ test("serialize with (new) embedded objects (hasMany relationship)", function() env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", homePlanet: league }); }); - env.registry.register('serializer:home-planet', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { villains: { embedded: 'always' } } @@ -979,10 +963,10 @@ test("serialize with (new) embedded objects (hasMany relationship)", function() deepEqual(json, { name: "Villain League", villains: [{ - first_name: "Tom", - last_name: "Dale", - home_planet_id: get(league, "id"), - secret_lab_id: null + firstName: "Tom", + lastName: "Dale", + homePlanet: get(league, "id"), + secretLab: null }] }); }); @@ -996,7 +980,7 @@ test("serialize with embedded objects (hasMany relationships, including related superVillain.get('secretWeapons').pushObject(secretWeapon); }); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { evilMinions: { serialize: 'records', deserialize: 'records' }, secretWeapons: { serialize: 'ids' } @@ -1009,43 +993,41 @@ test("serialize with embedded objects (hasMany relationships, including related json = serializer.serialize(superVillain._createSnapshot()); }); deepEqual(json, { - first_name: get(superVillain, "firstName"), - last_name: get(superVillain, "lastName"), - home_planet_id: null, - evil_minions: [{ + firstName: get(superVillain, "firstName"), + lastName: get(superVillain, "lastName"), + homePlanet: null, + evilMinions: [{ id: get(evilMinion, "id"), name: get(evilMinion, "name"), - super_villain_id: "1" + superVillain: "1" }], - secret_lab_id: null, - secret_weapon_ids: ["1"] + secretLab: null, + secretWeapons: ["1"] }); }); test("normalizeResponse with embedded object (belongsTo relationship)", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { embedded: 'always' } } })); - //env.registry.register('serializer:secret-lab', DS.ActiveModelSerializer); var serializer = env.container.lookup("serializer:super-villain"); var json_hash = { super_villain: { id: "1", - first_name: "Tom", - last_name: "Dale", - home_planet_id: "123", - evil_minion_ids: ["1", "2", "3"], - secret_lab: { - minion_capacity: 5000, + firstName: "Tom", + lastName: "Dale", + homePlanet: "123", + evilMinions: ["1", "2", "3"], + secretLab: { + minionCapacity: 5000, vicinity: "California, USA", id: "101" }, - secret_weapon_ids: [] + secretWeapons: [] } }; var json; @@ -1094,8 +1076,7 @@ test("normalizeResponse with embedded object (belongsTo relationship)", function }); test("serialize with embedded object (belongsTo relationship)", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { embedded: 'always' } } @@ -1120,26 +1101,25 @@ test("serialize with embedded object (belongsTo relationship)", function() { }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab: { + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: { id: get(tom, "secretLab").get("id"), - minion_capacity: get(tom, "secretLab").get("minionCapacity"), + minionCapacity: get(tom, "secretLab").get("minionCapacity"), vicinity: get(tom, "secretLab").get("vicinity") } }); }); test("serialize with embedded object (belongsTo relationship) works with different primaryKeys", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { primaryKey: '_id', attrs: { secretLab: { embedded: 'always' } } })); - env.registry.register('serializer:secret-lab', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:secret-lab', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { primaryKey: 'crazy_id' })); @@ -1163,20 +1143,19 @@ test("serialize with embedded object (belongsTo relationship) works with differe }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab: { + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: { crazy_id: get(tom, "secretLab").get("id"), - minion_capacity: get(tom, "secretLab").get("minionCapacity"), + minionCapacity: get(tom, "secretLab").get("minionCapacity"), vicinity: get(tom, "secretLab").get("vicinity") } }); }); test("serialize with embedded object (belongsTo relationship, new no id)", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { embedded: 'always' } } @@ -1202,19 +1181,18 @@ test("serialize with embedded object (belongsTo relationship, new no id)", funct }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab: { - minion_capacity: get(tom, "secretLab").get("minionCapacity"), + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: { + minionCapacity: get(tom, "secretLab").get("minionCapacity"), vicinity: get(tom, "secretLab").get("vicinity") } }); }); test("serialize with embedded object (belongsTo relationship) supports serialize:ids", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { serialize: 'ids' } } @@ -1239,16 +1217,15 @@ test("serialize with embedded object (belongsTo relationship) supports serialize }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab_id: get(tom, "secretLab").get("id") + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: get(tom, "secretLab").get("id") }); }); test("serialize with embedded object (belongsTo relationship) supports serialize:id", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { serialize: 'id' } } @@ -1274,16 +1251,15 @@ test("serialize with embedded object (belongsTo relationship) supports serialize }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab_id: get(tom, "secretLab").get("id") + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: get(tom, "secretLab").get("id") }); }); test("serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { serialize: 'id', deserialize: 'records' } } @@ -1309,16 +1285,15 @@ test("serialize with embedded object (belongsTo relationship) supports serialize }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab_id: get(tom, "secretLab").get("id") + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: get(tom, "secretLab").get("id") }); }); test("serialize with embedded object (belongsTo relationship) supports serialize:false", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { serialize: false } } @@ -1342,15 +1317,14 @@ test("serialize with embedded object (belongsTo relationship) supports serialize }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id") + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id") }); }); test("serialize with embedded object (belongsTo relationship) serializes the id by default if no option specified", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin)); + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin)); var serializer = env.container.lookup("serializer:super-villain"); // records with an id, persisted @@ -1372,16 +1346,15 @@ test("serialize with embedded object (belongsTo relationship) serializes the id }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab_id: get(tom, "secretLab").get("id") + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: get(tom, "secretLab").get("id") }); }); test("when related record is not present, serialize embedded record (with a belongsTo relationship) as null", function() { - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { embedded: 'always' } } @@ -1403,21 +1376,20 @@ test("when related record is not present, serialize embedded record (with a belo }); deepEqual(json, { - first_name: get(tom, "firstName"), - last_name: get(tom, "lastName"), - home_planet_id: get(tom, "homePlanet").get("id"), - secret_lab: null + firstName: get(tom, "firstName"), + lastName: get(tom, "lastName"), + homePlanet: get(tom, "homePlanet").get("id"), + secretLab: null }); }); test("normalizeResponse with multiply-nested belongsTo", function() { - env.registry.register('adapter:evil-minion', DS.ActiveModelAdapter); - env.registry.register('serializer:evil-minion', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:evil-minion', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { superVillain: { embedded: 'always' } } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { homePlanet: { embedded: 'always' } } @@ -1428,15 +1400,15 @@ test("normalizeResponse with multiply-nested belongsTo", function() { evilMinion: { id: "1", name: "Alex", - super_villain: { + superVillain: { id: "1", - first_name: "Tom", - last_name: "Dale", - evil_minion_ids: ["1"], - home_planet: { + firstName: "Tom", + lastName: "Dale", + evilMinions: ["1"], + homePlanet: { id: "1", name: "Umber", - villain_ids: ["1"] + villains: ["1"] } } } @@ -1499,8 +1471,7 @@ test("normalizeResponse with polymorphic hasMany", function() { secretWeapons: DS.hasMany("secretWeapon", { polymorphic: true, async: false }) }); - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretWeapons: { embedded: 'always' } } @@ -1510,9 +1481,9 @@ test("normalizeResponse with polymorphic hasMany", function() { var json_hash = { super_villain: { id: "1", - first_name: "Tom", - last_name: "Dale", - secret_weapons: [ + firstName: "Tom", + lastName: "Dale", + secretWeapons: [ { id: "1", type: "LightSaber", @@ -1574,11 +1545,10 @@ test("normalizeResponse with polymorphic hasMany and custom primary key", functi secretWeapons: DS.hasMany("secretWeapon", { polymorphic: true, async: false }) }); - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:light-saber', DS.ActiveModelSerializer.extend({ + env.registry.register('serializer:light-saber', DS.RESTSerializer.extend({ primaryKey: 'custom' })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretWeapons: { embedded: 'always' } } @@ -1588,9 +1558,9 @@ test("normalizeResponse with polymorphic hasMany and custom primary key", functi var json_hash = { super_villain: { id: "1", - first_name: "Tom", - last_name: "Dale", - secret_weapons: [ + firstName: "Tom", + lastName: "Dale", + secretWeapons: [ { custom: "1", type: "LightSaber", @@ -1655,8 +1625,7 @@ test("normalizeResponse with polymorphic belongsTo", function() { secretLab: DS.belongsTo("secretLab", { polymorphic: true, async: true }) }); - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { embedded: 'always' } } @@ -1666,9 +1635,9 @@ test("normalizeResponse with polymorphic belongsTo", function() { var json_hash = { super_villain: { id: "1", - first_name: "Tom", - last_name: "Dale", - secret_lab: { + firstName: "Tom", + lastName: "Dale", + secretLab: { id: "1", type: "bat-cave", infiltrated: true @@ -1714,23 +1683,22 @@ test("normalizeResponse with polymorphic belongsTo and custom primary key", func secretLab: DS.belongsTo("secretLab", { polymorphic: true, async: true }) }); - env.registry.register('adapter:super-villain', DS.ActiveModelAdapter); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretLab: { embedded: 'always' } } })); - env.registry.register('serializer:bat-cave', DS.ActiveModelSerializer.extend({ + env.registry.register('serializer:bat-cave', DS.RESTSerializer.extend({ primaryKey: 'custom' })); var serializer = env.container.lookup("serializer:super-villain"); var json_hash = { - super_villain: { + superVillain: { id: "1", - first_name: "Tom", - last_name: "Dale", - secret_lab: { + firstName: "Tom", + lastName: "Dale", + secretLab: { custom: "1", type: "bat-cave", infiltrated: true @@ -1788,8 +1756,6 @@ test("Mixin can be used with RESTSerializer which does not define keyForAttribut superVillain.get('evilMinions').pushObject(evilMinion); }); - env.registry.register('serializer:evil-minion', DS.RESTSerializer); - env.registry.register('serializer:secret-weapon', DS.RESTSerializer); env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { evilMinions: { serialize: 'records', deserialize: 'records' } @@ -1818,25 +1784,24 @@ test("Mixin can be used with RESTSerializer which does not define keyForAttribut }); test("normalize with custom belongsTo primary key", function() { - env.registry.register('adapter:evil-minion', DS.ActiveModelAdapter); - env.registry.register('serializer:evil-minion', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:evil-minion', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { superVillain: { embedded: 'always' } } })); - env.registry.register('serializer:super-villain', DS.ActiveModelSerializer.extend({ + env.registry.register('serializer:super-villain', DS.RESTSerializer.extend({ primaryKey: 'custom' })); var serializer = env.container.lookup("serializer:evil-minion"); var json_hash = { - evil_minion: { + evilMinion: { id: "1", name: "Alex", - super_villain: { + superVillain: { custom: "1", - first_name: "Tom", - last_name: "Dale" + firstName: "Tom", + lastName: "Dale" } } }; @@ -1887,7 +1852,7 @@ test("serializing relationships with an embedded and without calls super when no var calledSerializeBelongsTo = false; var calledSerializeHasMany = false; - var Serializer = DS.ActiveModelSerializer.extend({ + var Serializer = DS.RESTSerializer.extend({ serializeBelongsTo: function(snapshot, json, relationship) { calledSerializeBelongsTo = true; return this._super(snapshot, json, relationship); @@ -1921,17 +1886,17 @@ test("serializing relationships with an embedded and without calls super when no }); deepEqual(json, { - first_name: get(superVillain, "firstName"), - last_name: get(superVillain, "lastName"), - home_planet_id: "123", - evil_minions: [{ + firstName: get(superVillain, "firstName"), + lastName: get(superVillain, "lastName"), + homePlanet: "123", + evilMinions: [{ id: get(evilMinion, "id"), name: get(evilMinion, "name"), - super_villain_id: "1" + superVillain: "1" }], - secret_lab_id: "101", + secretLab: "101", // customized serializeHasMany method to generate ids for "manyToOne" relation - secret_weapon_ids: ["1"] + secretWeapons: ["1"] }); ok(calledSerializeBelongsTo); ok(calledSerializeHasMany); @@ -1951,7 +1916,7 @@ test("serializing belongsTo correctly removes embedded foreign key", function() evilMinion = env.store.createRecord('evil-minion', { name: "Evil Minion", secretWeapon: secretWeapon }); }); - env.registry.register('serializer:evil-minion', DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { + env.registry.register('serializer:evil-minion', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { secretWeapon: { embedded: 'always' } } @@ -1966,7 +1931,7 @@ test("serializing belongsTo correctly removes embedded foreign key", function() deepEqual(json, { name: "Evil Minion", - secret_weapon: { + secretWeapon: { name: "Secret Weapon" } }); diff --git a/packages/ember-data/tests/unit/store/lookup-test.js b/packages/ember-data/tests/unit/store/lookup-test.js index c586b204e30..3a5426ea7b8 100644 --- a/packages/ember-data/tests/unit/store/lookup-test.js +++ b/packages/ember-data/tests/unit/store/lookup-test.js @@ -13,8 +13,6 @@ function resetStore() { env.registry.unregister('adapter:application'); env.registry.unregister('serializer:application'); - env.registry.register('serializer:-active-model', DS.ActiveModelSerializer); - env.registry.optionsForType('serializer', { singleton: true }); env.registry.optionsForType('adapter', { singleton: true }); @@ -90,15 +88,15 @@ test('adapter lookup order', () => { strictEqual(personAdapter, lookupAdapter('-rest'), 'looks up the RESTAdapter first'); resetStore(); - registerAdapter('application', DS.ActiveModelSerializer.extend()); + registerAdapter('application', DS.RESTSerializer.extend()); personAdapter = lookupAdapter('person'); strictEqual(personAdapter, lookupAdapter('application'), 'looks up application adapter before RESTAdapter if it exists'); resetStore(); - registerAdapter('application', DS.ActiveModelSerializer.extend()); - registerAdapter('person', DS.ActiveModelSerializer.extend({ customThingy: true })); + registerAdapter('application', DS.RESTSerializer.extend()); + registerAdapter('person', DS.RESTSerializer.extend({ customThingy: true })); ok(lookupAdapter('person').get('customThingy'), 'looks up type serializer before application'); }); @@ -112,23 +110,23 @@ test('serializer lookup order', () => { resetStore(); - registerSerializer('application', DS.ActiveModelSerializer.extend()); + registerSerializer('application', DS.RESTSerializer.extend()); personSerializer = lookupSerializer('person'); strictEqual(personSerializer, lookupSerializer('application'), 'looks up application before default'); resetStore(); registerAdapter('person', DS.Adapter.extend({ - defaultSerializer: '-active-model' + defaultSerializer: '-rest' })); personSerializer = lookupSerializer('person'); - strictEqual(personSerializer, lookupSerializer('-active-model'), 'uses defaultSerializer on adapterFor("model") if application not defined'); + strictEqual(personSerializer, lookupSerializer('-rest'), 'uses defaultSerializer on adapterFor("model") if application not defined'); resetStore(); registerAdapter('person', DS.Adapter.extend({ - defaultSerializer: '-active-model' + defaultSerializer: '-rest' })); - registerSerializer('application', DS.ActiveModelSerializer.extend()); + registerSerializer('application', DS.RESTSerializer.extend()); registerSerializer('person', DS.JSONSerializer.extend({ customThingy: true })); personSerializer = lookupSerializer('person'); diff --git a/packages/ember-data/tests/unit/store/push-test.js b/packages/ember-data/tests/unit/store/push-test.js index a6b4f1a9336..61b675756de 100644 --- a/packages/ember-data/tests/unit/store/push-test.js +++ b/packages/ember-data/tests/unit/store/push-test.js @@ -38,7 +38,7 @@ module("unit/store/push - DS.Store#push", { store = env.store; - env.registry.register('serializer:post', DS.ActiveModelSerializer); + env.registry.register('serializer:post', DS.RESTSerializer); }, teardown: function() { @@ -52,17 +52,20 @@ test("Calling push with a normalized hash returns a record", function() { expect(2); run(function() { - var person = store.push('person', { + var person = store.push({ + type: 'person', id: 'wat', - firstName: "Yehuda", - lastName: "Katz" + attributes: { + firstName: 'Yehuda', + lastName: 'Katz' + } }); store.findRecord('person', 'wat').then(function(foundPerson) { equal(foundPerson, person, "record returned via load() is the same as the record returned from findRecord()"); deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { id: 'wat', - firstName: "Yehuda", - lastName: "Katz" + firstName: 'Yehuda', + lastName: 'Katz' }); }); }); @@ -75,17 +78,20 @@ test("Supplying a model class for `push` is the same as supplying a string", fun env.registry.register('model:programmer', Programmer); run(function() { - store.push('programmer', { + store.push({ + type: 'programmer', id: 'wat', - firstName: "Yehuda", - lastName: "Katz" + attributes: { + firstName: 'Yehuda', + lastName: 'Katz' + } }); store.findRecord('programmer', 'wat').then(function(foundProgrammer) { deepEqual(foundProgrammer.getProperties('id', 'firstName', 'lastName'), { id: 'wat', - firstName: "Yehuda", - lastName: "Katz" + firstName: 'Yehuda', + lastName: 'Katz' }); }); }); @@ -101,10 +107,13 @@ test("Calling push triggers `didLoad` even if the record hasn't been requested f }); run(function() { - store.push('person', { + store.push({ + type: 'person', id: 'wat', - firstName: "Yehuda", - lastName: "Katz" + attributes: { + firstName: 'Yehuda', + lastName: 'Katz' + } }); }); }); @@ -121,22 +130,28 @@ test("Calling push with partial records updates just those attributes", function expect(2); run(function() { - var person = store.push('person', { + var person = store.push({ + type: 'person', id: 'wat', - firstName: "Yehuda", - lastName: "Katz" + attributes: { + firstName: 'Yehuda', + lastName: 'Katz' + } }); - store.push('person', { + store.push({ + type: 'person', id: 'wat', - lastName: "Katz!" + attributes: { + lastName: "Katz!" + } }); store.findRecord('person', 'wat').then(function(foundPerson) { equal(foundPerson, person, "record returned via load() is the same as the record returned from findRecord()"); deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { id: 'wat', - firstName: "Yehuda", + firstName: 'Yehuda', lastName: "Katz!" }); }); @@ -148,10 +163,15 @@ test("Calling push on normalize allows partial updates with raw JSON", function var person; run(function() { - person = store.push('person', { - id: '1', - firstName: "Robert", - lastName: "Jackson" + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Robert', + lastName: 'Jackson' + } + } }); store.push(store.normalize('person', { @@ -218,12 +238,12 @@ test("Calling push with a normalized hash containing IDs of related records retu var person; run(function() { - person = store.push('person', { + person = store.push(store.normalize('person', { id: 'wat', firstName: 'John', lastName: 'Smith', phoneNumbers: ["1", "2"] - }); + })); person.get('phoneNumbers').then(function(phoneNumbers) { deepEqual(phoneNumbers.map(function(item) { return item.getProperties('id', 'number', 'person'); @@ -245,7 +265,7 @@ test("Calling pushPayload allows pushing raw JSON", function () { store.pushPayload('post', { posts: [{ id: '1', - post_title: "Ember rocks" + postTitle: "Ember rocks" }] }); }); @@ -258,7 +278,7 @@ test("Calling pushPayload allows pushing raw JSON", function () { store.pushPayload('post', { posts: [{ id: '1', - post_title: "Ember rocks (updated)" + postTitle: "Ember rocks (updated)" }] }); }); @@ -271,7 +291,7 @@ test("Calling pushPayload allows pushing singular payload properties", function store.pushPayload('post', { post: { id: '1', - post_title: "Ember rocks" + postTitle: "Ember rocks" } }); }); @@ -284,7 +304,7 @@ test("Calling pushPayload allows pushing singular payload properties", function store.pushPayload('post', { post: { id: '1', - post_title: "Ember rocks (updated)" + postTitle: "Ember rocks (updated)" } }); }); @@ -446,12 +466,12 @@ test('Calling push with a link for a non async relationship should warn', functi warns(function() { run(function() { - store.push('person', { + store.push(store.normalize('person', { id: '1', links: { phoneNumbers: '/api/people/1/phone-numbers' } - }); + })); }); }, /You have pushed a record of type 'person' with 'phoneNumbers' as a link, but the association is not an async relationship./); }); @@ -463,27 +483,27 @@ test('Calling push with a link containing an object throws an assertion error', expectAssertion(function() { run(function() { - store.push('person', { + store.push(store.normalize('person', { id: '1', links: { phoneNumbers: { href: '/api/people/1/phone-numbers' } } - }); + })); }); }, "You have pushed a record of type 'person' with 'phoneNumbers' as a link, but the value of that link is not a string."); }); test('Calling push with a link containing the value null', function() { run(function() { - store.push('person', { + store.push(store.normalize('person', { id: '1', firstName: 'Tan', links: { phoneNumbers: null } - }); + })); }); var person = store.peekRecord('person', 1);