From 4ba4ceaf2b57ffbe82a6cd57ae946db9f5d886fb Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Wed, 29 Aug 2012 13:28:49 -0300 Subject: [PATCH] Filter out activities echos from wall --- app/models/community.rb | 2 +- app/models/person.rb | 2 +- test/functional/profile_controller_test.rb | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/community.rb b/app/models/community.rb index 58d16b3..36b0564 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -88,7 +88,7 @@ class Community < Organization end def activities - Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.target_id = #{self.id} UNION SELECT at.id, at.updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} at INNER JOIN articles a ON at.target_id = a.id WHERE a.profile_id = #{self.id} AND at.target_type = 'Article' ORDER BY updated_at DESC") + Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.target_id = #{self.id} and action_tracker.verb != 'join_community' and action_tracker.verb != 'leave_scrap' UNION SELECT at.id, at.updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} at INNER JOIN articles a ON at.target_id = a.id WHERE a.profile_id = #{self.id} AND at.target_type = 'Article' ORDER BY updated_at DESC") end end diff --git a/app/models/person.rb b/app/models/person.rb index bbba1fb..5138fcb 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -443,7 +443,7 @@ class Person < Profile end def activities - Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} ORDER BY updated_at DESC") + Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' ORDER BY updated_at DESC") end protected diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 46fd7df..74a635a 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1139,8 +1139,10 @@ class ProfileControllerTest < ActionController::TestCase should "view more activities paginated" do login_as(profile.identifier) - 40.times{ fast_create(ActionTracker::Record, :user_id => profile.id)} + article = TinyMceArticle.create!(:profile => profile, :name => 'An Article about Free Software') + 40.times{ ActionTracker::Record.create!(:user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image})} assert_equal 40, profile.tracked_actions.count + assert_equal 40, profile.activities.count get :view_more_activities, :profile => profile.identifier, :page => 2 assert_response :success assert_template '_profile_activities_list' -- libgit2 0.21.2