]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2449 'updated_at' attribute of a review is not always updated
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 20 May 2011 08:28:23 +0000 (10:28 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Fri, 20 May 2011 08:30:25 +0000 (10:30 +0200)
It was not updated when a comment is added, edited or deleted.
Now it is the case.

sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb

index 48bcf107ba74f7a627f47fb34b8d5072b481d709..7097953cba0cf92de2e9965f2e7e29947bec0685 100644 (file)
@@ -97,15 +97,11 @@ class ReviewsController < ApplicationController
     end
 
     if params[:comment_id]
-      comment = @review.comments.find(params[:comment_id].to_i)
-      if comment
-        comment.text=params[:text]
-        comment.save!
-      end
+      @review.edit_comment(params[:comment_id].to_i, params[:text])
     else
-      @review.comments.create!(:user => current_user, :text => params[:text])
+      @review.create_comment(:user => current_user, :text => params[:text])
     end
-
+    
     render :partial => "reviews/view"
   end
 
@@ -146,8 +142,7 @@ class ReviewsController < ApplicationController
     end
     
     if @review
-      comment=@review.comments.find(params[:comment_id].to_i)
-      comment.delete if comment
+      @review.delete_comment(params[:comment_id].to_i)
     end
     render :partial => "reviews/view"
   end
@@ -245,13 +240,9 @@ class ReviewsController < ApplicationController
     end
 
     if params[:comment_id]
-      comment=violation.review.comments.find(params[:comment_id].to_i)
-      if comment
-        comment.text=params[:text]
-        comment.save!
-      end
+      violation.review.edit_comment(params[:comment_id].to_i, params[:text])
     else
-      violation.review.comments.create!(:user => current_user, :text => params[:text])
+      violation.review.create_comment(:user => current_user, :text => params[:text])
     end
 
     render :partial => "resource/violation", :locals => { :violation => violation }
@@ -266,8 +257,7 @@ class ReviewsController < ApplicationController
     end
     sanitize_violation(violation)
     if violation.review
-      comment=violation.review.comments.find(params[:comment_id].to_i)
-      comment.delete if comment
+      violation.review.delete_comment(params[:comment_id].to_i)
     end
     render :partial => "resource/violation", :locals => { :violation => violation }
   end
index 3fe1de33f866ff1e39cebb0dfddff7db7dd13656..55d7dce4efe12c7ad767213d2dbddcbec3e302a1 100644 (file)
@@ -49,6 +49,28 @@ class Review < ActiveRecord::Base
       end
   end
 
+  def create_comment(options={})
+    comments.create!(options)
+    touch
+  end
+
+  def edit_comment(comment_id, comment_text)
+    comment=comments.find(comment_id)
+    if comment
+      comment.text=comment_text
+      comment.save!
+      touch
+    end
+  end
+  
+  def delete_comment(comment_id)
+    comment=comments.find(comment_id)
+    if comment
+      comment.delete
+      touch
+    end
+  end
+  
   def self.search(options={})
     conditions=[]
     values={}