@@ -1,69 +1,69 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class IssueStatus < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | has_many :workflows, :foreign_key => "old_status_id", :dependent => :delete_all |
|
21 | 21 | acts_as_list |
|
22 | 22 | |
|
23 | 23 | validates_presence_of :name |
|
24 | 24 | validates_uniqueness_of :name |
|
25 | 25 | validates_length_of :name, :maximum => 30 |
|
26 | 26 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
27 | 27 | |
|
28 |
def |
|
|
29 |
IssueStatus.update_all |
|
|
28 | def after_save | |
|
29 | IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? | |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | # Returns the default status for new issues |
|
33 | 33 | def self.default |
|
34 | 34 | find(:first, :conditions =>["is_default=?", true]) |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | # Returns an array of all statuses the given role can switch to |
|
38 | 38 | # Uses association cache when called more than one time |
|
39 | 39 | def new_statuses_allowed_to(role, tracker) |
|
40 | 40 | new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker |
|
41 | 41 | new_statuses ? new_statuses.compact.sort{|x, y| x.position <=> y.position } : [] |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | # Same thing as above but uses a database query |
|
45 | 45 | # More efficient than the previous method if called just once |
|
46 | 46 | def find_new_statuses_allowed_to(role, tracker) |
|
47 | 47 | new_statuses = workflows.find(:all, |
|
48 | 48 | :include => :new_status, |
|
49 | 49 | :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact if role && tracker |
|
50 | 50 | new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : [] |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def new_status_allowed_to?(status, role, tracker) |
|
54 | 54 | status && role && tracker ? |
|
55 | 55 | !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => role.id, :tracker_id => tracker.id}).nil? : |
|
56 | 56 | false |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def <=>(status) |
|
60 | 60 | position <=> status.position |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def to_s; name end |
|
64 | 64 | |
|
65 | 65 | private |
|
66 | 66 | def check_integrity |
|
67 | 67 | raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) |
|
68 | 68 | end |
|
69 | 69 | end |
@@ -1,49 +1,56 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class IssueStatusTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :issue_statuses |
|
22 | 22 | |
|
23 | 23 | def test_create |
|
24 | 24 | status = IssueStatus.new :name => "Assigned" |
|
25 | 25 | assert !status.save |
|
26 | 26 | # status name uniqueness |
|
27 | 27 | assert_equal 1, status.errors.count |
|
28 | 28 | |
|
29 | 29 | status.name = "Test Status" |
|
30 | 30 | assert status.save |
|
31 | 31 | assert !status.is_default |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_default |
|
35 | 35 | status = IssueStatus.default |
|
36 | 36 | assert_kind_of IssueStatus, status |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def test_change_default |
|
40 | 40 | status = IssueStatus.find(2) |
|
41 | 41 | assert !status.is_default |
|
42 | 42 | status.is_default = true |
|
43 | 43 | assert status.save |
|
44 | 44 | status.reload |
|
45 | 45 | |
|
46 | 46 | assert_equal status, IssueStatus.default |
|
47 | 47 | assert !IssueStatus.find(1).is_default |
|
48 | 48 | end |
|
49 | ||
|
50 | def test_reorder_should_not_clear_default_status | |
|
51 | status = IssueStatus.default | |
|
52 | status.move_to_bottom | |
|
53 | status.reload | |
|
54 | assert status.is_default? | |
|
55 | end | |
|
49 | 56 | end |
General Comments 0
You need to be logged in to leave comments.
Login now