0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Fixed Ember Data record.toJSON() deprecation

no issue

- https://deprecations.emberjs.com/ember-data/v3.x/#toc_record-toJSON
This commit is contained in:
Kevin Ansfield 2020-01-07 13:23:15 +00:00
parent 571784ba3f
commit 3d7e593c96
3 changed files with 11 additions and 12 deletions

View file

@ -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');

View file

@ -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')));
}
@ -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);

View file

@ -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();
@ -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);
@ -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 () {
@ -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 () {