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

Ensure validation errors are shown on post save #136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/mixins/editor-base-controller.js
Expand Up @@ -7,6 +7,7 @@ import injectController from 'ember-controller/inject';
import {htmlSafe} from 'ember-string';
import observer from 'ember-metal/observer';
import run from 'ember-runloop';
import {isEmberArray} from 'ember-array/utils';

import PostModel from 'ghost-admin/models/post';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
Expand Down Expand Up @@ -309,6 +310,10 @@ export default Mixin.create({

if (error && isString(error)) {
errorMessage = error;
} else if (error && isEmberArray(error)) {
// This is here because validation errors are returned as an array
// TODO: remove this once validations are fixed
errorMessage = error[0];
} else if (error && error.errors && error.errors[0].message) {
errorMessage = error.errors[0].message;
} else {
Expand Down
29 changes: 29 additions & 0 deletions tests/acceptance/editor-test.js
Expand Up @@ -391,6 +391,35 @@ describe('Acceptance: Editor', function() {
});
});

it('handles title validation errors correctly', function () {
let post = server.createList('post', 1);

// post id 1 is a draft, checking for draft behaviour now
visit('/editor/1');

andThen(() => {
expect(currentURL(), 'currentURL')
.to.equal('/editor/1');
});

// Test title validation
fillIn('input[id="entry-title"]', Array(160).join('a'));
triggerEvent('input[id="entry-title"]', 'blur');
click('.view-header .btn.btn-sm.js-publish-button');

andThen(() => {
expect(
find('.gh-alert').length,
'number of alerts after invalid title'
).to.equal(1);

expect(
find('.gh-alert').text(),
'alert text after invalid title'
).to.match(/Title cannot be longer than 150 characters/);
});
});

it('renders first countdown notification before scheduled time', function () {
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
let clock = sinon.useFakeTimers(moment().valueOf());
Expand Down