diff --git a/features/comment.feature b/features/comment.feature index 3862d76..10f0724 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -84,3 +84,10 @@ Feature: comment When I press "Post comment" Then the "Title" field should contain "Joey Ramone" And I should see "Body can't be blank" + + @selenium + Scenario: wrong comment doesn't increment comment counter + Given I am on /booking/article-with-comment + And I follow "Post a comment" + When I press "Post comment" + And I should see "2 comments" diff --git a/public/javascripts/comment_form.js b/public/javascripts/comment_form.js index b5e0c9c..2b63562 100644 --- a/public/javascripts/comment_form.js +++ b/public/javascripts/comment_form.js @@ -54,6 +54,7 @@ function save_comment(button) { $('#'+ data.render_target).replaceWith(data.html); $('#' + data.render_target).effect("highlight", {}, 3000); $.colorbox.close(); + update_comment_count(); } else { //New comment of article comment_div.find('.article-comments-list').append(data.html); @@ -64,13 +65,9 @@ function save_comment(button) { page_comment_form.find('.errorExplanation').remove(); $.colorbox.close(); + update_comment_count(); } - comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { - var count = parseInt($(this).html()); - update_comment_count($(this), count + 1); - }); - if(jQuery('#recaptcha_response_field').val()){ Recaptcha.reload(); } @@ -86,6 +83,14 @@ function save_comment(button) { }, 'json'); } +function update_comment_count() { + comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { + var count = parseInt($(this).html()); + update_comment_count($(this), count + 1); + }); + +} + function show_display_comment_button() { if(jQuery('.post_comment_box.opened').length==0) jQuery('.display-comment-form').show(); -- libgit2 0.21.2