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