Patch #2482 ยป _redmine_-0002-Added-named-scopes-in-Issue-and-ActsAsWatchable-inst.diff
| test/unit/issue_test.rb (working copy) | ||
|---|---|---|
|
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
|
||
| test/unit/project_test.rb (working copy) | ||
|---|---|---|
|
|
||
|
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
|
||
|
|
||
| test/fixtures/projects.yml (working copy) | ||
|---|---|---|
|
is_public: false
|
||
|
identifier: private_child
|
||
|
parent_id: 1
|
||
|
|
||
|
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:
|
||
| app/models/issue.rb (working copy) | ||
|---|---|---|
|
|
||
|
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
|
||
| app/views/my/blocks/_issueswatched.rhtml (working copy) | ||
|---|---|---|
|
<h3><%=l(:label_watched_issues)%></h3>
|
||
|
<% 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 %>
|
||
|
<p><%=lwr(:label_last_updates, watched_issues.length)%></p>
|
||
| vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb (working copy) | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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
|
||