@@ -1,131 +1,131 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 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.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class TrackerTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :trackers, :workflows, :issue_statuses, :roles, :issues, :projects, :projects_trackers |
|
22 | 22 | |
|
23 | 23 | def test_sorted_scope |
|
24 | 24 | assert_equal Tracker.all.sort, Tracker.sorted.to_a |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_named_scope |
|
28 | 28 | assert_equal Tracker.find_by_name('Feature'), Tracker.named('feature').first |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def test_visible_scope_chained_with_project_rolled_up_trackers |
|
32 | 32 | project = Project.find(1) |
|
33 | 33 | role = Role.generate! |
|
34 | 34 | role.add_permission! :view_issues |
|
35 | 35 | role.set_permission_trackers :view_issues, [2] |
|
36 | 36 | role.save! |
|
37 | 37 | user = User.generate! |
|
38 | 38 | User.add_to_project user, project, role |
|
39 | 39 | |
|
40 | 40 | assert_equal [2], project.rolled_up_trackers(false).visible(user).map(&:id) |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_copy_workflows |
|
44 | 44 | source = Tracker.find(1) |
|
45 | 45 | rules_count = source.workflow_rules.count |
|
46 | 46 | assert rules_count > 0 |
|
47 | 47 | |
|
48 | 48 | target = Tracker.new(:name => 'Target', :default_status_id => 1) |
|
49 | 49 | assert target.save |
|
50 | 50 | target.workflow_rules.copy(source) |
|
51 | 51 | target.reload |
|
52 | 52 | assert_equal rules_count, target.workflow_rules.size |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def test_issue_statuses |
|
56 | 56 | tracker = Tracker.find(1) |
|
57 | 57 | WorkflowTransition.delete_all |
|
58 | 58 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
59 | 59 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
60 | 60 | |
|
61 | 61 | assert_kind_of Array, tracker.issue_statuses |
|
62 | 62 | assert_kind_of IssueStatus, tracker.issue_statuses.first |
|
63 | 63 | assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id) |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_issue_statuses_empty |
|
67 |
WorkflowTransition.delete_all |
|
|
67 | WorkflowTransition.where(:tracker_id => 1).delete_all | |
|
68 | 68 | assert_equal [], Tracker.find(1).issue_statuses |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def test_issue_statuses_should_be_empty_for_new_record |
|
72 | 72 | assert_equal [], Tracker.new.issue_statuses |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def test_core_fields_should_be_enabled_by_default |
|
76 | 76 | tracker = Tracker.new |
|
77 | 77 | assert_equal Tracker::CORE_FIELDS, tracker.core_fields |
|
78 | 78 | assert_equal [], tracker.disabled_core_fields |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def test_core_fields |
|
82 | 82 | tracker = Tracker.new |
|
83 | 83 | tracker.core_fields = %w(assigned_to_id due_date) |
|
84 | 84 | |
|
85 | 85 | assert_equal %w(assigned_to_id due_date), tracker.core_fields |
|
86 | 86 | assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def test_core_fields_should_return_fields_enabled_for_any_tracker |
|
90 | 90 | trackers = [] |
|
91 | 91 | trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date)) |
|
92 | 92 | trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio)) |
|
93 | 93 | trackers << Tracker.new(:core_fields => []) |
|
94 | 94 | |
|
95 | 95 | assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers) |
|
96 | 96 | assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers) |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | def test_core_fields_should_return_all_fields_for_an_empty_argument |
|
100 | 100 | assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([]) |
|
101 | 101 | assert_equal [], Tracker.disabled_core_fields([]) |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def test_sort_should_sort_by_position |
|
105 | 105 | a = Tracker.new(:name => 'Tracker A', :position => 2) |
|
106 | 106 | b = Tracker.new(:name => 'Tracker B', :position => 1) |
|
107 | 107 | |
|
108 | 108 | assert_equal [b, a], [a, b].sort |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def test_destroying_a_tracker_without_issues_should_not_raise_an_error |
|
112 | 112 | tracker = Tracker.find(1) |
|
113 |
Issue. |
|
|
113 | Issue.where(:tracker_id => tracker.id).delete_all | |
|
114 | 114 | |
|
115 | 115 | assert_difference 'Tracker.count', -1 do |
|
116 | 116 | assert_nothing_raised do |
|
117 | 117 | tracker.destroy |
|
118 | 118 | end |
|
119 | 119 | end |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_destroying_a_tracker_with_issues_should_raise_an_error |
|
123 | 123 | tracker = Tracker.find(1) |
|
124 | 124 | |
|
125 | 125 | assert_no_difference 'Tracker.count' do |
|
126 | 126 | assert_raise Exception do |
|
127 | 127 | tracker.destroy |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | end |
|
131 | 131 | end |
General Comments 0
You need to be logged in to leave comments.
Login now