diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index f845e52..589209d 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -285,35 +285,6 @@ class CommentTest < ActiveSupport::TestCase assert_equal [c1,c3], c.reload.children end - should "return activities comments as a thread" do - person = fast_create(Person) - a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') - c0 = Comment.create!(:source => a, :body => 'My comment', :author => person) - c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) - c2 = Comment.create!(:reply_of_id => c1.id, :source => a, :body => 'bla', :author => person) - c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) - c4 = Comment.create!(:source => a, :body => 'My comment', :author => person) - result = a.activity.comments_as_thread - assert_equal c0, result[0] - assert_equal [c1, c3], result[0].replies - assert_equal [c2], result[0].replies[0].replies - assert_equal c4, result[1] - assert result[1].replies.empty? - end - - should "return activities comments when some comment on thread is spam" do - person = fast_create(Person) - a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') - c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) - c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) - spam = Comment.create(:spam => true, :reply_of_id => c0.id, :source => a, :body => 'spam', :author => person) - c2 = Comment.create(:reply_of_id => spam.id, :source => a, :body => 'c2', :author => person) - result = a.activity.comments_as_thread - assert_equal c0, result[0] - assert_equal [c1], result[0].replies - assert_equal c2, result[1] - end - should 'provide author url for authenticated user' do author = Person.new author.expects(:url).returns('http://blabla.net/author') diff --git a/vendor/plugins/action_tracker_has_comments/init.rb b/vendor/plugins/action_tracker_has_comments/init.rb index e20e511..fe1d533 100644 --- a/vendor/plugins/action_tracker_has_comments/init.rb +++ b/vendor/plugins/action_tracker_has_comments/init.rb @@ -11,23 +11,5 @@ Rails.configuration.to_prepare do type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) "source_type = '#{type}' AND source_id = '#{id}' AND spam IS NOT TRUE AND reply_of_id IS NULL" end - - def comments_as_thread - result = {} - root = [] - self.comments.each do |c| - c.replies = [] - result[c.id] ||= c - if c.reply_of_id.nil? - root << c - elsif result[c.reply_of_id] - result[c.reply_of_id].replies << c - else # Comment is a reply but the reply is not being displayed - is spam, for example - root << c - end - end - root - end - end end -- libgit2 0.21.2