Commit 8de60dad8250038ca469045bd0c6a9ad51ec0384

Authored by Rodrigo Souto
1 parent b118aa79

[comments-refactor-review] Refactoring and making tests for comment root

app/models/comment.rb
... ... @@ -34,13 +34,8 @@ class Comment < ActiveRecord::Base
34 34  
35 35 xss_terminate :only => [ :body, :title, :name ], :on => 'validation'
36 36  
37   - #FIXME make this test
38 37 def comment_root
39   - if(self.reply_of.present?)
40   - self.reply_of.comment_root
41   - else
42   - self
43   - end
  38 + (reply_of && reply_of.comment_root) || self
44 39 end
45 40  
46 41 def action_tracker_target
... ...
test/unit/comment_test.rb
... ... @@ -690,6 +690,16 @@ class CommentTest < ActiveSupport::TestCase
690 690 assert comment.can_be_updated_by?(user)
691 691 end
692 692  
  693 + should 'get comment root' do
  694 + c1 = Comment.new
  695 + c2 = Comment.new(:reply_of => c1)
  696 + c3 = Comment.new(:reply_of => c2)
  697 +
  698 + assert_equal c1, c3.comment_root
  699 + assert_equal c1, c2.comment_root
  700 + assert_equal c1, c1.comment_root
  701 + end
  702 +
693 703 private
694 704  
695 705 def create_comment(args = {})
... ...