Index: test/unit/issue_test.rb =================================================================== --- test/unit/issue_test.rb (revision 2250) +++ test/unit/issue_test.rb (working copy) @@ -203,4 +203,23 @@ assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? assert !Issue.new(:due_date => nil).overdue? end + + def test_recently_updated_with_limit_scopes + #should return the last updated issue + assert_equal 1, Issue.recently_updated.with_limit(1).size + assert_equal Issue.find(:first, :order => "updated_on DESC"), Issue.recently_updated.with_limit(1).first + end + + def test_on_active_projects_scope + before = Issue.on_active_project.size + # test inclusion to results + issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30') + issue.save! + assert Issue.on_active_project.size == (before + 1) + + #test exclusion from results + issue.move_to(Project.find(6)) # Move to an archived peoject + issue.reload + assert Issue.on_active_project.size == before + end end Index: test/unit/project_test.rb =================================================================== --- test/unit/project_test.rb (revision 2250) +++ test/unit/project_test.rb (working copy) @@ -47,7 +47,7 @@ def test_public_projects public_projects = Project.find(:all, :conditions => ["is_public=?", true]) - assert_equal 3, public_projects.length + assert_equal 4, public_projects.length assert_equal true, public_projects[0].is_public? end Index: test/fixtures/projects.yml =================================================================== --- test/fixtures/projects.yml (revision 2250) +++ test/fixtures/projects.yml (working copy) @@ -54,4 +54,15 @@ is_public: false identifier: private_child parent_id: 1 - \ No newline at end of file +projects_006: + created_on: 2006-07-19 19:13:59 +02:00 + name: Dead Project + updated_on: 2006-07-19 22:53:01 +02:00 + projects_count: 0 + id: 6 + description: A vaporware project + homepage: "" + is_public: true + identifier: vaporware + status: <%= Project::STATUS_ARCHIVED %> + parent_id: Index: app/models/issue.rb =================================================================== --- app/models/issue.rb (revision 2250) +++ app/models/issue.rb (working copy) @@ -44,8 +44,14 @@ acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]}, :author_key => :author_id - + + named_scope :recently_updated, :order => "#{self.table_name}.updated_on DESC" + named_scope :with_limit, lambda { |limit| { :limit => limit} } + named_scope :on_active_project, :include => [:status, :project, :tracker], + :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"] + validates_presence_of :subject, :priority, :project, :tracker, :author, :status + validates_length_of :subject, :maximum => 255 validates_inclusion_of :done_ratio, :in => 0..100 validates_numericality_of :estimated_hours, :allow_nil => true Index: app/views/my/blocks/_issueswatched.rhtml =================================================================== --- app/views/my/blocks/_issueswatched.rhtml (revision 2250) +++ app/views/my/blocks/_issueswatched.rhtml (working copy) @@ -1,9 +1,5 @@

<%=l(:label_watched_issues)%>

-<% watched_issues = Issue.find(:all, - :include => [:status, :project, :tracker, :watchers], - :limit => 10, - :conditions => ["#{Watcher.table_name}.user_id = ? AND #{Project.table_name}.status=#{Project::STATUS_ACTIVE}", user.id], - :order => "#{Issue.table_name}.updated_on DESC") %> +<% watched_issues = Issue.on_active_project.watched_by(user.id).recently_updated.with_limit(10) %> <%= render :partial => 'issues/list_simple', :locals => { :issues => watched_issues } %> <% if watched_issues.length > 0 %>

<%=lwr(:label_last_updates, watched_issues.length)%>

Index: vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb =================================================================== --- vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb (revision 2250) +++ vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb (working copy) @@ -7,6 +7,9 @@ end module ClassMethods + # Additional to the instance methods it adds class method watched_by(user) + # which returns the objects that are watched by the _user_ object or _user_id_ + # which is passed as an argument. def acts_as_watchable(options = {}) return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) send :include, Redmine::Acts::Watchable::InstanceMethods @@ -15,6 +18,10 @@ has_many :watchers, :as => :watchable, :dependent => :delete_all has_many :watcher_users, :through => :watchers, :source => :user + named_scope :watched_by, lambda { |user| + { :include => :watchers, + :conditions => ["#{Watcher.table_name}.user_id = ?", user] } + } attr_protected :watcher_ids, :watcher_user_ids end end @@ -57,14 +64,7 @@ self.watchers.collect { |w| w.user.mail if w.user.active? }.compact end - module ClassMethods - # Returns the objects that are watched by user - def watched_by(user) - find(:all, - :include => :watchers, - :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]) - end - end + module ClassMethods; end end end end