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

New posts pass PostsController sorting function at the top

- PostsController orderBy function sorts posts with isNew to the top, otherwise their undefined dates fail to compare
- also catch when `updated_at` is undefined, happens when model is being written with results from the server
- catch objects of type Error in validation engine, helps catching client errors
- join server errors with BR tag in ajax util
- add `emberBuild` task to `grunt test-functional`
- add a test helper, `thenTransitionAndWaitForScreenLoad`, to test transitioning to major parts of the app
- add a test that transitions from Content to the Editor, and back to Content
This commit is contained in:
David Arvelo 2014-06-27 23:50:31 -04:00
parent 47eb354a7b
commit 9f9749d123
3 changed files with 23 additions and 5 deletions

View file

@ -15,7 +15,6 @@ var PostsController = Ember.ArrayController.extend({
// published_at: DESC // published_at: DESC
// updated_at: DESC // updated_at: DESC
orderBy: function (item1, item2) { orderBy: function (item1, item2) {
function publishedAtCompare() { function publishedAtCompare() {
var published1 = item1.get('published_at'), var published1 = item1.get('published_at'),
published2 = item2.get('published_at'); published2 = item2.get('published_at');
@ -35,9 +34,25 @@ var PostsController = Ember.ArrayController.extend({
return Ember.compare(item1.get('published_at').valueOf(), item2.get('published_at').valueOf()); return Ember.compare(item1.get('published_at').valueOf(), item2.get('published_at').valueOf());
} }
var statusResult = Ember.compare(item1.get('status'), item2.get('status')), var updated1 = item1.get('updated_at'),
updatedAtResult = Ember.compare(item1.get('updated_at').valueOf(), item2.get('updated_at').valueOf()), updated2 = item2.get('updated_at'),
publishedAtResult = publishedAtCompare(); statusResult,
updatedAtResult,
publishedAtResult;
// when `updated_at` is undefined, the model is still
// being written to with the results from the server
if (item1.get('isNew') || !updated1) {
return -1;
}
if (item2.get('isNew') || !updated2) {
return 1;
}
statusResult = Ember.compare(item1.get('status'), item2.get('status'));
updatedAtResult = Ember.compare(updated1.valueOf(), updated2.valueOf());
publishedAtResult = publishedAtCompare();
if (statusResult === 0) { if (statusResult === 0) {
if (publishedAtResult === 0) { if (publishedAtResult === 0) {

View file

@ -54,6 +54,9 @@ var ValidationEngine = Ember.Mixin.create({
if (Ember.isArray(errors)) { if (Ember.isArray(errors)) {
// get validation error messages // get validation error messages
message = errors.mapBy('message').join('<br />'); message = errors.mapBy('message').join('<br />');
} else if (errors instanceof Error) {
// we got some kind of error in Ember
message += ': ' + errors.message;
} else if (typeof errors === 'object') { } else if (typeof errors === 'object') {
// Get messages from server response // Get messages from server response
message += ': ' + getRequestErrorMessage(errors); message += ': ' + getRequestErrorMessage(errors);

View file

@ -26,7 +26,7 @@ var getRequestErrorMessage = function (request) {
message = request.responseJSON.errors.map(function (errorItem) { message = request.responseJSON.errors.map(function (errorItem) {
return errorItem.message; return errorItem.message;
}).join('; '); }).join('<br />');
} else { } else {
message = request.responseJSON.error || 'Unknown Error'; message = request.responseJSON.error || 'Unknown Error';
} }