From b4cfc68312aa7373c863afba2aa4d2ae5c22ad88 Mon Sep 17 00:00:00 2001 From: Bill Heaton Date: Sun, 11 Sep 2016 16:50:43 -0700 Subject: [PATCH] Change hasMany/hasOne to toMany/toOne - alias toOne as hasOne - alias toMany as hasMany --- addon/mixins/resource-operations.js | 4 +- addon/models/resource.js | 42 +++++++++---------- addon/utils/attr.js | 2 +- addon/utils/related-proxy.js | 10 ++--- addon/utils/{has-many.js => to-many.js} | 18 ++++---- addon/utils/{has-one.js => to-one.js} | 18 ++++---- .../files/__root__/__path__/__name__.js | 2 +- blueprints/jsonapi-model/index.js | 8 ++-- tests/dummy/app/models/author.js | 4 +- tests/dummy/app/models/comment.js | 6 +-- tests/dummy/app/models/commenter.js | 4 +- tests/dummy/app/models/employee.js | 6 +-- tests/dummy/app/models/picture.js | 4 +- tests/dummy/app/models/post.js | 6 +-- tests/dummy/app/models/product.js | 4 +- tests/dummy/app/models/supervisor.js | 4 +- tests/unit/mixins/fetch-test.js | 4 +- tests/unit/mixins/resource-operations-test.js | 6 +-- tests/unit/models/resource-test.js | 30 ++++++------- .../{has-many-test.js => to-many-test.js} | 6 +-- .../utils/{has-one-test.js => to-one-test.js} | 6 +-- 21 files changed, 99 insertions(+), 95 deletions(-) rename addon/utils/{has-many.js => to-many.js} (84%) rename addon/utils/{has-one.js => to-one.js} (83%) rename tests/unit/utils/{has-many-test.js => to-many-test.js} (90%) rename tests/unit/utils/{has-one-test.js => to-one-test.js} (89%) diff --git a/addon/mixins/resource-operations.js b/addon/mixins/resource-operations.js index d9bbd83..9df5251 100644 --- a/addon/mixins/resource-operations.js +++ b/addon/mixins/resource-operations.js @@ -127,9 +127,9 @@ export default Ember.Mixin.create({ updateRelationship(relationship, ids, errorCallback) { let related = this.get(relationship); let rollback; - if (related.kind === 'hasOne') { + if (related.kind === 'toOne') { rollback = related.get('id'); - } else if (related.kind === 'hasMany') { + } else if (related.kind === 'toMany') { rollback = related.mapBy('id'); } this._updateRelationshipsData(relationship, ids); diff --git a/addon/models/resource.js b/addon/models/resource.js index 239b186..4d51b07 100644 --- a/addon/models/resource.js +++ b/addon/models/resource.js @@ -6,8 +6,8 @@ import Ember from 'ember'; import { pluralize, singularize } from 'ember-inflector'; import attr from 'ember-jsonapi-resources/utils/attr'; -import hasOne from 'ember-jsonapi-resources/utils/has-one'; -import hasMany from 'ember-jsonapi-resources/utils/has-many'; +import { toOne, hasOne } from 'ember-jsonapi-resources/utils/to-one'; +import { toMany, hasMany } from 'ember-jsonapi-resources/utils/to-many'; import { isType } from 'ember-jsonapi-resources/utils/is'; import ResourceOperationsMixin from '../mixins/resource-operations'; @@ -187,9 +187,9 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { Also sets or adds to the `content` of the related proxy object. - - For has-many relations the related identifier object is added to + - For to-many relations the related identifier object is added to the resource linkage data array. - - For has-one relations the resource identifier object is assigned, + - For to-one relations the resource identifier object is assigned, so the relation may be replaced. See: @@ -248,12 +248,12 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { setupRelationshipTracking.call(this, relation, meta.kind); let ref = this._relationships[relation]; let relationshipData = this.get(`relationships.${relation}.data`); - if (meta && meta.kind === 'hasOne') { + if (meta && meta.kind === 'toOne') { if (!relationshipData || relationshipData.id !== identifier.id) { ref.changed = identifier; ref.previous = ref.previous || previous; } - } else if (meta && meta.kind === 'hasMany') { + } else if (meta && meta.kind === 'toMany') { let id = identifier.id; ref.removals = Ember.A(ref.removals.rejectBy('id', id)); if (!ref.added.findBy('id', id)) { @@ -266,8 +266,8 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { Removes resource identifier object of the relationship data. Also, sets the `content` of the related (computed property's) proxy object to `null`. - - For has-one relations the (resource linkage) data is set to `null`. - - For has-many relations the resource identifier object is removed from + - For to-one relations the (resource linkage) data is set to `null`. + - For to-many relations the resource identifier object is removed from the resource Linkage `data` array. See: @@ -315,10 +315,10 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { let ref = this._relationships[relation] = this._relationships[relation] || {}; let meta = this.relationMetadata(relation); setupRelationshipTracking.call(this, relation, meta.kind); - if (meta.kind === 'hasOne') { + if (meta.kind === 'toOne') { ref.changed = null; ref.previous = ref.previous || this.get('relationships.' + relation).data; - } else if (meta.kind === 'hasMany') { + } else if (meta.kind === 'toMany') { ref.added = Ember.A(ref.added.rejectBy('id', id)); if (!ref.removals.findBy('id', id)) { ref.removals.pushObject({ type: pluralize(relation), id: id }); @@ -428,11 +428,11 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { relations.forEach((relation) => { let ref = this._relationships[relation]; let meta = this.relationMetadata(relation); - if (meta && meta.kind === 'hasOne') { + if (meta && meta.kind === 'toOne') { if (ref.changed && ref.changed.id && ref.previous && ref.previous.id) { this.addRelationship(relation, ref.previous.id); } - } else if (meta && meta.kind === 'hasMany') { + } else if (meta && meta.kind === 'toMany') { let added = ref.added.mapBy('id'); let removed = ref.removals.mapBy('id'); added.forEach( (id) => { @@ -499,11 +499,11 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { /** Sets the relationships data, used after the promise proxy resolves by - hasOne and hasMany helpers + toOne and toMany helpers @method didResolveProxyRelation @param {String} relation name - @param {String} kind of relation hasOne or hasMany + @param {String} kind of relation toOne or toMany @param {Array|Object} related resource(s) */ didResolveProxyRelation(relation, kind, related) { @@ -518,9 +518,9 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { let relationshipData = 'relationships.' + relation + '.data'; let data = this.get(relationshipData); if (!data) { - if (kind === 'hasOne') { + if (kind === 'toOne') { this.set(relationshipData, {}); - } else if (kind === 'hasMany') { + } else if (kind === 'toMany') { this.set(relationshipData, Ember.A([])); } } @@ -620,7 +620,7 @@ Resource.reopenClass({ export default Resource; -export { attr, hasOne, hasMany }; +export { attr, toOne, toMany, hasOne, hasMany }; let _rp = 'service type id attributes relationships links meta _attributes isNew cacheDuration isCacheExpired'; const ignoredMetaProps = _rp.split(' '); @@ -650,9 +650,9 @@ function setupRelationship(relation, kind) { ref.links = {}; } if (!ref.data) { - if (kind === 'hasOne') { + if (kind === 'toOne') { ref.data = null; - } else if (kind === 'hasMany') { + } else if (kind === 'toMany') { ref.data = Ember.A([]); } } @@ -661,10 +661,10 @@ function setupRelationship(relation, kind) { function setupRelationshipTracking(relation, kind) { this._relationships[relation] = this._relationships[relation] || {}; let ref = this._relationships[relation]; - if (kind === 'hasOne') { + if (kind === 'toOne') { ref.changed = ref.changed || null; ref.previous = ref.previous || null; - } else if (kind === 'hasMany') { + } else if (kind === 'toMany') { ref.added = ref.added || Ember.A([]); ref.removals = ref.removals || Ember.A([]); } diff --git a/addon/utils/attr.js b/addon/utils/attr.js index 40cc721..0da3be5 100644 --- a/addon/utils/attr.js +++ b/addon/utils/attr.js @@ -22,7 +22,7 @@ import { isBlank, isDasherized, isType } from 'ember-jsonapi-resources/utils/is' ```js import Ember from 'ember'; import Resource from 'ember-jsonapi-resources/models/resource'; - import { attr, hasOne, hasMany } from 'ember-jsonapi-resources/models/resource'; + import { attr, toOne, toMany } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'articles', diff --git a/addon/utils/related-proxy.js b/addon/utils/related-proxy.js index d337ca0..ce93805 100644 --- a/addon/utils/related-proxy.js +++ b/addon/utils/related-proxy.js @@ -53,15 +53,15 @@ const RelatedProxyUtil = Ember.Object.extend({ @method createProxy @param {Resource} resource - @param {String} kind 'hasMany' or 'hasOne' + @param {String} kind 'toMany' or 'toOne' @return {PromiseProxy|ObjectProxy|ArrayProxy} proxy instance, new resource uses mock relations */ createProxy(resource, kind) { let proxyFactory, newContent; - if (kind === 'hasMany') { + if (kind === 'toMany') { proxyFactory = Ember.ArrayProxy; newContent = Ember.A([]); - } else if (kind === 'hasOne') { + } else if (kind === 'toOne') { proxyFactory = Ember.ObjectProxy; newContent = Ember.Object.create(); } @@ -76,7 +76,7 @@ const RelatedProxyUtil = Ember.Object.extend({ /** @method proxySetup @param {Resource} resource - @param {String} kind 'hasMany' or 'hasOne' + @param {String} kind 'toMany' or 'toOne' @param {Ember.ObjectProxy|Ember.ArrayProxy} proxyFactory @return {PromiseProxy} proxy */ @@ -92,7 +92,7 @@ const RelatedProxyUtil = Ember.Object.extend({ 'promise': promise, 'type': relation, 'kind': kind }); return proxyProto.create({ - content: (kind === 'hasOne') ? Ember.Object.create() : Ember.A([]) + content: (kind === 'toOne') ? Ember.Object.create() : Ember.A([]) }); }, diff --git a/addon/utils/has-many.js b/addon/utils/to-many.js similarity index 84% rename from addon/utils/has-many.js rename to addon/utils/to-many.js index 8696b11..3034892 100644 --- a/addon/utils/has-many.js +++ b/addon/utils/to-many.js @@ -1,7 +1,7 @@ /** @module ember-jsonapi-resources @submodule utils - @main hasMany + @main toMany **/ import Ember from 'ember'; @@ -16,7 +16,7 @@ import { isDasherized } from 'ember-jsonapi-resources/utils/is'; let Author = Resource.extend({ type: 'authors', name: attr(), - posts: hasMany('posts') + posts: toMany('posts') }); ``` @@ -30,11 +30,11 @@ import { isDasherized } from 'ember-jsonapi-resources/utils/is'; let Supervisor = Person.extend({ type: 'supervisors', - directReports: hasMany({ resource: 'employees', type: 'people' }) + directReports: toMany({ resource: 'employees', type: 'people' }) }); ``` - @method hasMany + @method toMany @for Resource @final @param {String|Object} relation the name of the relationship @@ -42,7 +42,7 @@ import { isDasherized } from 'ember-jsonapi-resources/utils/is'; @param {String} relation.type the name of the type or service to use @return {Object} computed property */ -export default function hasMany(relation) { +export function toMany(relation) { let type = relation; if (typeof type === 'object') { assertResourceAndTypeProps(relation); @@ -50,7 +50,7 @@ export default function hasMany(relation) { relation = relation.resource; } assertDasherizedHasManyRelation(relation); - let kind = 'hasMany'; + let kind = 'toMany'; let util = RelatedProxyUtil.create({'relationship': relation, 'type': type, kind: kind}); let path = linksPath(relation); return Ember.computed(path, function () { @@ -58,6 +58,8 @@ export default function hasMany(relation) { }).meta({relation: relation, type: type, kind: kind}); } +export let hasMany = toMany; + function assertResourceAndTypeProps(relation) { try { let msg = 'Options must include properties: resource, type'; @@ -70,8 +72,8 @@ function assertResourceAndTypeProps(relation) { function assertDasherizedHasManyRelation(name) { try { let relationName = Ember.String.dasherize(name); - let msg = " are recommended to use dasherized names, e.g `hasMany('"+ relationName +"')`"; - msg += ", instead of `hasMany('"+ name +"')`"; + let msg = " are recommended to use dasherized names, e.g `toMany('"+ relationName +"')`"; + msg += ", instead of `toMany('"+ name +"')`"; Ember.assert(msg, isDasherized(name)); } catch(e) { Ember.Logger.warn(e.message); diff --git a/addon/utils/has-one.js b/addon/utils/to-one.js similarity index 83% rename from addon/utils/has-one.js rename to addon/utils/to-one.js index 5a33984..76c4bf5 100644 --- a/addon/utils/has-one.js +++ b/addon/utils/to-one.js @@ -1,7 +1,7 @@ /** @module ember-jsonapi-resources @submodule utils - @main hasOne + @main toOne **/ import Ember from 'ember'; @@ -15,7 +15,7 @@ import { isDasherized } from 'ember-jsonapi-resources/utils/is'; ```js let Employee = Person.extend({ type: 'employees', - supervisor: hasOne('supervisor') + supervisor: toOne('supervisor') }); ``` @@ -29,11 +29,11 @@ import { isDasherized } from 'ember-jsonapi-resources/utils/is'; let Employee = Person.extend({ type: 'employees', - supervisor: hasOne({ resource: 'supervisor', type: 'people' }) + supervisor: toOne({ resource: 'supervisor', type: 'people' }) }); ``` - @method hasOne + @method toOne @for Resource @final @param {String|Object} relation the name of the relationship @@ -41,7 +41,7 @@ import { isDasherized } from 'ember-jsonapi-resources/utils/is'; @param {String} relation.type the name of the type or service to use @return {Object} computed property */ -export default function hasOne(relation) { +export function toOne(relation) { let type = relation; if (typeof type === 'object') { assertResourceAndTypeProps(relation); @@ -49,7 +49,7 @@ export default function hasOne(relation) { relation = relation.resource; } assertDasherizedHasOneRelation(type); - let kind = 'hasOne'; + let kind = 'toOne'; let util = RelatedProxyUtil.create({relationship: relation, type: type, kind: kind}); let path = linksPath(relation); return Ember.computed(path, function () { @@ -57,6 +57,8 @@ export default function hasOne(relation) { }).meta({relation: relation, type: type, kind: kind}); } +export let hasOne = toOne; + function assertResourceAndTypeProps(relation) { try { let msg = 'Options must include properties: resource, type'; @@ -69,8 +71,8 @@ function assertResourceAndTypeProps(relation) { function assertDasherizedHasOneRelation(name) { try { let relationName = Ember.String.dasherize(name); - let msg = " are recommended to use dasherized names, e.g `hasOne('"+ relationName +"')`"; - msg += ", instead of `hasOne('"+ name +"')`"; + let msg = " are recommended to use dasherized names, e.g `toOne('"+ relationName +"')`"; + msg += ", instead of `toOne('"+ name +"')`"; Ember.assert(msg, isDasherized(name)); } catch(e) { Ember.Logger.warn(e.message); diff --git a/blueprints/jsonapi-model/files/__root__/__path__/__name__.js b/blueprints/jsonapi-model/files/__root__/__path__/__name__.js index b448cd8..e185110 100644 --- a/blueprints/jsonapi-model/files/__root__/__path__/__name__.js +++ b/blueprints/jsonapi-model/files/__root__/__path__/__name__.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from 'ember-jsonapi-resources/models/resource'; -import { attr, hasOne, hasMany } from 'ember-jsonapi-resources/models/resource'; +import { attr, toOne, toMany } from 'ember-jsonapi-resources/models/resource'; let <%= classifiedModuleName %>Model = Resource.extend({ type: '<%= resource %>', diff --git a/blueprints/jsonapi-model/index.js b/blueprints/jsonapi-model/index.js index fe9254b..d23891a 100644 --- a/blueprints/jsonapi-model/index.js +++ b/blueprints/jsonapi-model/index.js @@ -94,10 +94,10 @@ module.exports = { function resourceAttr(name, type) { switch (type) { - case 'has-one': - return 'hasOne(\'' + name + '\')'; - case 'has-many': - return 'hasMany(\'' + name + '\')'; + case 'to-one': + return 'toOne(\'' + name + '\')'; + case 'to-many': + return 'toMany(\'' + name + '\')'; case '': return 'attr()'; default: diff --git a/tests/dummy/app/models/author.js b/tests/dummy/app/models/author.js index 6155df3..eca6600 100644 --- a/tests/dummy/app/models/author.js +++ b/tests/dummy/app/models/author.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from './resource'; -import { attr, hasMany } from 'ember-jsonapi-resources/models/resource'; +import { attr, toMany } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'authors', @@ -9,5 +9,5 @@ export default Resource.extend({ name: attr('string'), email: attr('string'), - posts: hasMany('posts') + posts: toMany('posts') }); diff --git a/tests/dummy/app/models/comment.js b/tests/dummy/app/models/comment.js index 50be0a0..3a364bf 100644 --- a/tests/dummy/app/models/comment.js +++ b/tests/dummy/app/models/comment.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from './resource'; -import { attr, hasOne } from 'ember-jsonapi-resources/models/resource'; +import { attr, toOne } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'comments', @@ -14,6 +14,6 @@ export default Resource.extend({ } }), - commenter: hasOne('commenter'), - post: hasOne('post') + commenter: toOne('commenter'), + post: toOne('post') }); diff --git a/tests/dummy/app/models/commenter.js b/tests/dummy/app/models/commenter.js index b7bf5e3..9b234b4 100644 --- a/tests/dummy/app/models/commenter.js +++ b/tests/dummy/app/models/commenter.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from './resource'; -import { attr, hasMany } from 'ember-jsonapi-resources/models/resource'; +import { attr, toMany } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'commenters', @@ -10,5 +10,5 @@ export default Resource.extend({ email: attr('string'), hash: attr(), - comments: hasMany('comments') + comments: toMany('comments') }); diff --git a/tests/dummy/app/models/employee.js b/tests/dummy/app/models/employee.js index 90a724d..ab28441 100644 --- a/tests/dummy/app/models/employee.js +++ b/tests/dummy/app/models/employee.js @@ -1,8 +1,8 @@ import PersonResource from './person'; -import { hasOne, hasMany } from 'ember-jsonapi-resources/models/resource'; +import { toOne, toMany } from 'ember-jsonapi-resources/models/resource'; export default PersonResource.extend({ type: 'employees', - pictures: hasMany('pictures'), - supervisor: hasOne('supervisor') + pictures: toMany('pictures'), + supervisor: toOne('supervisor') }); diff --git a/tests/dummy/app/models/picture.js b/tests/dummy/app/models/picture.js index b0fae88..c8f3552 100644 --- a/tests/dummy/app/models/picture.js +++ b/tests/dummy/app/models/picture.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from './resource'; -import { attr, hasOne } from 'ember-jsonapi-resources/models/resource'; +import { attr, toOne } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'pictures', @@ -10,5 +10,5 @@ export default Resource.extend({ "updated-at": attr('date'), "created-at": attr('date'), - imageable: hasOne('imageable') // polymorphic + imageable: toOne('imageable') // polymorphic }); diff --git a/tests/dummy/app/models/post.js b/tests/dummy/app/models/post.js index 01045f9..33c702d 100644 --- a/tests/dummy/app/models/post.js +++ b/tests/dummy/app/models/post.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from './resource'; -import { attr, hasOne, hasMany } from 'ember-jsonapi-resources/models/resource'; +import { attr, toOne, toMany } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'posts', @@ -10,6 +10,6 @@ export default Resource.extend({ date: attr(), excerpt: attr('string'), - author: hasOne('author'), - comments: hasMany('comments') + author: toOne('author'), + comments: toMany('comments') }); diff --git a/tests/dummy/app/models/product.js b/tests/dummy/app/models/product.js index a98f5f1..b834985 100644 --- a/tests/dummy/app/models/product.js +++ b/tests/dummy/app/models/product.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resource from './resource'; -import { attr, hasMany } from 'ember-jsonapi-resources/models/resource'; +import { attr, toMany } from 'ember-jsonapi-resources/models/resource'; export default Resource.extend({ type: 'products', @@ -8,5 +8,5 @@ export default Resource.extend({ name: attr('string'), - pictures: hasMany('pictures') + pictures: toMany('pictures') }); diff --git a/tests/dummy/app/models/supervisor.js b/tests/dummy/app/models/supervisor.js index b794f44..5b282e0 100644 --- a/tests/dummy/app/models/supervisor.js +++ b/tests/dummy/app/models/supervisor.js @@ -1,7 +1,7 @@ import EmployeeResource from './person'; -import { hasMany } from 'ember-jsonapi-resources/models/resource'; +import { toMany } from 'ember-jsonapi-resources/models/resource'; export default EmployeeResource.extend({ type: 'supervisors', - directReports: hasMany({resource: 'direct-reports', type: 'employees'}) + directReports: toMany({resource: 'direct-reports', type: 'employees'}) }); diff --git a/tests/unit/mixins/fetch-test.js b/tests/unit/mixins/fetch-test.js index c1847bf..14a02c7 100644 --- a/tests/unit/mixins/fetch-test.js +++ b/tests/unit/mixins/fetch-test.js @@ -136,7 +136,7 @@ test('#_getAjaxHeaders', function(assert) { assert.equal(headers['Cache-Control'], 'max-age=0, private, must-revalidate', 'Catch control header ok'); }); -test('#ajaxSuccessHandler handles response for empty has-one relationship', function(assert) { +test('#ajaxSuccessHandler handles response for empty to-one relationship', function(assert) { assert.expect(1); let result = void 0; let resolve = function(resp) { result = resp; }; @@ -148,7 +148,7 @@ test('#ajaxSuccessHandler handles response for empty has-one relationship', func assert.ok(result === null, 'resolved with `null`'); }); -test('#fetchSuccessHandler handles response for empty has-one relationship', function(assert) { +test('#fetchSuccessHandler handles response for empty to-one relationship', function(assert) { assert.expect(1); let done = assert.async(); let response = { diff --git a/tests/unit/mixins/resource-operations-test.js b/tests/unit/mixins/resource-operations-test.js index 1f0cc47..c51680f 100644 --- a/tests/unit/mixins/resource-operations-test.js +++ b/tests/unit/mixins/resource-operations-test.js @@ -3,7 +3,7 @@ import RSVP from 'rsvp'; // import ResourceOperationsMixin from 'ember-jsonapi-resources/mixins/resource-operations'; import { module, test } from 'qunit'; import Resource from 'ember-jsonapi-resources/models/resource'; -import { attr/*, hasOne, hasMany*/ } from 'ember-jsonapi-resources/models/resource'; +import { attr/*, toOne, toMany*/ } from 'ember-jsonapi-resources/models/resource'; let promiseResolved = function() { return RSVP.Promise.resolve(); }; @@ -24,8 +24,8 @@ module('Unit | Mixin | resource-operations', { }, name: attr('string'), // mock relationship computed properties - guns: {kind: 'hasMany', mapBy: Ember.K }, // hasMany('guns') - horse: {kind: 'hasOne', get: Ember.K } // hasOne('horse') + guns: {kind: 'toMany', mapBy: Ember.K }, // toMany('guns') + horse: {kind: 'toOne', get: Ember.K } // toOne('horse') }); this.subject = Cowboy.create({ id: 1, name:'Lone Ranger'}); // mock payload setup diff --git a/tests/unit/models/resource-test.js b/tests/unit/models/resource-test.js index 919f2b1..6565950 100644 --- a/tests/unit/models/resource-test.js +++ b/tests/unit/models/resource-test.js @@ -253,11 +253,11 @@ test('#relationMetadata', function(assert) { } }); let metaData = post.relationMetadata('author'); - assert.ok(metaData.kind, 'hasOne', 'meta kind is hasOne'); + assert.ok(metaData.kind, 'toOne', 'meta kind is toOne'); assert.ok(metaData.relation, 'author', 'meta relation is author'); assert.ok(metaData.type, 'author', 'meta type is author'); metaData = post.relationMetadata('comments'); - assert.ok(metaData.kind, 'hasMany', 'meta kind is hasMany'); + assert.ok(metaData.kind, 'toMany', 'meta kind is toMany'); assert.ok(metaData.relation, 'comments', 'meta relation is comments'); assert.ok(metaData.type, 'comments', 'meta type is comments'); }); @@ -375,7 +375,7 @@ test('#removeRelationship', function(assert) { }; assert.deepEqual(author.get('relationships.posts'), authorPostsRelation, - 'author relations have a post (hasMany)'); + 'author relations have a post (toMany)'); let postAuthorRelation = { data: { type: 'authors', id: '2'}, links: { related: 'url' } @@ -385,10 +385,10 @@ test('#removeRelationship', function(assert) { }; assert.deepEqual(post.get('relationships.author'), postAuthorRelation, - 'post relations have an author (hasOne)'); + 'post relations have an author (toOne)'); assert.deepEqual(post.get('relationships.comments'), postCommentsRelation, - 'post relations have a comment (hasMany)'); + 'post relations have a comment (toMany)'); let commentCommenterRelation = { data: {type: 'commenters', id: '4'}, links: { related: 'url'} @@ -398,20 +398,20 @@ test('#removeRelationship', function(assert) { }; assert.deepEqual(comment.get('relationships.commenter'), commentCommenterRelation, - 'comment relations have a commenter (hasOne)'); + 'comment relations have a commenter (toOne)'); assert.deepEqual(comment.get('relationships.post'), commentPostRelation, - 'comment relations have a post (hasOne)'); + 'comment relations have a post (toOne)'); let commenterCommentsRelation = {data: [{type: 'comments', id: '3'}], links: { related: 'url'} }; assert.deepEqual(commenter.get('relationships.comments'), commenterCommentsRelation, - 'commenter relations have a comment (hasMany)'); + 'commenter relations have a comment (toMany)'); // Remove relationships and test for correct representation of relationships. post.removeRelationship('author', '2'); - // author relationship must still exist, but empty (hasOne == null) + // author relationship must still exist, but empty (toOne == null) postAuthorRelation.data = null; assert.deepEqual(post.get('relationships.author'), postAuthorRelation, @@ -422,7 +422,7 @@ test('#removeRelationship', function(assert) { 'removed author from post, comments relation unchanged'); post.removeRelationship('comments', '3'); - // comments relationship must still exist, but empty (hasMany == empty array) + // comments relationship must still exist, but empty (toMany == empty array) postCommentsRelation.data = []; // author relationship must be unchanged. assert.deepEqual(post.get('relationships.comments'), @@ -433,14 +433,14 @@ test('#removeRelationship', function(assert) { 'removed comment from post, author relation unchanged'); author.removeRelationship('posts', '1'); - // posts relation must still exist, but empty (hasMany == empty array) + // posts relation must still exist, but empty (toMany == empty array) authorPostsRelation.data = []; assert.deepEqual(author.get('relationships.posts'), authorPostsRelation, 'removed a post from author, posts relation now empty'); comment.removeRelationship('commenter', '4'); - // comment relation must still exist, but empty (hasOne == null) + // comment relation must still exist, but empty (toOne == null) commentCommenterRelation.data = null; assert.deepEqual(comment.get('relationships.commenter'), commentCommenterRelation, @@ -459,7 +459,7 @@ test('#removeRelationship', function(assert) { 'removed a post from comment, commenter relation unchanged'); commenter.removeRelationship('comments', '3'); - // comments relation must still exist, but empty (hasMany == empty array) + // comments relation must still exist, but empty (toMany == empty array) commenterCommentsRelation.data = []; assert.deepEqual(commenter.get('relationships.comments'), commenterCommentsRelation, @@ -538,13 +538,13 @@ test('#didResolveProxyRelation', function(assert) { } }); - post.didResolveProxyRelation('author', 'hasOne', author); + post.didResolveProxyRelation('author', 'toOne', author); assert.ok(post.get('relationships.author.data'), 'author data is setup'); assert.equal(post.get('relationships.author.data.type'), 'authors', 'relation data set for authors type'); assert.equal(post.get('relationships.author.data.id'), '2', 'relation data set with author id: 2'); - author.didResolveProxyRelation('posts', 'hasMany', post); + author.didResolveProxyRelation('posts', 'toMany', post); assert.ok(author.get('relationships.posts.data'), 'post data is setup'); assert.equal(author.get('relationships.posts.data')[0].type, 'posts', 'relation data set for posts type'); diff --git a/tests/unit/utils/has-many-test.js b/tests/unit/utils/to-many-test.js similarity index 90% rename from tests/unit/utils/has-many-test.js rename to tests/unit/utils/to-many-test.js index 16b2b23..aa6290c 100644 --- a/tests/unit/utils/has-many-test.js +++ b/tests/unit/utils/to-many-test.js @@ -13,7 +13,7 @@ const mockService = function () { }; let entities = ['post', 'author']; -moduleFor('model:resource', 'Unit | Utility | hasMany', { +moduleFor('model:resource', 'Unit | Utility | toMany', { beforeEach() { setup.call(this); this.sandbox = window.sinon.sandbox.create(); @@ -31,7 +31,7 @@ moduleFor('model:resource', 'Unit | Utility | hasMany', { } }); -test('hasMany() helper sets up a promise proxy to a related resource', function(assert) { +test('toMany() helper sets up a promise proxy to a related resource', function(assert) { let author = Ember.getOwner(this)._lookupFactory('model:author').create({ id: '1', attributes: { name: 'pixelhandler' }, relationships: { @@ -56,5 +56,5 @@ test('hasMany() helper sets up a promise proxy to a related resource', function( } }); let promise = author.get('posts'); - assert.ok(promise.toString().match('ArrayProxy').length === 1, 'ArrayProxy used for hasMany relation'); + assert.ok(promise.toString().match('ArrayProxy').length === 1, 'ArrayProxy used for toMany relation'); }); diff --git a/tests/unit/utils/has-one-test.js b/tests/unit/utils/to-one-test.js similarity index 89% rename from tests/unit/utils/has-one-test.js rename to tests/unit/utils/to-one-test.js index f1d13e3..a9983ca 100644 --- a/tests/unit/utils/has-one-test.js +++ b/tests/unit/utils/to-one-test.js @@ -14,7 +14,7 @@ const mockService = function () { }; let entities = ['post', 'author']; -moduleFor('model:resource', 'Unit | Utility | hasOne', { +moduleFor('model:resource', 'Unit | Utility | toOne', { beforeEach() { setup.call(this); this.sandbox = window.sinon.sandbox.create(); @@ -32,7 +32,7 @@ moduleFor('model:resource', 'Unit | Utility | hasOne', { } }); -test('hasOne() helper sets up a promise proxy to a related resource', function(assert) { +test('toOne() helper sets up a promise proxy to a related resource', function(assert) { let post = Ember.getOwner(this)._lookupFactory('model:post').create({ id: '1', attributes: { title: 'Wyatt Earp', excerpt: 'Was a gambler.'}, relationships: { @@ -46,5 +46,5 @@ test('hasOne() helper sets up a promise proxy to a related resource', function(a } }); let promise = post.get('author'); - assert.ok(promise.toString().match('ObjectProxy').length === 1, 'ObjectProxy used for hasOne relation'); + assert.ok(promise.toString().match('ObjectProxy').length === 1, 'ObjectProxy used for toOne relation'); });