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