From 8de60dad8250038ca469045bd0c6a9ad51ec0384 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Fri, 12 Jul 2013 19:47:49 -0300 Subject: [PATCH] [comments-refactor-review] Refactoring and making tests for comment root --- app/models/comment.rb | 7 +------ test/unit/comment_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index d8461bb..ff2c2d8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -34,13 +34,8 @@ class Comment < ActiveRecord::Base xss_terminate :only => [ :body, :title, :name ], :on => 'validation' - #FIXME make this test def comment_root - if(self.reply_of.present?) - self.reply_of.comment_root - else - self - end + (reply_of && reply_of.comment_root) || self end def action_tracker_target diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index aac949f..531c428 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -690,6 +690,16 @@ class CommentTest < ActiveSupport::TestCase assert comment.can_be_updated_by?(user) end + should 'get comment root' do + c1 = Comment.new + c2 = Comment.new(:reply_of => c1) + c3 = Comment.new(:reply_of => c2) + + assert_equal c1, c3.comment_root + assert_equal c1, c2.comment_root + assert_equal c1, c1.comment_root + end + private def create_comment(args = {}) -- libgit2 0.21.2