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:
parent
571784ba3f
commit
3d7e593c96
3 changed files with 11 additions and 12 deletions
|
@ -19,11 +19,9 @@ export default Model.extend({
|
||||||
ghostPaths: service(),
|
ghostPaths: service(),
|
||||||
|
|
||||||
resend() {
|
resend() {
|
||||||
let fullInviteData = this.toJSON();
|
|
||||||
|
|
||||||
let inviteData = {
|
let inviteData = {
|
||||||
email: fullInviteData.email,
|
email: this.email,
|
||||||
role_id: fullInviteData.role
|
role_id: this.belongsTo('role').id
|
||||||
};
|
};
|
||||||
|
|
||||||
let inviteUrl = this.get('ghostPaths.url').api('invites');
|
let inviteUrl = this.get('ghostPaths.url').api('invites');
|
||||||
|
|
|
@ -42,7 +42,7 @@ export default Service.extend({
|
||||||
|
|
||||||
handleNotification(message, delayed) {
|
handleNotification(message, delayed) {
|
||||||
// If this is an alert message from the server, treat it as html safe
|
// 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')));
|
message.set('message', htmlSafe(message.get('message')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ export default Service.extend({
|
||||||
closeNotification(notification) {
|
closeNotification(notification) {
|
||||||
let content = this.content;
|
let content = this.content;
|
||||||
|
|
||||||
if (typeof notification.toJSON === 'function') {
|
if (notification.constructor.modelName === 'notification') {
|
||||||
notification.deleteRecord();
|
notification.deleteRecord();
|
||||||
notification.save().finally(() => {
|
notification.save().finally(() => {
|
||||||
content.removeObject(notification);
|
content.removeObject(notification);
|
||||||
|
|
|
@ -9,6 +9,11 @@ import {get} from '@ember/object';
|
||||||
import {run} from '@ember/runloop';
|
import {run} from '@ember/runloop';
|
||||||
import {setupTest} from 'ember-mocha';
|
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 () {
|
describe('Unit: Service: notifications', function () {
|
||||||
setupTest();
|
setupTest();
|
||||||
|
|
||||||
|
@ -35,9 +40,7 @@ describe('Unit: Service: notifications', function () {
|
||||||
|
|
||||||
it('#handleNotification deals with DS.Notification notifications', function () {
|
it('#handleNotification deals with DS.Notification notifications', function () {
|
||||||
let notifications = this.owner.lookup('service:notifications');
|
let notifications = this.owner.lookup('service:notifications');
|
||||||
let notification = EmberObject.create({message: '<h1>Test</h1>', status: 'alert'});
|
let notification = NotificationStub.create({message: '<h1>Test</h1>', status: 'alert'});
|
||||||
|
|
||||||
notification.toJSON = function () {};
|
|
||||||
|
|
||||||
notifications.handleNotification(notification);
|
notifications.handleNotification(notification);
|
||||||
|
|
||||||
|
@ -315,10 +318,9 @@ describe('Unit: Service: notifications', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#closeNotification removes and deletes DS.Notification records', 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 notifications = this.owner.lookup('service:notifications');
|
||||||
|
let notification = NotificationStub.create({message: 'Close test', status: 'alert'});
|
||||||
|
|
||||||
notification.toJSON = function () {};
|
|
||||||
notification.deleteRecord = function () {};
|
notification.deleteRecord = function () {};
|
||||||
sinon.spy(notification, 'deleteRecord');
|
sinon.spy(notification, 'deleteRecord');
|
||||||
notification.save = function () {
|
notification.save = function () {
|
||||||
|
@ -392,7 +394,6 @@ describe('Unit: Service: notifications', function () {
|
||||||
let notifications = this.owner.lookup('service:notifications');
|
let notifications = this.owner.lookup('service:notifications');
|
||||||
let notificationModel = EmberObject.create({message: 'model'});
|
let notificationModel = EmberObject.create({message: 'model'});
|
||||||
|
|
||||||
notificationModel.toJSON = function () {};
|
|
||||||
notificationModel.deleteRecord = function () {};
|
notificationModel.deleteRecord = function () {};
|
||||||
sinon.spy(notificationModel, 'deleteRecord');
|
sinon.spy(notificationModel, 'deleteRecord');
|
||||||
notificationModel.save = function () {
|
notificationModel.save = function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue