Commit e4a4505ff18c89d6a6aac8cd4a8cd97ad923bad5
Committed by
Daniela Feitosa
1 parent
7020cd0e
Exists in
master
and in
23 other branches
Fixing bug on the browse lists
Co-Author: Aurelio A. Heckert <aurelio@colivre.coop.br>
* Listing profiles that have 0 objects (friends, actions, etc).
* More active based on action instead of articles.
* Testing profile in the profile tests instead of communities or
people.
(ActionItem1885)
Showing
9 changed files
with
163 additions
and
213 deletions
Show diff stats
app/models/organization.rb
| ... | ... | @@ -21,6 +21,12 @@ class Organization < Profile |
| 21 | 21 | |
| 22 | 22 | has_many :mailings, :class_name => 'OrganizationMailing', :foreign_key => :source_id, :as => 'source' |
| 23 | 23 | |
| 24 | + named_scope :more_popular, | |
| 25 | + :select => "#{Profile.qualified_column_names}, count(resource_id) as total", | |
| 26 | + :group => Profile.qualified_column_names, | |
| 27 | + :joins => "LEFT OUTER JOIN role_assignments ON profiles.id = role_assignments.resource_id", | |
| 28 | + :order => "total DESC" | |
| 29 | + | |
| 24 | 30 | def validation_methodology |
| 25 | 31 | self.validation_info ? self.validation_info.validation_methodology : nil |
| 26 | 32 | end | ... | ... |
app/models/person.rb
| ... | ... | @@ -22,10 +22,10 @@ class Person < Profile |
| 22 | 22 | has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy |
| 23 | 23 | |
| 24 | 24 | named_scope :more_popular, |
| 25 | - :select => "#{Profile.qualified_column_names}, count(friend_id) as total", | |
| 26 | - :group => Profile.qualified_column_names, | |
| 27 | - :joins => :friendships, | |
| 28 | - :order => "total DESC" | |
| 25 | + :select => "#{Profile.qualified_column_names}, count(friend_id) as total", | |
| 26 | + :group => Profile.qualified_column_names, | |
| 27 | + :joins => "LEFT OUTER JOIN friendships on profiles.id = friendships.person_id", | |
| 28 | + :order => "total DESC" | |
| 29 | 29 | |
| 30 | 30 | after_destroy do |person| |
| 31 | 31 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } | ... | ... |
app/models/profile.rb
| ... | ... | @@ -78,18 +78,19 @@ class Profile < ActiveRecord::Base |
| 78 | 78 | end |
| 79 | 79 | |
| 80 | 80 | named_scope :visible, :conditions => { :visible => true } |
| 81 | + # Subclasses must override this method | |
| 82 | + named_scope :more_popular | |
| 81 | 83 | named_scope :more_recent, :order => "created_at DESC" |
| 82 | - named_scope :more_popular, | |
| 83 | - :select => "#{Profile.qualified_column_names}, count(resource_id) as total", | |
| 84 | - :group => Profile.qualified_column_names, | |
| 85 | - :joins => :role_assignments, | |
| 86 | - :order => "total DESC" | |
| 87 | - named_scope :more_active, | |
| 88 | - :select => "#{Profile.qualified_column_names}, count(articles.id) as total, sum(articles.comments_count) as total_comments", | |
| 89 | - :joins => :articles, | |
| 90 | - :group => Profile.qualified_column_names, | |
| 91 | - :order => "total DESC, total_comments DESC", | |
| 92 | - :conditions => ["articles.created_at BETWEEN ? AND ?", 7.days.ago, DateTime.now] | |
| 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 | + } | |
| 93 | 94 | |
| 94 | 95 | acts_as_trackable :dependent => :destroy |
| 95 | 96 | |
| ... | ... | @@ -779,18 +780,27 @@ private :generate_url, :url_options |
| 779 | 780 | _("Since: ") |
| 780 | 781 | end |
| 781 | 782 | |
| 783 | + def recent_actions | |
| 784 | + tracked_actions.recent | |
| 785 | + end | |
| 786 | + | |
| 787 | + def recent_notifications | |
| 788 | + tracked_notifications.recent | |
| 789 | + end | |
| 790 | + | |
| 782 | 791 | def more_active_label |
| 783 | - amount = self.articles.count | |
| 792 | + amount = recent_actions.count | |
| 793 | + amount += recent_notifications.count if organization? | |
| 784 | 794 | { |
| 785 | - 0 => _('none'), | |
| 786 | - 1 => _('one article') | |
| 787 | - }[amount] || _("%s articles") % amount | |
| 795 | + 0 => _('no actions'), | |
| 796 | + 1 => _('one action') | |
| 797 | + }[amount] || _("%s actions") % amount | |
| 788 | 798 | end |
| 789 | 799 | |
| 790 | 800 | def more_popular_label |
| 791 | 801 | amount = self.members_count |
| 792 | 802 | { |
| 793 | - 0 => _('none'), | |
| 803 | + 0 => _('no members'), | |
| 794 | 804 | 1 => _('one member') |
| 795 | 805 | }[amount] || _("%s members") % amount |
| 796 | 806 | end | ... | ... |
test/functional/browse_controller_test.rb
| ... | ... | @@ -89,11 +89,12 @@ class BrowseControllerTest < Test::Unit::TestCase |
| 89 | 89 | p1 = create(Person, :name => 'Testing person 1', :user_id => 1) |
| 90 | 90 | p2 = create(Person, :name => 'Testing person 2', :user_id => 2) |
| 91 | 91 | p3 = create(Person, :name => 'Testing person 3', :user_id => 3) |
| 92 | - Article.delete_all | |
| 93 | - fast_create(Article, :profile_id => p1, :created_at => 1.day.ago) | |
| 94 | - fast_create(Article, :profile_id => p2, :created_at => DateTime.now.beginning_of_day) | |
| 92 | + ActionTracker::Record.delete_all | |
| 93 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) | |
| 94 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 95 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 95 | 96 | get :people, :filter => 'more_active' |
| 96 | - assert_equal [p1,p2] , assigns(:results) | |
| 97 | + assert_equal [p2,p1,p3] , assigns(:results) | |
| 97 | 98 | end |
| 98 | 99 | |
| 99 | 100 | should 'filter more popular people' do |
| ... | ... | @@ -106,7 +107,7 @@ class BrowseControllerTest < Test::Unit::TestCase |
| 106 | 107 | p2.add_friend(p1) |
| 107 | 108 | p2.add_friend(p3) |
| 108 | 109 | get :people, :filter => 'more_popular' |
| 109 | - assert_equal [p2,p1] , assigns(:results) | |
| 110 | + assert_equal [p2,p1,p3] , assigns(:results) | |
| 110 | 111 | end |
| 111 | 112 | |
| 112 | 113 | should 'the people filter be only the hardcoded one' do |
| ... | ... | @@ -203,18 +204,19 @@ class BrowseControllerTest < Test::Unit::TestCase |
| 203 | 204 | c1 = create(Community, :name => 'Testing community 1') |
| 204 | 205 | c2 = create(Community, :name => 'Testing community 2') |
| 205 | 206 | c3 = create(Community, :name => 'Testing community 3') |
| 206 | - Article.delete_all | |
| 207 | - fast_create(Article, :profile_id => c1, :created_at => 1.day.ago) | |
| 208 | - fast_create(Article, :profile_id => c2, :created_at => DateTime.now.beginning_of_day) | |
| 207 | + 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 | 211 | get :communities, :filter => 'more_active' |
| 210 | - assert_equal [c1,c2] , assigns(:results) | |
| 212 | + assert_equal [c2,c1,c3] , assigns(:results) | |
| 211 | 213 | end |
| 212 | 214 | |
| 213 | 215 | should 'filter more popular communities' do |
| 214 | 216 | Person.delete_all |
| 217 | + Community.delete_all | |
| 215 | 218 | c1 = create(Community, :name => 'Testing community 1') |
| 216 | 219 | c2 = create(Community, :name => 'Testing community 2') |
| 217 | - create(Community, :name => 'Testing community 3') | |
| 218 | 220 | |
| 219 | 221 | p1 = create(Person, :name => 'Testing person 1', :user_id => 1) |
| 220 | 222 | p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | ... | ... |
test/unit/organization_test.rb
| ... | ... | @@ -297,4 +297,51 @@ class OrganizationTest < Test::Unit::TestCase |
| 297 | 297 | assert_equal "online_community@conference.#{org.environment.default_hostname}/#{org.short_name}", org.full_jid |
| 298 | 298 | end |
| 299 | 299 | |
| 300 | + should 'find more popular organizations' do | |
| 301 | + Organization.delete_all | |
| 302 | + o1 = fast_create(Organization) | |
| 303 | + o2 = fast_create(Organization) | |
| 304 | + | |
| 305 | + p1 = fast_create(Person) | |
| 306 | + p2 = fast_create(Person) | |
| 307 | + o1.add_member(p1) | |
| 308 | + assert_equal [o1,o2] , Organization.more_popular | |
| 309 | + | |
| 310 | + o2.add_member(p1) | |
| 311 | + o2.add_member(p2) | |
| 312 | + assert_equal [o2,o1] , Organization.more_popular | |
| 313 | + end | |
| 314 | + | |
| 315 | + should 'list organizations that have no members in more popular list' do | |
| 316 | + organization = fast_create(Organization) | |
| 317 | + assert_includes Organization.more_popular, organization | |
| 318 | + end | |
| 319 | + | |
| 320 | + should "return no members on label if the organization has no members" do | |
| 321 | + organization = fast_create(Organization) | |
| 322 | + assert_equal 0, organization.members_count | |
| 323 | + assert_equal "no members", organization.more_popular_label | |
| 324 | + end | |
| 325 | + | |
| 326 | + should "return one member on label if the organization has one member" do | |
| 327 | + person = fast_create(Person) | |
| 328 | + organization = fast_create(Organization) | |
| 329 | + organization.add_member(person) | |
| 330 | + | |
| 331 | + assert_equal "one member", organization.more_popular_label | |
| 332 | + end | |
| 333 | + | |
| 334 | + should "return the number of members on label if the organization has more than one member" do | |
| 335 | + person1 = fast_create(Person) | |
| 336 | + person2 = fast_create(Person) | |
| 337 | + organization = fast_create(Organization) | |
| 338 | + | |
| 339 | + organization.add_member(person1) | |
| 340 | + organization.add_member(person2) | |
| 341 | + assert_equal "2 members", organization.more_popular_label | |
| 342 | + | |
| 343 | + person3 = fast_create(Person) | |
| 344 | + organization.add_member(person3) | |
| 345 | + assert_equal "3 members", organization.more_popular_label | |
| 346 | + end | |
| 300 | 347 | end | ... | ... |
test/unit/person_test.rb
| ... | ... | @@ -625,20 +625,20 @@ class PersonTest < Test::Unit::TestCase |
| 625 | 625 | |
| 626 | 626 | should 'find more popular people' do |
| 627 | 627 | Person.delete_all |
| 628 | - env = fast_create(Environment) | |
| 629 | 628 | p1 = fast_create(Person) |
| 630 | 629 | p2 = fast_create(Person) |
| 631 | 630 | p3 = fast_create(Person) |
| 632 | 631 | |
| 633 | 632 | p1.add_friend(p2) |
| 634 | - assert_equal [p1], Person.more_popular | |
| 635 | - | |
| 636 | 633 | p2.add_friend(p1) |
| 637 | 634 | p2.add_friend(p3) |
| 638 | - assert_equal [p2,p1] , Person.more_popular | |
| 635 | + assert_equal p2, Person.more_popular[0] | |
| 636 | + assert_equal p1, Person.more_popular[1] | |
| 637 | + end | |
| 639 | 638 | |
| 640 | - p2.remove_friend(p3) | |
| 641 | - assert_equal [p1,p2] , Person.more_popular | |
| 639 | + should 'list people that have no friends in more popular list' do | |
| 640 | + person = fast_create(Person) | |
| 641 | + assert_includes Person.more_popular, person | |
| 642 | 642 | end |
| 643 | 643 | |
| 644 | 644 | should 'persons has reference to user' do | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -1553,151 +1553,53 @@ class ProfileTest < Test::Unit::TestCase |
| 1553 | 1553 | assert_match /<!-- .* --> <h1> Wellformed html code <\/h1>/, profile.custom_footer |
| 1554 | 1554 | end |
| 1555 | 1555 | |
| 1556 | - should 'find more recent people' do | |
| 1557 | - Person.delete_all | |
| 1558 | - p1 = fast_create(Person,:created_at => 4.days.ago) | |
| 1559 | - p2 = fast_create(Person, :created_at => DateTime.now) | |
| 1560 | - p3 = fast_create(Person, :created_at => 2.days.ago) | |
| 1561 | - | |
| 1562 | - assert_equal [p2,p3,p1] , Person.more_recent | |
| 1563 | - | |
| 1564 | - p4 = fast_create(Person, :created_at => 3.days.ago) | |
| 1565 | - assert_equal [p2,p3,p4,p1] , Person.more_recent | |
| 1566 | - end | |
| 1567 | - | |
| 1568 | - should 'find more active people' do | |
| 1569 | - Person.delete_all | |
| 1570 | - p1 = fast_create(Person) | |
| 1571 | - p2 = fast_create(Person) | |
| 1572 | - p3 = fast_create(Person) | |
| 1573 | - Article.delete_all | |
| 1574 | - fast_create(Article, :profile_id => p1, :created_at => 7.days.ago) | |
| 1575 | - fast_create(Article, :profile_id => p1, :created_at => DateTime.now.beginning_of_day) | |
| 1576 | - fast_create(Article, :profile_id => p2, :created_at => DateTime.now.beginning_of_day) | |
| 1577 | - assert_equal [p1,p2] , Person.more_active | |
| 1578 | - | |
| 1579 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1580 | - fast_create(Article, :profile_id => p2, :created_at => 5.days.ago) | |
| 1581 | - fast_create(Article, :profile_id => p3, :created_at => 2.days.ago) | |
| 1582 | - assert_equal [p2,p1,p3] , Person.more_active | |
| 1583 | - end | |
| 1584 | - | |
| 1585 | - should 'the ties on more active people be solved by the number of comments' do | |
| 1586 | - Person.delete_all | |
| 1587 | - p1 = fast_create(Person) | |
| 1588 | - p2 = fast_create(Person) | |
| 1589 | - Article.delete_all | |
| 1590 | - a1 = fast_create(Article, :profile_id => p1, :created_at => DateTime.now.beginning_of_day) | |
| 1591 | - a2 = fast_create(Article, :profile_id => p2, :created_at => DateTime.now.beginning_of_day) | |
| 1592 | - assert_equal [], [p1,p2] - Person.more_active | |
| 1593 | - assert_equal [], Person.more_active - [p1, p2] | |
| 1594 | - | |
| 1595 | - a2.comments.build(:title => 'test comment', :body => 'anything', :author => p1).save! | |
| 1596 | - assert_equal [p2,p1] , Person.more_active | |
| 1597 | - | |
| 1598 | - a1.comments.build(:title => 'test comment', :body => 'anything', :author => p2).save! | |
| 1599 | - a1.comments.build(:title => 'test comment', :body => 'anything', :author => p2).save! | |
| 1600 | - assert_equal [p1,p2] , Person.more_active | |
| 1601 | - end | |
| 1602 | - | |
| 1603 | - should 'more active people take in consideration only articles created current the last week' do | |
| 1604 | - Person.delete_all | |
| 1605 | - env = fast_create(Environment) | |
| 1606 | - p1 = fast_create(Person) | |
| 1607 | - p2 = fast_create(Person) | |
| 1608 | - p3 = fast_create(Person) | |
| 1609 | - Article.delete_all | |
| 1610 | - fast_create(Article, :profile_id => p1, :created_at => DateTime.now.beginning_of_day) | |
| 1611 | - fast_create(Article, :profile_id => p2, :created_at => 10.days.ago) | |
| 1612 | - assert_equal [p1] , Person.more_active | |
| 1613 | - | |
| 1614 | - fast_create(Article, :profile_id => p2, :created_at => DateTime.now.beginning_of_day) | |
| 1615 | - fast_create(Article, :profile_id => p2, :created_at => 7.days.ago) | |
| 1616 | - fast_create(Article, :profile_id => p3, :created_at => 8.days.ago) | |
| 1617 | - assert_equal [p2,p1] , Person.more_active | |
| 1618 | - end | |
| 1619 | - | |
| 1620 | - should 'find more recent community' do | |
| 1621 | - c1 = fast_create(Community, :created_at => 3.days.ago) | |
| 1622 | - c2 = fast_create(Community, :created_at => 1.day.ago) | |
| 1623 | - c3 = fast_create(Community, :created_at => DateTime.now) | |
| 1624 | - | |
| 1625 | - assert_equal [c3,c2,c1] , Community.more_recent | |
| 1556 | + should 'find more recent profile' do | |
| 1557 | + Profile.delete_all | |
| 1558 | + p1 = fast_create(Profile, :created_at => 4.days.ago) | |
| 1559 | + p2 = fast_create(Profile, :created_at => Time.now) | |
| 1560 | + p3 = fast_create(Profile, :created_at => 2.days.ago) | |
| 1561 | + assert_equal [p2,p3,p1] , Profile.more_recent | |
| 1626 | 1562 | |
| 1627 | - c4 = fast_create(Community, :created_at => 2.days.ago) | |
| 1628 | - assert_equal [c3,c2,c4,c1] , Community.more_recent | |
| 1563 | + p4 = fast_create(Profile, :created_at => 3.days.ago) | |
| 1564 | + assert_equal [p2,p3,p4,p1] , Profile.more_recent | |
| 1629 | 1565 | end |
| 1630 | 1566 | |
| 1631 | - should 'find more active community' do | |
| 1632 | - c1 = fast_create(Community) | |
| 1633 | - c2 = fast_create(Community) | |
| 1634 | - c3 = fast_create(Community) | |
| 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) | |
| 1635 | 1572 | |
| 1636 | - Article.delete_all | |
| 1637 | - fast_create(Article, :profile_id => c1, :created_at => 1.day.ago) | |
| 1638 | - fast_create(Article, :profile_id => c1, :created_at => DateTime.now.beginning_of_day) | |
| 1639 | - fast_create(Article, :profile_id => c2, :created_at => DateTime.now.beginning_of_day) | |
| 1640 | - assert_equal [c1,c2], Community.more_active | |
| 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) | |
| 1641 | 1580 | |
| 1642 | - fast_create(Article, :profile_id => c2, :created_at => 2.days.ago) | |
| 1643 | - fast_create(Article, :profile_id => c2, :created_at => 7.days.ago) | |
| 1644 | - fast_create(Article, :profile_id => c3, :created_at => 1.day.ago) | |
| 1645 | - assert_equal [c2,c1,c3] , Community.more_active | |
| 1581 | + assert_equal [p3,p2,p1] , Profile.more_active | |
| 1646 | 1582 | end |
| 1647 | 1583 | |
| 1648 | - should 'the ties on more active communities be solved by the number of comments' do | |
| 1649 | - env = create(Environment) | |
| 1650 | - Community.delete_all | |
| 1651 | - c1 = fast_create(Community) | |
| 1652 | - c2 = fast_create(Community) | |
| 1653 | - Article.delete_all | |
| 1654 | - a1 = fast_create(Article, :profile_id => c1, :created_at => DateTime.now.beginning_of_day) | |
| 1655 | - a2 = fast_create(Article, :profile_id => c2, :created_at => DateTime.now.beginning_of_day) | |
| 1656 | - assert_equal [c1,c2] , Community.more_active | |
| 1657 | - | |
| 1658 | - p1 = fast_create(Person) | |
| 1659 | - a2.comments.build(:title => 'test comment', :body => 'anything', :author => p1).save! | |
| 1660 | - assert_equal [c2,c1] , Community.more_active | |
| 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 | |
| 1661 | 1588 | |
| 1662 | - a1.comments.build(:title => 'test comment', :body => 'anything', :author => p1).save! | |
| 1663 | - a1.comments.build(:title => 'test comment', :body => 'anything', :author => p1).save! | |
| 1664 | - assert_equal [c1,c2] , Community.more_active | |
| 1665 | - end | |
| 1589 | + p1 = fast_create(Profile) | |
| 1590 | + p2 = fast_create(Profile) | |
| 1666 | 1591 | |
| 1667 | - should 'more active communities take in consideration only articles created current the last week' do | |
| 1668 | - c1 = fast_create(Community) | |
| 1669 | - c2 = fast_create(Community) | |
| 1670 | - c3 = fast_create(Community) | |
| 1671 | - Article.delete_all | |
| 1672 | - fast_create(Article, :profile_id => c1, :created_at => DateTime.now.beginning_of_day) | |
| 1673 | - fast_create(Article, :profile_id => c2, :created_at => 10.days.ago) | |
| 1674 | - assert_equal [c1] , Community.more_active | |
| 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) | |
| 1675 | 1596 | |
| 1676 | - fast_create(Article, :profile_id => c2, :created_at => DateTime.now.beginning_of_day) | |
| 1677 | - fast_create(Article, :profile_id => c2, :created_at => 7.days.ago) | |
| 1678 | - fast_create(Article, :profile_id => c3, :created_at => 8.days.ago) | |
| 1679 | - assert_equal [c2,c1] , Community.more_active | |
| 1597 | + assert_equal [p1,p2], Profile.more_active | |
| 1680 | 1598 | end |
| 1681 | 1599 | |
| 1682 | - should 'find more popular communities' do | |
| 1683 | - Community.delete_all | |
| 1684 | - | |
| 1685 | - c1 = fast_create(Community) | |
| 1686 | - c2 = fast_create(Community) | |
| 1687 | - fast_create(Community) | |
| 1688 | - | |
| 1689 | - p1 = fast_create(Person) | |
| 1690 | - p2 = fast_create(Person) | |
| 1691 | - c1.add_member(p1) | |
| 1692 | - assert_equal [c1] , Community.more_popular | |
| 1693 | - | |
| 1694 | - c2.add_member(p1) | |
| 1695 | - c2.add_member(p2) | |
| 1696 | - assert_equal [c2,c1] , Community.more_popular | |
| 1697 | - | |
| 1698 | - c2.remove_member(p2) | |
| 1699 | - c2.remove_member(p1) | |
| 1700 | - assert_equal [c1] , Community.more_popular | |
| 1600 | + should 'list profiles that have no actions in more active list' do | |
| 1601 | + profile = fast_create(Profile) | |
| 1602 | + assert_includes Profile.more_active, profile | |
| 1701 | 1603 | end |
| 1702 | 1604 | |
| 1703 | 1605 | should "return the more recent label" do |
| ... | ... | @@ -1705,57 +1607,29 @@ class ProfileTest < Test::Unit::TestCase |
| 1705 | 1607 | assert_equal "Since: ", p.more_recent_label |
| 1706 | 1608 | end |
| 1707 | 1609 | |
| 1708 | - should "return none on label if the profile hasn't articles" do | |
| 1610 | + should "return no actions if profile has 0 actions" do | |
| 1709 | 1611 | p = fast_create(Profile) |
| 1710 | - assert_equal 0, p.articles.count | |
| 1711 | - assert_equal "none", p.more_active_label | |
| 1612 | + assert_equal 0, p.recent_actions.count | |
| 1613 | + assert_equal "no actions", p.more_active_label | |
| 1712 | 1614 | end |
| 1713 | 1615 | |
| 1714 | - should "return one article on label if the profile has one article" do | |
| 1616 | + should "return one action on label if the profile has one action" do | |
| 1715 | 1617 | p = fast_create(Profile) |
| 1716 | - fast_create(Article, :profile_id => p.id) | |
| 1717 | - assert_equal 1, p.articles.count | |
| 1718 | - assert_equal "one article", p.more_active_label | |
| 1618 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) | |
| 1619 | + assert_equal 1, p.recent_actions.count | |
| 1620 | + assert_equal "one action", p.more_active_label | |
| 1719 | 1621 | end |
| 1720 | 1622 | |
| 1721 | - should "return number of artciles on label if the profile has more than one article" do | |
| 1623 | + should "return number of actions on label if the profile has more than one action" do | |
| 1722 | 1624 | p = fast_create(Profile) |
| 1723 | - fast_create(Article, :profile_id => p.id) | |
| 1724 | - fast_create(Article, :profile_id => p.id) | |
| 1725 | - assert_equal 2, p.articles.count | |
| 1726 | - assert_equal "2 articles", p.more_active_label | |
| 1727 | - | |
| 1728 | - fast_create(Article, :profile_id => p.id) | |
| 1729 | - assert_equal 3, p.articles.count | |
| 1730 | - assert_equal "3 articles", p.more_active_label | |
| 1731 | - end | |
| 1732 | - | |
| 1733 | - should "return none on label if the profile hasn't members" do | |
| 1734 | - p = fast_create(Profile) | |
| 1735 | - assert_equal 0, p.members_count | |
| 1736 | - assert_equal "none", p.more_popular_label | |
| 1737 | - end | |
| 1738 | - | |
| 1739 | - should "return one member on label if the profile has one member" do | |
| 1740 | - person = fast_create(Person) | |
| 1741 | - community = fast_create(Community) | |
| 1742 | - community.add_member(person) | |
| 1743 | - | |
| 1744 | - assert_equal "one member", community.more_popular_label | |
| 1745 | - end | |
| 1746 | - | |
| 1747 | - should "return the number of members on label if the profile has more than one member" do | |
| 1748 | - person1 = fast_create(Person) | |
| 1749 | - person2 = fast_create(Person) | |
| 1750 | - community = fast_create(Community) | |
| 1751 | - | |
| 1752 | - community.add_member(person1) | |
| 1753 | - community.add_member(person2) | |
| 1754 | - assert_equal "2 members", community.more_popular_label | |
| 1755 | - | |
| 1756 | - person3 = fast_create(Person) | |
| 1757 | - community.add_member(person3) | |
| 1758 | - assert_equal "3 members", community.more_popular_label | |
| 1625 | + 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) | |
| 1627 | + assert_equal 2, p.recent_actions.count | |
| 1628 | + assert_equal "2 actions", p.more_active_label | |
| 1629 | + | |
| 1630 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p, :created_at => Time.now) | |
| 1631 | + assert_equal 3, p.recent_actions.count | |
| 1632 | + assert_equal "3 actions", p.more_active_label | |
| 1759 | 1633 | end |
| 1760 | 1634 | |
| 1761 | 1635 | should 'provide list of galleries' do | ... | ... |
vendor/plugins/action_tracker/lib/action_tracker_model.rb
| ... | ... | @@ -20,6 +20,11 @@ module ActionTracker |
| 20 | 20 | |
| 21 | 21 | alias_method :subject, :user |
| 22 | 22 | |
| 23 | + # In days | |
| 24 | + RECENT_DELAY = 30 | |
| 25 | + | |
| 26 | + named_scope :recent, :conditions => ['created_at >= ?', RECENT_DELAY.days.ago] | |
| 27 | + | |
| 23 | 28 | def self.current_user_from_model |
| 24 | 29 | u = new |
| 25 | 30 | u.valid? | ... | ... |
vendor/plugins/action_tracker/test/action_tracker_model_test.rb
| ... | ... | @@ -356,4 +356,10 @@ class ActionTrackerModelTest < ActiveSupport::TestCase |
| 356 | 356 | assert_equal(["foo 1", "bar 2"], t.collect_group_with_index(:test){|x, i| "#{x} #{i+1}" }) |
| 357 | 357 | end |
| 358 | 358 | |
| 359 | + def test_recent_filter_actions | |
| 360 | + ActionTracker::Record.destroy_all | |
| 361 | + t1 = ActionTracker::Record.create!(:user => SomeModel.create!, :verb => :some_verb, :created_at => Time.now) | |
| 362 | + t2 = ActionTracker::Record.create!(:user => SomeModel.create!, :verb => :some_verb, :created_at => ActionTracker::Record::RECENT_DELAY.days.ago - 1.day) | |
| 363 | + assert_equal [t1], ActionTracker::Record.recent.all | |
| 364 | + end | |
| 359 | 365 | end | ... | ... |