@@ -49,8 +49,9 class Issue < ActiveRecord::Base | |||
|
49 | 49 | DONE_RATIO_OPTIONS = %w(issue_field issue_status) |
|
50 | 50 | |
|
51 | 51 | attr_reader :current_journal |
|
52 | ||
|
52 | ||
|
53 | 53 | validates_presence_of :subject, :priority, :project, :tracker, :author, :status |
|
54 | ||
|
54 | 55 | validates_length_of :subject, :maximum => 255 |
|
55 | 56 | validates_inclusion_of :done_ratio, :in => 0..100 |
|
56 | 57 | validates_numericality_of :estimated_hours, :allow_nil => true |
@@ -60,6 +61,11 class Issue < ActiveRecord::Base | |||
|
60 | 61 | |
|
61 | 62 | named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status |
|
62 | 63 | |
|
64 | named_scope :recently_updated, :order => "#{self.table_name}.updated_on DESC" | |
|
65 | named_scope :with_limit, lambda { |limit| { :limit => limit} } | |
|
66 | named_scope :on_active_project, :include => [:status, :project, :tracker], | |
|
67 | :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"] | |
|
68 | ||
|
63 | 69 | before_create :default_assign |
|
64 | 70 | before_save :reschedule_following_issues, :close_duplicates, :update_done_ratio_from_issue_status |
|
65 | 71 | after_save :create_journal |
@@ -1,10 +1,5 | |||
|
1 |
<h3><%=l(:label_watched_issues)%> (<%= Issue.visible.count |
|
|
2 | :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]) %>)</h3> | |
|
3 | <% watched_issues = Issue.visible.find(:all, | |
|
4 | :include => [:status, :project, :tracker, :watchers], | |
|
5 | :limit => 10, | |
|
6 | :conditions => ["#{Watcher.table_name}.user_id = ?", user.id], | |
|
7 | :order => "#{Issue.table_name}.updated_on DESC") %> | |
|
1 | <h3><%=l(:label_watched_issues)%> (<%= Issue.visible.watched_by(user.id).count %>)</h3> | |
|
2 | <% watched_issues = Issue.visible.on_active_project.watched_by(user.id).recently_updated.with_limit(10) %> | |
|
8 | 3 | |
|
9 | 4 | <%= render :partial => 'issues/list_simple', :locals => { :issues => watched_issues } %> |
|
10 | 5 | <% if watched_issues.length > 0 %> |
@@ -656,4 +656,24 class IssueTest < ActiveSupport::TestCase | |||
|
656 | 656 | assert_equal 2, groups.size |
|
657 | 657 | assert_equal 5, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
658 | 658 | end |
|
659 | ||
|
660 | def test_recently_updated_with_limit_scopes | |
|
661 | #should return the last updated issue | |
|
662 | assert_equal 1, Issue.recently_updated.with_limit(1).length | |
|
663 | assert_equal Issue.find(:first, :order => "updated_on DESC"), Issue.recently_updated.with_limit(1).first | |
|
664 | end | |
|
665 | ||
|
666 | def test_on_active_projects_scope | |
|
667 | assert Project.find(2).archive | |
|
668 | ||
|
669 | before = Issue.on_active_project.length | |
|
670 | # test inclusion to results | |
|
671 | issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first) | |
|
672 | assert_equal before + 1, Issue.on_active_project.length | |
|
673 | ||
|
674 | # Move to an archived project | |
|
675 | issue.project = Project.find(2) | |
|
676 | assert issue.save | |
|
677 | assert_equal before, Issue.on_active_project.length | |
|
678 | end | |
|
659 | 679 | end |
@@ -15,6 +15,10 module Redmine | |||
|
15 | 15 | has_many :watchers, :as => :watchable, :dependent => :delete_all |
|
16 | 16 | has_many :watcher_users, :through => :watchers, :source => :user |
|
17 | 17 | |
|
18 | named_scope :watched_by, lambda { |user_id| | |
|
19 | { :include => :watchers, | |
|
20 | :conditions => ["#{Watcher.table_name}.user_id = ?", user_id] } | |
|
21 | } | |
|
18 | 22 | attr_protected :watcher_ids, :watcher_user_ids |
|
19 | 23 | end |
|
20 | 24 | end |
@@ -60,14 +64,7 module Redmine | |||
|
60 | 64 | notified.collect(&:mail).compact |
|
61 | 65 | end |
|
62 | 66 | |
|
63 | module ClassMethods | |
|
64 | # Returns the objects that are watched by user | |
|
65 | def watched_by(user) | |
|
66 | find(:all, | |
|
67 | :include => :watchers, | |
|
68 | :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]) | |
|
69 | end | |
|
70 | end | |
|
67 | module ClassMethods; end | |
|
71 | 68 | end |
|
72 | 69 | end |
|
73 | 70 | end |
General Comments 0
You need to be logged in to leave comments.
Login now