@@ -1,68 +1,68 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Tracker < ActiveRecord::Base |
|
18 | class Tracker < ActiveRecord::Base | |
19 | before_destroy :check_integrity |
|
19 | before_destroy :check_integrity | |
20 | has_many :issues |
|
20 | has_many :issues | |
21 | has_many :workflows, :dependent => :delete_all do |
|
21 | has_many :workflows, :dependent => :delete_all do | |
22 | def copy(source_tracker) |
|
22 | def copy(source_tracker) | |
23 | Workflow.copy(source_tracker, nil, proxy_association.owner, nil) |
|
23 | Workflow.copy(source_tracker, nil, proxy_association.owner, nil) | |
24 | end |
|
24 | end | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | has_and_belongs_to_many :projects |
|
27 | has_and_belongs_to_many :projects | |
28 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' |
|
28 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' | |
29 | acts_as_list |
|
29 | acts_as_list | |
30 |
|
30 | |||
31 | validates_presence_of :name |
|
31 | validates_presence_of :name | |
32 | validates_uniqueness_of :name |
|
32 | validates_uniqueness_of :name | |
33 | validates_length_of :name, :maximum => 30 |
|
33 | validates_length_of :name, :maximum => 30 | |
34 |
|
34 | |||
35 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} |
|
35 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
36 |
|
36 | |||
37 | def to_s; name end |
|
37 | def to_s; name end | |
38 |
|
38 | |||
39 | def <=>(tracker) |
|
39 | def <=>(tracker) | |
40 |
n |
|
40 | position <=> tracker.position | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def self.all |
|
43 | def self.all | |
44 | find(:all, :order => 'position') |
|
44 | find(:all, :order => 'position') | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | # Returns an array of IssueStatus that are used |
|
47 | # Returns an array of IssueStatus that are used | |
48 | # in the tracker's workflows |
|
48 | # in the tracker's workflows | |
49 | def issue_statuses |
|
49 | def issue_statuses | |
50 | if @issue_statuses |
|
50 | if @issue_statuses | |
51 | return @issue_statuses |
|
51 | return @issue_statuses | |
52 | elsif new_record? |
|
52 | elsif new_record? | |
53 | return [] |
|
53 | return [] | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | ids = Workflow. |
|
56 | ids = Workflow. | |
57 | connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}"). |
|
57 | connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}"). | |
58 | flatten. |
|
58 | flatten. | |
59 | uniq |
|
59 | uniq | |
60 |
|
60 | |||
61 | @issue_statuses = IssueStatus.find_all_by_id(ids).sort |
|
61 | @issue_statuses = IssueStatus.find_all_by_id(ids).sort | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | private |
|
64 | private | |
65 | def check_integrity |
|
65 | def check_integrity | |
66 | raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) |
|
66 | raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end |
@@ -1,53 +1,60 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class TrackerTest < ActiveSupport::TestCase |
|
20 | class TrackerTest < ActiveSupport::TestCase | |
21 | fixtures :trackers, :workflows, :issue_statuses, :roles |
|
21 | fixtures :trackers, :workflows, :issue_statuses, :roles | |
22 |
|
22 | |||
23 | def test_copy_workflows |
|
23 | def test_copy_workflows | |
24 | source = Tracker.find(1) |
|
24 | source = Tracker.find(1) | |
25 | assert_equal 89, source.workflows.size |
|
25 | assert_equal 89, source.workflows.size | |
26 |
|
26 | |||
27 | target = Tracker.new(:name => 'Target') |
|
27 | target = Tracker.new(:name => 'Target') | |
28 | assert target.save |
|
28 | assert target.save | |
29 | target.workflows.copy(source) |
|
29 | target.workflows.copy(source) | |
30 | target.reload |
|
30 | target.reload | |
31 | assert_equal 89, target.workflows.size |
|
31 | assert_equal 89, target.workflows.size | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_issue_statuses |
|
34 | def test_issue_statuses | |
35 | tracker = Tracker.find(1) |
|
35 | tracker = Tracker.find(1) | |
36 | Workflow.delete_all |
|
36 | Workflow.delete_all | |
37 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
37 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) | |
38 | Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
38 | Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) | |
39 |
|
39 | |||
40 | assert_kind_of Array, tracker.issue_statuses |
|
40 | assert_kind_of Array, tracker.issue_statuses | |
41 | assert_kind_of IssueStatus, tracker.issue_statuses.first |
|
41 | assert_kind_of IssueStatus, tracker.issue_statuses.first | |
42 | assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id) |
|
42 | assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id) | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_issue_statuses_empty |
|
45 | def test_issue_statuses_empty | |
46 | Workflow.delete_all("tracker_id = 1") |
|
46 | Workflow.delete_all("tracker_id = 1") | |
47 | assert_equal [], Tracker.find(1).issue_statuses |
|
47 | assert_equal [], Tracker.find(1).issue_statuses | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_issue_statuses_should_be_empty_for_new_record |
|
50 | def test_issue_statuses_should_be_empty_for_new_record | |
51 | assert_equal [], Tracker.new.issue_statuses |
|
51 | assert_equal [], Tracker.new.issue_statuses | |
52 | end |
|
52 | end | |
|
53 | ||||
|
54 | def test_sort_should_sort_by_position | |||
|
55 | a = Tracker.new(:name => 'Tracker A', :position => 2) | |||
|
56 | b = Tracker.new(:name => 'Tracker B', :position => 1) | |||
|
57 | ||||
|
58 | assert_equal [b, a], [a, b].sort | |||
|
59 | end | |||
53 | end |
|
60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now