Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9981 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
7c6582009a
commit
6c1db9c3a8
@ -28,23 +28,22 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
|
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
|
||||||
|
|
||||||
scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
scope :named, lambda {|arg| where(["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip])}
|
||||||
|
|
||||||
def update_default
|
def update_default
|
||||||
IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
|
IssueStatus.update_all({:is_default => false}, ['id <> ?', id]) if self.is_default?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the default status for new issues
|
# Returns the default status for new issues
|
||||||
def self.default
|
def self.default
|
||||||
find(:first, :conditions =>["is_default=?", true])
|
where(:is_default => true).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
|
# Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
|
||||||
def self.update_issue_done_ratios
|
def self.update_issue_done_ratios
|
||||||
if Issue.use_status_for_done_ratio?
|
if Issue.use_status_for_done_ratio?
|
||||||
IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status|
|
IssueStatus.where("default_done_ratio >= 0").all.each do |status|
|
||||||
Issue.update_all(["done_ratio = ?", status.default_done_ratio],
|
Issue.update_all({:done_ratio => status.default_done_ratio}, {:status_id => status.id})
|
||||||
["status_id = ?", status.id])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
w.tracker_id == tracker.id &&
|
w.tracker_id == tracker.id &&
|
||||||
((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee))
|
((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee))
|
||||||
end
|
end
|
||||||
transitions.collect{|w| w.new_status}.compact.sort
|
transitions.map(&:new_status).compact.sort
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@ -75,12 +74,12 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
conditions << " OR author = :true" if author
|
conditions << " OR author = :true" if author
|
||||||
conditions << " OR assignee = :true" if assignee
|
conditions << " OR assignee = :true" if assignee
|
||||||
|
|
||||||
workflows.find(:all,
|
workflows.
|
||||||
:include => :new_status,
|
includes(:new_status).
|
||||||
:conditions => ["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
|
where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
|
||||||
{:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
|
{:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
|
||||||
]
|
]).all.
|
||||||
).collect{|w| w.new_status}.compact.sort
|
map(&:new_status).compact.sort
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@ -93,8 +92,9 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
def to_s; name end
|
def to_s; name end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_integrity
|
def check_integrity
|
||||||
raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
|
raise "Can't delete status" if Issue.where(:status_id => id).any?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Deletes associated workflows
|
# Deletes associated workflows
|
||||||
|
@ -111,4 +111,10 @@ class IssueStatusTest < ActiveSupport::TestCase
|
|||||||
assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq
|
assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_named_scope
|
||||||
|
status = IssueStatus.named("resolved").first
|
||||||
|
assert_not_nil status
|
||||||
|
assert_equal "Resolved", status.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user