- Notifications
You must be signed in to change notification settings - Fork 19
Improve test setup#92
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
51f8fed7382a950fbba5027e37ab2c0da1df127f956eed5324e00accc79e92285cb60580a180445073d2fc3957f49982413aa664f1a0eed98e6e1512fb312730062940a8a38fc663d0a7992141c5df288165db1dcfb0a5f70b31e0246afcbaf0754c190d364c28e08ef1b8095b54fc8cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -116,7 +116,7 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { | ||
| @method toString | ||
| */ | ||
| toString() { | ||
| let type = this.get('type') || 'null'; | ||
| let type = singularize(this.get('type')) || 'null'; | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes toStrings more predictable and easier to test. | ||
| let id = this.get('id') || 'null'; | ||
| return `[JSONAPIResource|${type}:${id}]`; | ||
| }, | ||
| @@ -189,6 +189,7 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { | ||
| @param {String} id | ||
| */ | ||
| addRelationship(related, id) { | ||
| if (id !== undefined) { id = id.toString(); } // ensure String id. | ||
| let key = ['relationships', related, 'data'].join('.'); | ||
| let data = this.get(key); | ||
| let type = pluralize(related); | ||
| @@ -229,6 +230,8 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { | ||
| @param {String} id | ||
| */ | ||
| removeRelationship(related, id) { | ||
| if (id !== undefined) { id = id.toString(); } // ensure String ids. | ||
| let relation = this.get('relationships.' + related); | ||
| if (Array.isArray(relation.data)) { | ||
| for (let i = 0; i < relation.data.length; i++) { | ||
| @@ -415,8 +418,14 @@ Resource.reopenClass({ | ||
| for (let i = 0; i < attrs.length; i++) { | ||
| prototype[attrs[i]] = {}; | ||
| } | ||
| const instance = this._super(prototype); | ||
| if (properties) { | ||
| if (properties.hasOwnProperty('id')) { | ||
| // JSONAPI ids MUST be strings. | ||
| properties.id = properties.id.toString(); | ||
Owner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should work for both creating on client side (via app, e.g. new resource) as well as when deserializing, nice. CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes. So now we do support mildly broken JSONAPI servers :) Owner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it's worth adding an Assert in here, https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/addon/serializers/application.js#L208-L233 ? CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmm... meh... It was kinda fitting when we were thinking about adding code to the serializer for casting to string.. but since we're not doing that (it's handled by | ||
| } | ||
| instance.setProperties(properties); | ||
| } | ||
| let type = singularize(instance.get('type')); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,7 @@ import Resource from './resource'; | ||
| import { attr, hasMany } from 'ember-jsonapi-resources/models/resource'; | ||
| export default Resource.extend({ | ||
| type: 'author', | ||
| type: 'authors', | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistency. | ||
| service: Ember.inject.service('authors'), | ||
| name: attr('string'), | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,7 @@ import Resource from './resource'; | ||
| import { attr, hasOne } from 'ember-jsonapi-resources/models/resource'; | ||
| export default Resource.extend({ | ||
| type: 'comment', | ||
| type: 'comments', | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistency. | ||
| service: Ember.inject.service('comments'), | ||
| body: attr('string'), | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,7 @@ import Resource from './resource'; | ||
| import { attr, hasMany } from 'ember-jsonapi-resources/models/resource'; | ||
| export default Resource.extend({ | ||
| type: 'commenter', | ||
| type: 'commenters', | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistency. | ||
| service: Ember.inject.service('commenters'), | ||
| name: attr('string'), | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,8 @@ | ||
| import Ember from 'ember'; | ||
| import Resource from './resource'; | ||
| import { attr, hasMany } from 'ember-jsonapi-resources/models/resource'; | ||
| import PersonResource from './person'; | ||
| import { hasOne, hasMany } from 'ember-jsonapi-resources/models/resource'; | ||
| export default Resource.extend({ | ||
| export default PersonResource.extend({ | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Person->Employee->Supervisor. | ||
| type: 'employees', | ||
| service: Ember.inject.service('employees'), | ||
| name: attr('string'), | ||
| pictures: hasMany('pictures') | ||
| pictures: hasMany('pictures'), | ||
| supervisor: hasOne({resource: 'supervisor', type: 'employees'}) | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Ember from 'ember'; | ||
| import Resource from './resource'; | ||
| import { attr } from 'ember-jsonapi-resources/models/resource'; | ||
| export default Resource.extend({ | ||
| type: 'people', | ||
| service: Ember.inject.service('people'), | ||
| name: attr() // can use any value type for an attribute | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,7 @@ import Resource from './resource'; | ||
| import { attr, hasOne, hasMany } from 'ember-jsonapi-resources/models/resource'; | ||
| export default Resource.extend({ | ||
| type: 'post', | ||
| type: 'posts', | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistency. | ||
| service: Ember.inject.service('posts'), | ||
| title: attr('string'), | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import EmployeeResource from './person'; | ||
| import { hasMany } from 'ember-jsonapi-resources/models/resource'; | ||
| export default EmployeeResource.extend({ | ||
| type: 'supervisors', | ||
| directReports: hasMany('employees') | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,6 +22,7 @@ module.exports = function(environment) { | ||
| API_PATH: 'api/v1', | ||
| }, | ||
| contentSecurityPolicy: { | ||
| 'script-src': "'self' 'unsafe-inline' 'unsafe-eval' localhost:49152", | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allows the inline | ||
| 'connect-src': "'self' api.pixelhandler.com localhost:3000 0.0.0.0:3000", | ||
| 'img-src': "'self' www.gravatar.com" | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good :)