Chris@909
|
1 # Redmine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class TrackerTest < ActiveSupport::TestCase
|
Chris@1115
|
21 fixtures :trackers, :workflows, :issue_statuses, :roles, :issues
|
Chris@1115
|
22
|
Chris@1115
|
23 def test_sorted_scope
|
Chris@1115
|
24 assert_equal Tracker.all.sort, Tracker.sorted.all
|
Chris@1115
|
25 end
|
Chris@1115
|
26
|
Chris@1115
|
27 def test_named_scope
|
Chris@1115
|
28 assert_equal Tracker.find_by_name('Feature'), Tracker.named('feature').first
|
Chris@1115
|
29 end
|
Chris@0
|
30
|
Chris@0
|
31 def test_copy_workflows
|
Chris@0
|
32 source = Tracker.find(1)
|
Chris@1115
|
33 assert_equal 89, source.workflow_rules.size
|
Chris@909
|
34
|
Chris@0
|
35 target = Tracker.new(:name => 'Target')
|
Chris@0
|
36 assert target.save
|
Chris@1115
|
37 target.workflow_rules.copy(source)
|
Chris@0
|
38 target.reload
|
Chris@1115
|
39 assert_equal 89, target.workflow_rules.size
|
Chris@0
|
40 end
|
Chris@909
|
41
|
Chris@0
|
42 def test_issue_statuses
|
Chris@0
|
43 tracker = Tracker.find(1)
|
Chris@1115
|
44 WorkflowTransition.delete_all
|
Chris@1115
|
45 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
|
Chris@1115
|
46 WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
|
Chris@909
|
47
|
Chris@0
|
48 assert_kind_of Array, tracker.issue_statuses
|
Chris@0
|
49 assert_kind_of IssueStatus, tracker.issue_statuses.first
|
Chris@0
|
50 assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id)
|
Chris@0
|
51 end
|
Chris@909
|
52
|
Chris@0
|
53 def test_issue_statuses_empty
|
Chris@1115
|
54 WorkflowTransition.delete_all("tracker_id = 1")
|
Chris@0
|
55 assert_equal [], Tracker.find(1).issue_statuses
|
Chris@0
|
56 end
|
Chris@1115
|
57
|
Chris@1115
|
58 def test_issue_statuses_should_be_empty_for_new_record
|
Chris@1115
|
59 assert_equal [], Tracker.new.issue_statuses
|
Chris@1115
|
60 end
|
Chris@1115
|
61
|
Chris@1115
|
62 def test_core_fields_should_be_enabled_by_default
|
Chris@1115
|
63 tracker = Tracker.new
|
Chris@1115
|
64 assert_equal Tracker::CORE_FIELDS, tracker.core_fields
|
Chris@1115
|
65 assert_equal [], tracker.disabled_core_fields
|
Chris@1115
|
66 end
|
Chris@1115
|
67
|
Chris@1115
|
68 def test_core_fields
|
Chris@1115
|
69 tracker = Tracker.new
|
Chris@1115
|
70 tracker.core_fields = %w(assigned_to_id due_date)
|
Chris@1115
|
71
|
Chris@1115
|
72 assert_equal %w(assigned_to_id due_date), tracker.core_fields
|
Chris@1115
|
73 assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields
|
Chris@1115
|
74 end
|
Chris@1115
|
75
|
Chris@1115
|
76 def test_core_fields_should_return_fields_enabled_for_any_tracker
|
Chris@1115
|
77 trackers = []
|
Chris@1115
|
78 trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date))
|
Chris@1115
|
79 trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio))
|
Chris@1115
|
80 trackers << Tracker.new(:core_fields => [])
|
Chris@1115
|
81
|
Chris@1115
|
82 assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers)
|
Chris@1115
|
83 assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
|
Chris@1115
|
84 end
|
Chris@1115
|
85
|
Chris@1115
|
86 def test_core_fields_should_return_all_fields_for_an_empty_argument
|
Chris@1115
|
87 assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([])
|
Chris@1115
|
88 assert_equal [], Tracker.disabled_core_fields([])
|
Chris@1115
|
89 end
|
Chris@1115
|
90
|
Chris@1115
|
91 def test_sort_should_sort_by_position
|
Chris@1115
|
92 a = Tracker.new(:name => 'Tracker A', :position => 2)
|
Chris@1115
|
93 b = Tracker.new(:name => 'Tracker B', :position => 1)
|
Chris@1115
|
94
|
Chris@1115
|
95 assert_equal [b, a], [a, b].sort
|
Chris@1115
|
96 end
|
Chris@1115
|
97
|
Chris@1115
|
98 def test_destroying_a_tracker_without_issues_should_not_raise_an_error
|
Chris@1115
|
99 tracker = Tracker.find(1)
|
Chris@1115
|
100 Issue.delete_all :tracker_id => tracker.id
|
Chris@1115
|
101
|
Chris@1115
|
102 assert_difference 'Tracker.count', -1 do
|
Chris@1115
|
103 assert_nothing_raised do
|
Chris@1115
|
104 tracker.destroy
|
Chris@1115
|
105 end
|
Chris@1115
|
106 end
|
Chris@1115
|
107 end
|
Chris@1115
|
108
|
Chris@1115
|
109 def test_destroying_a_tracker_with_issues_should_raise_an_error
|
Chris@1115
|
110 tracker = Tracker.find(1)
|
Chris@1115
|
111
|
Chris@1115
|
112 assert_no_difference 'Tracker.count' do
|
Chris@1115
|
113 assert_raise Exception do
|
Chris@1115
|
114 tracker.destroy
|
Chris@1115
|
115 end
|
Chris@1115
|
116 end
|
Chris@1115
|
117 end
|
Chris@0
|
118 end
|