From 3f3409a0a5235d18e1359676bb056173711c2a9d Mon Sep 17 00:00:00 2001 From: pestrada Date: Sun, 24 Feb 2013 21:01:29 -0600 Subject: [PATCH] avoid posting empty comments fix Jasmine test updated changelog with bugfix #3836 fix changelog update remove wrong bug fix line --- Changelog.md | 6 +++++- .../app/views/comment_stream_view.js | 12 ++++++++--- .../app/views/comment_stream_view_spec.js | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 9a901cc7e..dde16f14e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Head +## Bug fixes + +* avoid posting empty comments. [#3836](https://github.com/diaspora/diaspora/issues/3836) + ## Refactor * Refactor people_controller#show and photos_controller#index [#4002](https://github.com/diaspora/diaspora/issues/4002) @@ -57,7 +61,7 @@ * Stream form on profile page [#3910](https://github.com/diaspora/diaspora/issues/3910). * Add Getting_Started page mobile. [#3949](https://github.com/diaspora/diaspora/issues/3949). * Autoscroll to the first unread message in conversations. [#3216](https://github.com/diaspora/diaspora/issues/3216) -* Friendlier new-conversation mobile. [#3984](https://github.com/diaspora/diaspora/issues/3984) +* Friendlier new-conversation mobile. [#3984](https://github.com/diaspora/diaspora/issues/3984) ## Bug Fixes diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index b5fd41572..24d0ebfab 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -39,9 +39,15 @@ app.views.CommentStream = app.views.Base.extend({ createComment: function(evt) { if(evt){ evt.preventDefault(); } - this.model.comment(this.$(".comment_box").val()) - this.$(".comment_box").val("") - return this; + + var commentText = $.trim(this.$('.comment_box').val()); + if(commentText) { + this.model.comment(commentText); + this.$(".comment_box").val(""); + return this; + } else { + this.$(".comment_box").val("").focus(); + } }, appendComment: function(comment) { diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index 465b32e23..a84cbdb81 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -28,6 +28,26 @@ describe("app.views.CommentStream", function(){ expect($.fn.autoResize.mostRecentCall.object.selector).toBe("textarea") }) }) + + describe("createComment", function() { + beforeEach(function() { + jasmine.Ajax.useMock(); + this.view.render(); + this.view.expandComments(); + }) + + it("submits the new comment when comment text is not empty", function() { + this.view.$(".comment_box").val('a new comment'); + this.view.createComment(); + expect(this.view.$(".comment-content p").text()).toEqual("a new comment"); + }) + + it("clears the comment box when there are only spaces", function() { + this.view.$(".comment_box").val(' '); + this.view.createComment(); + expect(this.view.$(".comment_box").val()).toEqual(""); + }) + }) describe("appendComment", function(){ it("appends this.model as 'parent' to the comment", function(){