Skip to content
Extraits de code Groupes Projets
Valider f9996249 rédigé par Steffen van Bergerem's avatar Steffen van Bergerem Validation de Benjamin Neff
Parcourir les fichiers

Use error message from the server when comment failed

parent 82e78d3c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -95,8 +95,8 @@ app.models.Post.Interactions = Backbone.Model.extend({
var self = this;
options = options || {};
this.comments.make(text).fail(function () {
app.flashMessages.error(Diaspora.I18n.t("failed_to_comment"));
this.comments.make(text).fail(function(response) {
app.flashMessages.handleAjaxError(response);
if (options.error) { options.error(); }
}).done(function() {
self.post.set({participation: true});
......
......@@ -12,11 +12,17 @@ class CommentsController < ApplicationController
end
def create
comment = comment_service.create(params[:post_id], params[:text])
begin
comment = comment_service.create(params[:post_id], params[:text])
rescue ActiveRecord::RecordNotFound
render text: I18n.t("javascripts.failed_to_comment"), status: 404
return
end
if comment
respond_create_success(comment)
else
render nothing: true, status: 404
render text: I18n.t("javascripts.failed_to_comment"), status: 422
end
end
......
......@@ -67,6 +67,7 @@ describe CommentsController, :type => :controller do
expect(alice).not_to receive(:comment)
post :create, comment_hash
expect(response.code).to eq("404")
expect(response.body).to eq(I18n.t("javascripts.failed_to_comment"))
end
end
......
......@@ -286,6 +286,16 @@ describe("app.models.Post.Interactions", function(){
jasmine.Ajax.requests.mostRecent().respondWith({status: 400});
expect(error).toHaveBeenCalled();
});
it("displays a flash message", function() {
spyOn(app.flashMessages, "handleAjaxError").and.callThrough();
this.interactions.comment("text");
jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "error message"});
expect(app.flashMessages.handleAjaxError).toHaveBeenCalled();
expect(app.flashMessages.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("error message");
expect(spec.content().find(".flash-message")).toBeErrorFlashMessage("error message");
});
});
});
});
......@@ -116,9 +116,6 @@ describe("app.views.CommentStream", function(){
it("doesn't add the comment to the view", function() {
this.request.respondWith({status: 500});
expect(this.view.$(".comment-content p").text()).not.toEqual("a new comment");
expect(this.view.$(".flash-message")).toBeErrorFlashMessage(
"Failed to comment. Maybe the author is ignoring you?"
);
});
it("doesn't reset the comment box value", function() {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter