Commit 8b0ca3f517d4480932a7583b80084e15b2eed81a
1 parent
e4a4505f
Exists in
master
and in
29 other branches
Enhancements on patch for browse lists bug
* Replacing actions by activities * Removing the more_active logic from profile to organization and person (ActionItem1885)
Showing
7 changed files
with
116 additions
and
57 deletions
Show diff stats
app/models/organization.rb
@@ -27,6 +27,13 @@ class Organization < Profile | @@ -27,6 +27,13 @@ class Organization < Profile | ||
27 | :joins => "LEFT OUTER JOIN role_assignments ON profiles.id = role_assignments.resource_id", | 27 | :joins => "LEFT OUTER JOIN role_assignments ON profiles.id = role_assignments.resource_id", |
28 | :order => "total DESC" | 28 | :order => "total DESC" |
29 | 29 | ||
30 | + named_scope :more_active, | ||
31 | + :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", | ||
32 | + :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id", | ||
33 | + :group => Profile.qualified_column_names, | ||
34 | + :order => 'total DESC', | ||
35 | + :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] | ||
36 | + | ||
30 | def validation_methodology | 37 | def validation_methodology |
31 | self.validation_info ? self.validation_info.validation_methodology : nil | 38 | self.validation_info ? self.validation_info.validation_methodology : nil |
32 | end | 39 | end |
app/models/person.rb
@@ -27,6 +27,13 @@ class Person < Profile | @@ -27,6 +27,13 @@ class Person < Profile | ||
27 | :joins => "LEFT OUTER JOIN friendships on profiles.id = friendships.person_id", | 27 | :joins => "LEFT OUTER JOIN friendships on profiles.id = friendships.person_id", |
28 | :order => "total DESC" | 28 | :order => "total DESC" |
29 | 29 | ||
30 | + named_scope :more_active, | ||
31 | + :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", | ||
32 | + :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id", | ||
33 | + :group => Profile.qualified_column_names, | ||
34 | + :order => 'total DESC', | ||
35 | + :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] | ||
36 | + | ||
30 | after_destroy do |person| | 37 | after_destroy do |person| |
31 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } | 38 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } |
32 | end | 39 | end |
app/models/profile.rb
@@ -78,19 +78,11 @@ class Profile < ActiveRecord::Base | @@ -78,19 +78,11 @@ class Profile < ActiveRecord::Base | ||
78 | end | 78 | end |
79 | 79 | ||
80 | named_scope :visible, :conditions => { :visible => true } | 80 | named_scope :visible, :conditions => { :visible => true } |
81 | - # Subclasses must override this method | 81 | + # Subclasses must override these methods |
82 | named_scope :more_popular | 82 | named_scope :more_popular |
83 | + named_scope :more_active | ||
84 | + | ||
83 | named_scope :more_recent, :order => "created_at DESC" | 85 | named_scope :more_recent, :order => "created_at DESC" |
84 | - named_scope :more_active, lambda { | ||
85 | - { | ||
86 | - :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", | ||
87 | - :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id" + | ||
88 | - (self == Person ? '' : ' OR profiles.id = action_tracker.target_id'), | ||
89 | - :group => Profile.qualified_column_names, | ||
90 | - :order => 'total DESC', | ||
91 | - :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] | ||
92 | - } | ||
93 | - } | ||
94 | 86 | ||
95 | acts_as_trackable :dependent => :destroy | 87 | acts_as_trackable :dependent => :destroy |
96 | 88 | ||
@@ -792,9 +784,9 @@ private :generate_url, :url_options | @@ -792,9 +784,9 @@ private :generate_url, :url_options | ||
792 | amount = recent_actions.count | 784 | amount = recent_actions.count |
793 | amount += recent_notifications.count if organization? | 785 | amount += recent_notifications.count if organization? |
794 | { | 786 | { |
795 | - 0 => _('no actions'), | ||
796 | - 1 => _('one action') | ||
797 | - }[amount] || _("%s actions") % amount | 787 | + 0 => _('no activity'), |
788 | + 1 => _('one activity') | ||
789 | + }[amount] || _("%s activities") % amount | ||
798 | end | 790 | end |
799 | 791 | ||
800 | def more_popular_label | 792 | def more_popular_label |
test/functional/browse_controller_test.rb
@@ -201,13 +201,14 @@ class BrowseControllerTest < Test::Unit::TestCase | @@ -201,13 +201,14 @@ class BrowseControllerTest < Test::Unit::TestCase | ||
201 | 201 | ||
202 | 202 | ||
203 | should 'list all communities filter by more active' do | 203 | should 'list all communities filter by more active' do |
204 | + person = fast_create(Person) | ||
204 | c1 = create(Community, :name => 'Testing community 1') | 205 | c1 = create(Community, :name => 'Testing community 1') |
205 | c2 = create(Community, :name => 'Testing community 2') | 206 | c2 = create(Community, :name => 'Testing community 2') |
206 | c3 = create(Community, :name => 'Testing community 3') | 207 | c3 = create(Community, :name => 'Testing community 3') |
207 | ActionTracker::Record.delete_all | 208 | ActionTracker::Record.delete_all |
208 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => c1, :created_at => Time.now) | ||
209 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => c2, :created_at => Time.now) | ||
210 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => c2, :created_at => Time.now) | 209 | + fast_create(ActionTracker::Record, :target_id => c1, :user_type => 'Profile', :user_id => person, :created_at => Time.now) |
210 | + fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | ||
211 | + fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | ||
211 | get :communities, :filter => 'more_active' | 212 | get :communities, :filter => 'more_active' |
212 | assert_equal [c2,c1,c3] , assigns(:results) | 213 | assert_equal [c2,c1,c3] , assigns(:results) |
213 | end | 214 | end |
test/unit/organization_test.rb
@@ -344,4 +344,46 @@ class OrganizationTest < Test::Unit::TestCase | @@ -344,4 +344,46 @@ class OrganizationTest < Test::Unit::TestCase | ||
344 | organization.add_member(person3) | 344 | organization.add_member(person3) |
345 | assert_equal "3 members", organization.more_popular_label | 345 | assert_equal "3 members", organization.more_popular_label |
346 | end | 346 | end |
347 | + | ||
348 | + should 'find more active organizations' do | ||
349 | + person = fast_create(Person) | ||
350 | + Organization.destroy_all | ||
351 | + p1 = fast_create(Organization) | ||
352 | + p2 = fast_create(Organization) | ||
353 | + p3 = fast_create(Organization) | ||
354 | + | ||
355 | + ActionTracker::Record.destroy_all | ||
356 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p1.id) | ||
357 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p2.id) | ||
358 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p2.id) | ||
359 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p3.id) | ||
360 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p3.id) | ||
361 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => Time.now, :target_id => p3.id) | ||
362 | + | ||
363 | + assert_equal [p3,p2,p1] , Organization.more_active | ||
364 | + end | ||
365 | + | ||
366 | + should 'more active profile take in consideration only actions created only in the recent delay interval' do | ||
367 | + ActionTracker::Record.destroy_all | ||
368 | + recent_delay = ActionTracker::Record::RECENT_DELAY.days.ago | ||
369 | + | ||
370 | + person = fast_create(Person) | ||
371 | + Organization.destroy_all | ||
372 | + p1 = fast_create(Organization) | ||
373 | + p2 = fast_create(Organization) | ||
374 | + | ||
375 | + ActionTracker::Record.destroy_all | ||
376 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay, :target_id => p1.id) | ||
377 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay, :target_id => p1.id) | ||
378 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay, :target_id => p2.id) | ||
379 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person, :created_at => recent_delay - 1.day, :target_id => p2.id) | ||
380 | + | ||
381 | + assert_equal [p1,p2] , Organization.more_active | ||
382 | + end | ||
383 | + | ||
384 | + should 'list profiles that have no actions in more active list' do | ||
385 | + profile = fast_create(Organization) | ||
386 | + assert_includes Organization.more_active, profile | ||
387 | + end | ||
388 | + | ||
347 | end | 389 | end |
test/unit/person_test.rb
@@ -1145,4 +1145,42 @@ class PersonTest < Test::Unit::TestCase | @@ -1145,4 +1145,42 @@ class PersonTest < Test::Unit::TestCase | ||
1145 | assert_equal [person], Person.members_of(community) | 1145 | assert_equal [person], Person.members_of(community) |
1146 | end | 1146 | end |
1147 | 1147 | ||
1148 | + should 'find more active people' do | ||
1149 | + Person.destroy_all | ||
1150 | + p1 = fast_create(Person) | ||
1151 | + p2 = fast_create(Person) | ||
1152 | + p3 = fast_create(Person) | ||
1153 | + | ||
1154 | + ActionTracker::Record.destroy_all | ||
1155 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) | ||
1156 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | ||
1157 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | ||
1158 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) | ||
1159 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) | ||
1160 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) | ||
1161 | + | ||
1162 | + assert_equal [p3,p2,p1] , Person.more_active | ||
1163 | + end | ||
1164 | + | ||
1165 | + should 'more active profile take in consideration only actions created only in the recent delay interval' do | ||
1166 | + Person.delete_all | ||
1167 | + ActionTracker::Record.destroy_all | ||
1168 | + recent_delay = ActionTracker::Record::RECENT_DELAY.days.ago | ||
1169 | + | ||
1170 | + p1 = fast_create(Person) | ||
1171 | + p2 = fast_create(Person) | ||
1172 | + | ||
1173 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) | ||
1174 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) | ||
1175 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay) | ||
1176 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay - 1.day) | ||
1177 | + | ||
1178 | + assert_equal [p1,p2], Person.more_active | ||
1179 | + end | ||
1180 | + | ||
1181 | + should 'list profiles that have no actions in more active list' do | ||
1182 | + profile = fast_create(Person) | ||
1183 | + assert_includes Person.more_active, profile | ||
1184 | + end | ||
1185 | + | ||
1148 | end | 1186 | end |
test/unit/profile_test.rb
@@ -1564,42 +1564,14 @@ class ProfileTest < Test::Unit::TestCase | @@ -1564,42 +1564,14 @@ class ProfileTest < Test::Unit::TestCase | ||
1564 | assert_equal [p2,p3,p4,p1] , Profile.more_recent | 1564 | assert_equal [p2,p3,p4,p1] , Profile.more_recent |
1565 | end | 1565 | end |
1566 | 1566 | ||
1567 | - should 'find more active profiles' do | ||
1568 | - Profile.destroy_all | ||
1569 | - p1 = fast_create(Profile) | ||
1570 | - p2 = fast_create(Profile) | ||
1571 | - p3 = fast_create(Profile) | ||
1572 | - | ||
1573 | - ActionTracker::Record.destroy_all | ||
1574 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) | ||
1575 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | ||
1576 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | ||
1577 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) | ||
1578 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) | ||
1579 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3, :created_at => Time.now) | ||
1580 | - | ||
1581 | - assert_equal [p3,p2,p1] , Profile.more_active | ||
1582 | - end | ||
1583 | - | ||
1584 | - should 'more active profile take in consideration only actions created only in the recent delay interval' do | ||
1585 | - Profile.delete_all | ||
1586 | - ActionTracker::Record.destroy_all | ||
1587 | - recent_delay = ActionTracker::Record::RECENT_DELAY.days.ago | ||
1588 | - | ||
1589 | - p1 = fast_create(Profile) | ||
1590 | - p2 = fast_create(Profile) | ||
1591 | - | ||
1592 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) | ||
1593 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => recent_delay) | ||
1594 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay) | ||
1595 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => recent_delay - 1.day) | ||
1596 | - | ||
1597 | - assert_equal [p1,p2], Profile.more_active | 1567 | + should 'respond to more active' do |
1568 | + profile = fast_create(Profile) | ||
1569 | + assert_respond_to Profile, :more_active | ||
1598 | end | 1570 | end |
1599 | 1571 | ||
1600 | - should 'list profiles that have no actions in more active list' do | 1572 | + should 'respond to more popular' do |
1601 | profile = fast_create(Profile) | 1573 | profile = fast_create(Profile) |
1602 | - assert_includes Profile.more_active, profile | 1574 | + assert_respond_to Profile, :more_popular |
1603 | end | 1575 | end |
1604 | 1576 | ||
1605 | should "return the more recent label" do | 1577 | should "return the more recent label" do |
@@ -1607,29 +1579,29 @@ class ProfileTest < Test::Unit::TestCase | @@ -1607,29 +1579,29 @@ class ProfileTest < Test::Unit::TestCase | ||
1607 | assert_equal "Since: ", p.more_recent_label | 1579 | assert_equal "Since: ", p.more_recent_label |
1608 | end | 1580 | end |
1609 | 1581 | ||
1610 | - should "return no actions if profile has 0 actions" do | 1582 | + should "return no activity if profile has 0 actions" do |
1611 | p = fast_create(Profile) | 1583 | p = fast_create(Profile) |
1612 | assert_equal 0, p.recent_actions.count | 1584 | assert_equal 0, p.recent_actions.count |
1613 | - assert_equal "no actions", p.more_active_label | 1585 | + assert_equal "no activity", p.more_active_label |
1614 | end | 1586 | end |
1615 | 1587 | ||
1616 | - should "return one action on label if the profile has one action" do | 1588 | + should "return one activity on label if the profile has one action" do |
1617 | p = fast_create(Profile) | 1589 | p = fast_create(Profile) |
1618 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) | 1590 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) |
1619 | assert_equal 1, p.recent_actions.count | 1591 | assert_equal 1, p.recent_actions.count |
1620 | - assert_equal "one action", p.more_active_label | 1592 | + assert_equal "one activity", p.more_active_label |
1621 | end | 1593 | end |
1622 | 1594 | ||
1623 | - should "return number of actions on label if the profile has more than one action" do | 1595 | + should "return number of activities on label if the profile has more than one action" do |
1624 | p = fast_create(Profile) | 1596 | p = fast_create(Profile) |
1625 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) | 1597 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) |
1626 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) | 1598 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) |
1627 | assert_equal 2, p.recent_actions.count | 1599 | assert_equal 2, p.recent_actions.count |
1628 | - assert_equal "2 actions", p.more_active_label | 1600 | + assert_equal "2 activities", p.more_active_label |
1629 | 1601 | ||
1630 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) | 1602 | fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) |
1631 | assert_equal 3, p.recent_actions.count | 1603 | assert_equal 3, p.recent_actions.count |
1632 | - assert_equal "3 actions", p.more_active_label | 1604 | + assert_equal "3 activities", p.more_active_label |
1633 | end | 1605 | end |
1634 | 1606 | ||
1635 | should 'provide list of galleries' do | 1607 | should 'provide list of galleries' do |