diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 802045a..c9e4de5 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -294,6 +294,7 @@ class CommentTest < ActiveSupport::TestCase 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 + assert result.present? assert_equal c0, result[0] assert_equal [c1, c3], result[0].replies assert_equal [c2], result[0].replies[0].replies diff --git a/vendor/plugins/action_tracker_has_comments/init.rb b/vendor/plugins/action_tracker_has_comments/init.rb index 4976123..c072cd1 100644 --- a/vendor/plugins/action_tracker_has_comments/init.rb +++ b/vendor/plugins/action_tracker_has_comments/init.rb @@ -3,15 +3,11 @@ Rails.configuration.to_prepare do ActionTracker::Record.module_eval do - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy - #FIXME rails 4.1 removes finder_sql - #:finder_sql => Proc.new { %Q{SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC}}, - #:counter_sql => Proc.new { %Q{SELECT COUNT(*) FROM comments WHERE #{conditions_for_comments}} } - - def conditions_for_comments - 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" + def comments + type, id = if self.target_type == 'Article' then ['Article', self.target_id] else [self.class.to_s, self.id] end + Comment.order('created_at ASC'). + where('comments.spam IS NOT TRUE AND comments.reply_of_id IS NULL'). + where('source_type = ? AND source_id = ?', type, id) end - end end -- libgit2 0.21.2