diff --git a/cms/static/coffee/spec/views/course_info_spec.coffee b/cms/static/coffee/spec/views/course_info_spec.coffee index 6e275ca2f7..af79984d40 100644 --- a/cms/static/coffee/spec/views/course_info_spec.coffee +++ b/cms/static/coffee/spec/views/course_info_spec.coffee @@ -232,6 +232,20 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model @handoutsEdit.render() + it "saves
    when content left empty", -> + requests = AjaxHelpers["requests"](this) + + # Enter empty string in the handouts section, verifying that the model + # is saved with '
      ' instead of the empty string + @handoutsEdit.$el.find('.edit-button').click() + spyOn(@handoutsEdit.$codeMirror, 'getValue').and.returnValue('') + spyOn(@model, "save").and.callThrough() + @handoutsEdit.$el.find('.save-button').click() + expect(@model.save).toHaveBeenCalled() + + contentSaved = JSON.parse(requests[requests.length - 1].requestBody).data + expect(contentSaved).toEqual('
        ') + it "does not rewrite links on save", -> requests = AjaxHelpers["requests"](this) diff --git a/cms/static/js/views/course_info_handout.js b/cms/static/js/views/course_info_handout.js index 2188312d10..5fe274311f 100644 --- a/cms/static/js/views/course_info_handout.js +++ b/cms/static/js/views/course_info_handout.js @@ -50,10 +50,14 @@ define(['js/views/baseview', 'codemirror', 'common/js/components/views/feedback_ }, onSave: function(event) { + var handoutsContent = this.$codeMirror.getValue(); $('#handout_error').removeClass('is-shown'); $('.save-button').removeClass('is-disabled').attr('aria-disabled', false); if ($('.CodeMirror-lines').find('.cm-error').length == 0) { - this.model.set('data', this.$codeMirror.getValue()); + if (handoutsContent === '') { + handoutsContent = '
          '; + } + this.model.set('data', handoutsContent); var saving = new NotificationView.Mini({ title: gettext('Saving') });