diff --git a/assets/js/src/newsletter_editor/components/content.js b/assets/js/src/newsletter_editor/components/content.js index a884491f3f..aeb168c312 100644 --- a/assets/js/src/newsletter_editor/components/content.js +++ b/assets/js/src/newsletter_editor/components/content.js @@ -11,7 +11,7 @@ define([ // Does not hold newsletter content nor newsletter styles, those are // handled by other components. Module.NewsletterModel = SuperModel.extend({ - stale: ['body', 'created_at', 'deleted_at', 'updated_at'], + whitelisted: ['id', 'subject', 'preheader'], initialize: function(options) { this.on('change', function() { App.getChannel().trigger('autoSave'); @@ -19,7 +19,7 @@ define([ }, toJSON: function() { // Remove stale attributes from resulting JSON object - return _.omit(SuperModel.prototype.toJSON.call(this), this.stale); + return _.pick(SuperModel.prototype.toJSON.call(this), this.whitelisted); }, }); diff --git a/tests/javascript/newsletter_editor/components/content.spec.js b/tests/javascript/newsletter_editor/components/content.spec.js index 1bd1856794..80cd6da66a 100644 --- a/tests/javascript/newsletter_editor/components/content.spec.js +++ b/tests/javascript/newsletter_editor/components/content.spec.js @@ -19,7 +19,7 @@ define([ data2: 'data2Value', }, }, - someField: 'someValue' + subject: 'my test subject' }); }); @@ -28,13 +28,32 @@ define([ global.stubChannel(EditorApplication, { trigger: mock, }); - model.set('someField', 'anotherValue'); + model.set('subject', 'another test subject'); mock.verify(); }); - it('does not include styles and content attributes in its JSON', function() { + it('does not include styles and content properties in its JSON', function() { var json = model.toJSON(); - expect(json).to.deep.equal({someField: 'someValue'}); + expect(json).to.deep.equal({subject: 'my test subject'}); + }); + + describe('toJSON()', function() { + it('will only contain properties modifyable by the editor', function() { + var model = new (ContentComponent.NewsletterModel)({ + id: 19, + subject: 'some subject', + preheader: 'some preheader', + segments: [1, 2, 3], + modified_at: '2000-01-01 12:01:02', + someField: 'someValue' + }); + + var json = model.toJSON(); + expect(json.id).to.equal(19); + expect(json.subject).to.equal('some subject'); + expect(json.preheader).to.equal('some preheader'); + expect(json).to.not.include.keys('segments', 'modified_at', 'someField'); + }) }); });