@@ -28,23 +28,22 class IssueStatus < ActiveRecord::Base | |||||
28 | validates_length_of :name, :maximum => 30 |
|
28 | validates_length_of :name, :maximum => 30 | |
29 | validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true |
|
29 | validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true | |
30 |
|
30 | |||
31 |
scope :named, lambda {|arg| |
|
31 | scope :named, lambda {|arg| where(["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip])} | |
32 |
|
32 | |||
33 | def update_default |
|
33 | def update_default | |
34 |
IssueStatus.update_all( |
|
34 | IssueStatus.update_all({:is_default => false}, ['id <> ?', id]) if self.is_default? | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | # Returns the default status for new issues |
|
37 | # Returns the default status for new issues | |
38 | def self.default |
|
38 | def self.default | |
39 | find(:first, :conditions =>["is_default=?", true]) |
|
39 | where(:is_default => true).first | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+ |
|
42 | # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+ | |
43 | def self.update_issue_done_ratios |
|
43 | def self.update_issue_done_ratios | |
44 | if Issue.use_status_for_done_ratio? |
|
44 | if Issue.use_status_for_done_ratio? | |
45 |
IssueStatus. |
|
45 | IssueStatus.where("default_done_ratio >= 0").all.each do |status| | |
46 |
Issue.update_all( |
|
46 | Issue.update_all({:done_ratio => status.default_done_ratio}, {:status_id => status.id}) | |
47 | ["status_id = ?", status.id]) |
|
|||
48 | end |
|
47 | end | |
49 | end |
|
48 | end | |
50 |
|
49 | |||
@@ -61,7 +60,7 class IssueStatus < ActiveRecord::Base | |||||
61 | w.tracker_id == tracker.id && |
|
60 | w.tracker_id == tracker.id && | |
62 | ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee)) |
|
61 | ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee)) | |
63 | end |
|
62 | end | |
64 |
transitions. |
|
63 | transitions.map(&:new_status).compact.sort | |
65 | else |
|
64 | else | |
66 | [] |
|
65 | [] | |
67 | end |
|
66 | end | |
@@ -75,12 +74,12 class IssueStatus < ActiveRecord::Base | |||||
75 | conditions << " OR author = :true" if author |
|
74 | conditions << " OR author = :true" if author | |
76 | conditions << " OR assignee = :true" if assignee |
|
75 | conditions << " OR assignee = :true" if assignee | |
77 |
|
76 | |||
78 |
workflows. |
|
77 | workflows. | |
79 |
|
|
78 | includes(:new_status). | |
80 |
|
|
79 | where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})", | |
81 | {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false} |
|
80 | {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false} | |
82 | ] |
|
81 | ]).all. | |
83 |
) |
|
82 | map(&:new_status).compact.sort | |
84 | else |
|
83 | else | |
85 | [] |
|
84 | [] | |
86 | end |
|
85 | end | |
@@ -92,9 +91,10 class IssueStatus < ActiveRecord::Base | |||||
92 |
|
91 | |||
93 | def to_s; name end |
|
92 | def to_s; name end | |
94 |
|
93 | |||
95 | private |
|
94 | private | |
|
95 | ||||
96 | def check_integrity |
|
96 | def check_integrity | |
97 |
raise "Can't delete status" if Issue. |
|
97 | raise "Can't delete status" if Issue.where(:status_id => id).any? | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | # Deletes associated workflows |
|
100 | # Deletes associated workflows |
@@ -111,4 +111,10 class IssueStatusTest < ActiveSupport::TestCase | |||||
111 | assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq |
|
111 | assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq | |
112 | end |
|
112 | end | |
113 | end |
|
113 | end | |
|
114 | ||||
|
115 | def test_named_scope | |||
|
116 | status = IssueStatus.named("resolved").first | |||
|
117 | assert_not_nil status | |||
|
118 | assert_equal "Resolved", status.name | |||
|
119 | end | |||
114 | end |
|
120 | end |
General Comments 0
You need to be logged in to leave comments.
Login now