diff --git a/app/models/organization.rb b/app/models/organization.rb index e319d51..49b6666 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -27,6 +27,13 @@ class Organization < Profile :joins => "LEFT OUTER JOIN role_assignments ON profiles.id = role_assignments.resource_id", :order => "total DESC" + named_scope :more_active, + :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", + :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id", + :group => Profile.qualified_column_names, + :order => 'total DESC', + :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] + def validation_methodology self.validation_info ? self.validation_info.validation_methodology : nil end diff --git a/app/models/person.rb b/app/models/person.rb index 2668fb5..74a11e5 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -27,6 +27,13 @@ class Person < Profile :joins => "LEFT OUTER JOIN friendships on profiles.id = friendships.person_id", :order => "total DESC" + named_scope :more_active, + :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", + :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id", + :group => Profile.qualified_column_names, + :order => 'total DESC', + :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] + after_destroy do |person| Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } end diff --git a/app/models/profile.rb b/app/models/profile.rb index f166304..246f278 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -78,19 +78,11 @@ class Profile < ActiveRecord::Base end named_scope :visible, :conditions => { :visible => true } - # Subclasses must override this method + # Subclasses must override these methods named_scope :more_popular + named_scope :more_active + named_scope :more_recent, :order => "created_at DESC" - named_scope :more_active, lambda { - { - :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", - :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id" + - (self == Person ? '' : ' OR profiles.id = action_tracker.target_id'), - :group => Profile.qualified_column_names, - :order => 'total DESC', - :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] - } - } acts_as_trackable :dependent => :destroy @@ -792,9 +784,9 @@ private :generate_url, :url_options amount = recent_actions.count amount += recent_notifications.count if organization? { - 0 => _('no actions'), - 1 => _('one action') - }[amount] || _("%s actions") % amount + 0 => _('no activity'), + 1 => _('one activity') + }[amount] || _("%s activities") % amount end def more_popular_label diff --git a/test/functional/browse_controller_test.rb b/test/functional/browse_controller_test.rb index f796843..c66e802 100644 --- a/test/functional/browse_controller_test.rb +++ b/test/functional/browse_controller_test.rb @@ -201,13 +201,14 @@ class BrowseControllerTest < Test::Unit::TestCase should 'list all communities filter by more active' do + person = fast_create(Person) c1 = create(Community, :name => 'Testing community 1') c2 = create(Community, :name => 'Testing community 2') c3 = create(Community, :name => 'Testing community 3') ActionTracker::Record.delete_all - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => c1, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => c2, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => c2, :created_at => Time.now) + fast_create(ActionTracker::Record, :target_id => c1, :user_type => 'Profile', :user_id => person, :created_at => Time.now) + fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) + fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) get :communities, :filter => 'more_active' assert_equal [c2,c1,c3] , assigns(:results) end diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index f64f5c4..eb7f1a5 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -344,4 +344,46 @@ class OrganizationTest < Test::Unit::TestCase organization.add_member(person3) assert_equal "3 members", organization.more_popular_label end + + should 'find more active organizations' do + person = fast_create(Person) + Organization.destroy_all + p1 = fast_create(Organization) + p2 = fast_create(Organization) + p3 = fast_create(Organization) + + ActionTracker::Record.destroy_all + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p1.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p2.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p2.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p3.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p3.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p3.id) + + assert_equal [p3,p2,p1] , Organization.more_active + end + + should 'more active profile take in consideration only actions created only in the recent delay interval' do + ActionTracker::Record.destroy_all + recent_delay = ActionTracker::Record::RECENT_DELAY.days.ago + + person = fast_create(Person) + Organization.destroy_all + p1 = fast_create(Organization) + p2 = fast_create(Organization) + + ActionTracker::Record.destroy_all + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay, :target_id => p1.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay, :target_id => p1.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay, :target_id => p2.id) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay - 1.day, :target_id => p2.id) + + assert_equal [p1,p2] , Organization.more_active + end + + should 'list profiles that have no actions in more active list' do + profile = fast_create(Organization) + assert_includes Organization.more_active, profile + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 52e4677..c2d9e4e 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1145,4 +1145,42 @@ class PersonTest < Test::Unit::TestCase assert_equal [person], Person.members_of(community) end + should 'find more active people' do + Person.destroy_all + p1 = fast_create(Person) + p2 = fast_create(Person) + p3 = fast_create(Person) + + ActionTracker::Record.destroy_all + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) + + assert_equal [p3,p2,p1] , Person.more_active + end + + should 'more active profile take in consideration only actions created only in the recent delay interval' do + Person.delete_all + ActionTracker::Record.destroy_all + recent_delay = ActionTracker::Record::RECENT_DELAY.days.ago + + p1 = fast_create(Person) + p2 = fast_create(Person) + + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay) + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay - 1.day) + + assert_equal [p1,p2], Person.more_active + end + + should 'list profiles that have no actions in more active list' do + profile = fast_create(Person) + assert_includes Person.more_active, profile + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index a201857..e3a5f00 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1564,42 +1564,14 @@ class ProfileTest < Test::Unit::TestCase assert_equal [p2,p3,p4,p1] , Profile.more_recent end - should 'find more active profiles' do - Profile.destroy_all - p1 = fast_create(Profile) - p2 = fast_create(Profile) - p3 = fast_create(Profile) - - ActionTracker::Record.destroy_all - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) - - assert_equal [p3,p2,p1] , Profile.more_active - end - - should 'more active profile take in consideration only actions created only in the recent delay interval' do - Profile.delete_all - ActionTracker::Record.destroy_all - recent_delay = ActionTracker::Record::RECENT_DELAY.days.ago - - p1 = fast_create(Profile) - p2 = fast_create(Profile) - - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay) - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay - 1.day) - - assert_equal [p1,p2], Profile.more_active + should 'respond to more active' do + profile = fast_create(Profile) + assert_respond_to Profile, :more_active end - should 'list profiles that have no actions in more active list' do + should 'respond to more popular' do profile = fast_create(Profile) - assert_includes Profile.more_active, profile + assert_respond_to Profile, :more_popular end should "return the more recent label" do @@ -1607,29 +1579,29 @@ class ProfileTest < Test::Unit::TestCase assert_equal "Since: ", p.more_recent_label end - should "return no actions if profile has 0 actions" do + should "return no activity if profile has 0 actions" do p = fast_create(Profile) assert_equal 0, p.recent_actions.count - assert_equal "no actions", p.more_active_label + assert_equal "no activity", p.more_active_label end - should "return one action on label if the profile has one action" do + should "return one activity on label if the profile has one action" do p = fast_create(Profile) fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) assert_equal 1, p.recent_actions.count - assert_equal "one action", p.more_active_label + assert_equal "one activity", p.more_active_label end - should "return number of actions on label if the profile has more than one action" do + should "return number of activities on label if the profile has more than one action" do p = fast_create(Profile) fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) assert_equal 2, p.recent_actions.count - assert_equal "2 actions", p.more_active_label + assert_equal "2 activities", p.more_active_label fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) assert_equal 3, p.recent_actions.count - assert_equal "3 actions", p.more_active_label + assert_equal "3 activities", p.more_active_label end should 'provide list of galleries' do -- libgit2 0.21.2