Commit 1b2a4981c1bb1a93ba67bcd03e477a95a9cc8d75

Authored by Leandro Nunes dos Santos
Committed by Rodrigo Souto
1 parent f3047975

comment counter should not update is somenthing wrong happens with comment creation

features/comment.feature
@@ -84,3 +84,10 @@ Feature: comment @@ -84,3 +84,10 @@ Feature: comment
84 When I press "Post comment" 84 When I press "Post comment"
85 Then the "Title" field should contain "Joey Ramone" 85 Then the "Title" field should contain "Joey Ramone"
86 And I should see "Body can't be blank" 86 And I should see "Body can't be blank"
  87 +
  88 + @selenium
  89 + Scenario: wrong comment doesn't increment comment counter
  90 + Given I am on /booking/article-with-comment
  91 + And I follow "Post a comment"
  92 + When I press "Post comment"
  93 + And I should see "2 comments"
public/javascripts/comment_form.js
@@ -54,6 +54,7 @@ function save_comment(button) { @@ -54,6 +54,7 @@ function save_comment(button) {
54 $('#'+ data.render_target).replaceWith(data.html); 54 $('#'+ data.render_target).replaceWith(data.html);
55 $('#' + data.render_target).effect("highlight", {}, 3000); 55 $('#' + data.render_target).effect("highlight", {}, 3000);
56 $.colorbox.close(); 56 $.colorbox.close();
  57 + update_comment_count();
57 } else { 58 } else {
58 //New comment of article 59 //New comment of article
59 comment_div.find('.article-comments-list').append(data.html); 60 comment_div.find('.article-comments-list').append(data.html);
@@ -64,13 +65,9 @@ function save_comment(button) { @@ -64,13 +65,9 @@ function save_comment(button) {
64 65
65 page_comment_form.find('.errorExplanation').remove(); 66 page_comment_form.find('.errorExplanation').remove();
66 $.colorbox.close(); 67 $.colorbox.close();
  68 + update_comment_count();
67 } 69 }
68 70
69 - comment_div.find('.comment-count').add('#article-header .comment-count').each(function() {  
70 - var count = parseInt($(this).html());  
71 - update_comment_count($(this), count + 1);  
72 - });  
73 -  
74 if(jQuery('#recaptcha_response_field').val()){ 71 if(jQuery('#recaptcha_response_field').val()){
75 Recaptcha.reload(); 72 Recaptcha.reload();
76 } 73 }
@@ -86,6 +83,14 @@ function save_comment(button) { @@ -86,6 +83,14 @@ function save_comment(button) {
86 }, 'json'); 83 }, 'json');
87 } 84 }
88 85
  86 +function update_comment_count() {
  87 + comment_div.find('.comment-count').add('#article-header .comment-count').each(function() {
  88 + var count = parseInt($(this).html());
  89 + update_comment_count($(this), count + 1);
  90 + });
  91 +
  92 +}
  93 +
89 function show_display_comment_button() { 94 function show_display_comment_button() {
90 if(jQuery('.post_comment_box.opened').length==0) 95 if(jQuery('.post_comment_box.opened').length==0)
91 jQuery('.display-comment-form').show(); 96 jQuery('.display-comment-form').show();