Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Fixed Ember Data record.toJSON() deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinansfield committed Jan 7, 2020
1 parent 4e4ff8b commit af4bd52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 2 additions & 4 deletions app/models/invite.js
Expand Up @@ -19,11 +19,9 @@ export default Model.extend({
ghostPaths: service(),

resend() {
let fullInviteData = this.toJSON();

let inviteData = {
email: fullInviteData.email,
role_id: fullInviteData.role
email: this.email,
role_id: this.belongsTo('role').id
};

let inviteUrl = this.get('ghostPaths.url').api('invites');
Expand Down
4 changes: 2 additions & 2 deletions app/services/notifications.js
Expand Up @@ -42,7 +42,7 @@ export default Service.extend({

handleNotification(message, delayed) {
// If this is an alert message from the server, treat it as html safe
if (typeof message.toJSON === 'function' && message.get('status') === 'alert') {
if (message.constructor.modelName === 'notification' && message.get('status') === 'alert') {
message.set('message', htmlSafe(message.get('message')));
}

Expand Down Expand Up @@ -155,7 +155,7 @@ export default Service.extend({
closeNotification(notification) {
let content = this.content;

if (typeof notification.toJSON === 'function') {
if (notification.constructor.modelName === 'notification') {
notification.deleteRecord();
notification.save().finally(() => {
content.removeObject(notification);
Expand Down
13 changes: 7 additions & 6 deletions tests/unit/services/notifications-test.js
Expand Up @@ -9,6 +9,11 @@ import {get} from '@ember/object';
import {run} from '@ember/runloop';
import {setupTest} from 'ember-mocha';

// notifications service determines if a notification is a model instance by
// checking `notification.constructor.modelName === 'notification'`
const NotificationStub = EmberObject.extend();
NotificationStub.modelName = 'notification';

describe('Unit: Service: notifications', function () {
setupTest();

Expand All @@ -35,9 +40,7 @@ describe('Unit: Service: notifications', function () {

it('#handleNotification deals with DS.Notification notifications', function () {
let notifications = this.owner.lookup('service:notifications');
let notification = EmberObject.create({message: '<h1>Test</h1>', status: 'alert'});

notification.toJSON = function () {};
let notification = NotificationStub.create({message: '<h1>Test</h1>', status: 'alert'});

notifications.handleNotification(notification);

Expand Down Expand Up @@ -315,10 +318,9 @@ describe('Unit: Service: notifications', function () {
});

it('#closeNotification removes and deletes DS.Notification records', function () {
let notification = EmberObject.create({message: 'Close test', status: 'alert'});
let notifications = this.owner.lookup('service:notifications');
let notification = NotificationStub.create({message: 'Close test', status: 'alert'});

notification.toJSON = function () {};
notification.deleteRecord = function () {};
sinon.spy(notification, 'deleteRecord');
notification.save = function () {
Expand Down Expand Up @@ -392,7 +394,6 @@ describe('Unit: Service: notifications', function () {
let notifications = this.owner.lookup('service:notifications');
let notificationModel = EmberObject.create({message: 'model'});

notificationModel.toJSON = function () {};
notificationModel.deleteRecord = function () {};
sinon.spy(notificationModel, 'deleteRecord');
notificationModel.save = function () {
Expand Down

0 comments on commit af4bd52

Please sign in to comment.