Commit 2f568c12b69978d5609bdcbfd7bd4ff98f2f51f7

Authored by Braulio Bhavamitra
1 parent 5d783a7e

rails4: port comments on action_tracker

test/unit/comment_test.rb
@@ -294,6 +294,7 @@ class CommentTest < ActiveSupport::TestCase @@ -294,6 +294,7 @@ class CommentTest < ActiveSupport::TestCase
294 c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) 294 c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)
295 c4 = Comment.create!(:source => a, :body => 'My comment', :author => person) 295 c4 = Comment.create!(:source => a, :body => 'My comment', :author => person)
296 result = a.activity.comments 296 result = a.activity.comments
  297 + assert result.present?
297 assert_equal c0, result[0] 298 assert_equal c0, result[0]
298 assert_equal [c1, c3], result[0].replies 299 assert_equal [c1, c3], result[0].replies
299 assert_equal [c2], result[0].replies[0].replies 300 assert_equal [c2], result[0].replies[0].replies
vendor/plugins/action_tracker_has_comments/init.rb
@@ -3,15 +3,11 @@ @@ -3,15 +3,11 @@
3 Rails.configuration.to_prepare do 3 Rails.configuration.to_prepare do
4 ActionTracker::Record.module_eval do 4 ActionTracker::Record.module_eval do
5 5
6 - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy  
7 - #FIXME rails 4.1 removes finder_sql  
8 - #:finder_sql => Proc.new { %Q{SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC}},  
9 - #:counter_sql => Proc.new { %Q{SELECT COUNT(*) FROM comments WHERE #{conditions_for_comments}} }  
10 -  
11 - def conditions_for_comments  
12 - type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id])  
13 - "source_type = '#{type}' AND source_id = '#{id}' AND spam IS NOT TRUE AND reply_of_id IS NULL" 6 + def comments
  7 + type, id = if self.target_type == 'Article' then ['Article', self.target_id] else [self.class.to_s, self.id] end
  8 + Comment.order('created_at ASC').
  9 + where('comments.spam IS NOT TRUE AND comments.reply_of_id IS NULL').
  10 + where('source_type = ? AND source_id = ?', type, id)
14 end 11 end
15 -  
16 end 12 end
17 end 13 end