Patch #2482 ยป _redmine_-0002-Added-named-scopes-in-Issue-and-ActsAsWatchable-inst.diff
| test/unit/issue_test.rb (working copy) | ||
|---|---|---|
| 203 | 203 |
assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? |
| 204 | 204 |
assert !Issue.new(:due_date => nil).overdue? |
| 205 | 205 |
end |
| 206 | ||
| 207 |
def test_recently_updated_with_limit_scopes |
|
| 208 |
#should return the last updated issue |
|
| 209 |
assert_equal 1, Issue.recently_updated.with_limit(1).size |
|
| 210 |
assert_equal Issue.find(:first, :order => "updated_on DESC"), Issue.recently_updated.with_limit(1).first |
|
| 211 |
end |
|
| 212 | ||
| 213 |
def test_on_active_projects_scope |
|
| 214 |
before = Issue.on_active_project.size |
|
| 215 |
# test inclusion to results |
|
| 216 |
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')
|
|
| 217 |
issue.save! |
|
| 218 |
assert Issue.on_active_project.size == (before + 1) |
|
| 219 | ||
| 220 |
#test exclusion from results |
|
| 221 |
issue.move_to(Project.find(6)) # Move to an archived peoject |
|
| 222 |
issue.reload |
|
| 223 |
assert Issue.on_active_project.size == before |
|
| 224 |
end |
|
| 206 | 225 |
end |
| test/unit/project_test.rb (working copy) | ||
|---|---|---|
| 47 | 47 |
|
| 48 | 48 |
def test_public_projects |
| 49 | 49 |
public_projects = Project.find(:all, :conditions => ["is_public=?", true]) |
| 50 |
assert_equal 3, public_projects.length
|
|
| 50 |
assert_equal 4, public_projects.length
|
|
| 51 | 51 |
assert_equal true, public_projects[0].is_public? |
| 52 | 52 |
end |
| 53 | 53 |
|
| test/fixtures/projects.yml (working copy) | ||
|---|---|---|
| 54 | 54 |
is_public: false |
| 55 | 55 |
identifier: private_child |
| 56 | 56 |
parent_id: 1 |
| 57 |
|
|
| 57 |
projects_006: |
|
| 58 |
created_on: 2006-07-19 19:13:59 +02:00 |
|
| 59 |
name: Dead Project |
|
| 60 |
updated_on: 2006-07-19 22:53:01 +02:00 |
|
| 61 |
projects_count: 0 |
|
| 62 |
id: 6 |
|
| 63 |
description: A vaporware project |
|
| 64 |
homepage: "" |
|
| 65 |
is_public: true |
|
| 66 |
identifier: vaporware |
|
| 67 |
status: <%= Project::STATUS_ARCHIVED %> |
|
| 68 |
parent_id: |
|
| app/models/issue.rb (working copy) | ||
|---|---|---|
| 44 | 44 |
|
| 45 | 45 |
acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
|
| 46 | 46 |
:author_key => :author_id |
| 47 |
|
|
| 47 | ||
| 48 |
named_scope :recently_updated, :order => "#{self.table_name}.updated_on DESC"
|
|
| 49 |
named_scope :with_limit, lambda { |limit| { :limit => limit} }
|
|
| 50 |
named_scope :on_active_project, :include => [:status, :project, :tracker], |
|
| 51 |
:conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
|
|
| 52 | ||
| 48 | 53 |
validates_presence_of :subject, :priority, :project, :tracker, :author, :status |
| 54 | ||
| 49 | 55 |
validates_length_of :subject, :maximum => 255 |
| 50 | 56 |
validates_inclusion_of :done_ratio, :in => 0..100 |
| 51 | 57 |
validates_numericality_of :estimated_hours, :allow_nil => true |
| app/views/my/blocks/_issueswatched.rhtml (working copy) | ||
|---|---|---|
| 1 | 1 |
<h3><%=l(:label_watched_issues)%></h3> |
| 2 |
<% watched_issues = Issue.find(:all, |
|
| 3 |
:include => [:status, :project, :tracker, :watchers], |
|
| 4 |
:limit => 10, |
|
| 5 |
:conditions => ["#{Watcher.table_name}.user_id = ? AND #{Project.table_name}.status=#{Project::STATUS_ACTIVE}", user.id],
|
|
| 6 |
:order => "#{Issue.table_name}.updated_on DESC") %>
|
|
| 2 |
<% watched_issues = Issue.on_active_project.watched_by(user.id).recently_updated.with_limit(10) %> |
|
| 7 | 3 |
<%= render :partial => 'issues/list_simple', :locals => { :issues => watched_issues } %>
|
| 8 | 4 |
<% if watched_issues.length > 0 %> |
| 9 | 5 |
<p><%=lwr(:label_last_updates, watched_issues.length)%></p> |
| vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb (working copy) | ||
|---|---|---|
| 7 | 7 |
end |
| 8 | 8 | |
| 9 | 9 |
module ClassMethods |
| 10 |
# Additional to the instance methods it adds class method watched_by(user) |
|
| 11 |
# which returns the objects that are watched by the _user_ object or _user_id_ |
|
| 12 |
# which is passed as an argument. |
|
| 10 | 13 |
def acts_as_watchable(options = {})
|
| 11 | 14 |
return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) |
| 12 | 15 |
send :include, Redmine::Acts::Watchable::InstanceMethods |
| ... | ... | |
| 15 | 18 |
has_many :watchers, :as => :watchable, :dependent => :delete_all |
| 16 | 19 |
has_many :watcher_users, :through => :watchers, :source => :user |
| 17 | 20 |
|
| 21 |
named_scope :watched_by, lambda { |user|
|
|
| 22 |
{ :include => :watchers,
|
|
| 23 |
:conditions => ["#{Watcher.table_name}.user_id = ?", user] }
|
|
| 24 |
} |
|
| 18 | 25 |
attr_protected :watcher_ids, :watcher_user_ids |
| 19 | 26 |
end |
| 20 | 27 |
end |
| ... | ... | |
| 57 | 64 |
self.watchers.collect { |w| w.user.mail if w.user.active? }.compact
|
| 58 | 65 |
end |
| 59 | 66 | |
| 60 |
module ClassMethods |
|
| 61 |
# Returns the objects that are watched by user |
|
| 62 |
def watched_by(user) |
|
| 63 |
find(:all, |
|
| 64 |
:include => :watchers, |
|
| 65 |
:conditions => ["#{Watcher.table_name}.user_id = ?", user.id])
|
|
| 66 |
end |
|
| 67 |
end |
|
| 67 |
module ClassMethods; end |
|
| 68 | 68 |
end |
| 69 | 69 |
end |
| 70 | 70 |
end |