@@ -1,1542 +1,1541 | |||||
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 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class IssueTest < ActiveSupport::TestCase |
|
20 | class IssueTest < ActiveSupport::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, | |
22 | :groups_users, |
|
22 | :groups_users, | |
23 | :trackers, :projects_trackers, |
|
23 | :trackers, :projects_trackers, | |
24 | :enabled_modules, |
|
24 | :enabled_modules, | |
25 | :versions, |
|
25 | :versions, | |
26 | :issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
26 | :issue_statuses, :issue_categories, :issue_relations, :workflows, | |
27 | :enumerations, |
|
27 | :enumerations, | |
28 | :issues, |
|
28 | :issues, | |
29 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
|
29 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | |
30 | :time_entries |
|
30 | :time_entries | |
31 |
|
31 | |||
32 | include Redmine::I18n |
|
32 | include Redmine::I18n | |
33 |
|
33 | |||
34 | def teardown |
|
34 | def teardown | |
35 | User.current = nil |
|
35 | User.current = nil | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_create |
|
38 | def test_create | |
39 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
39 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
40 | :status_id => 1, :priority => IssuePriority.all.first, |
|
40 | :status_id => 1, :priority => IssuePriority.all.first, | |
41 | :subject => 'test_create', |
|
41 | :subject => 'test_create', | |
42 | :description => 'IssueTest#test_create', :estimated_hours => '1:30') |
|
42 | :description => 'IssueTest#test_create', :estimated_hours => '1:30') | |
43 | assert issue.save |
|
43 | assert issue.save | |
44 | issue.reload |
|
44 | issue.reload | |
45 | assert_equal 1.5, issue.estimated_hours |
|
45 | assert_equal 1.5, issue.estimated_hours | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_create_minimal |
|
48 | def test_create_minimal | |
49 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
49 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
50 | :status_id => 1, :priority => IssuePriority.all.first, |
|
50 | :status_id => 1, :priority => IssuePriority.all.first, | |
51 | :subject => 'test_create') |
|
51 | :subject => 'test_create') | |
52 | assert issue.save |
|
52 | assert issue.save | |
53 | assert issue.description.nil? |
|
53 | assert issue.description.nil? | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_create_with_required_custom_field |
|
56 | def test_create_with_required_custom_field | |
57 | set_language_if_valid 'en' |
|
57 | set_language_if_valid 'en' | |
58 | field = IssueCustomField.find_by_name('Database') |
|
58 | field = IssueCustomField.find_by_name('Database') | |
59 | field.update_attribute(:is_required, true) |
|
59 | field.update_attribute(:is_required, true) | |
60 |
|
60 | |||
61 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, |
|
61 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
62 | :status_id => 1, :subject => 'test_create', |
|
62 | :status_id => 1, :subject => 'test_create', | |
63 | :description => 'IssueTest#test_create_with_required_custom_field') |
|
63 | :description => 'IssueTest#test_create_with_required_custom_field') | |
64 | assert issue.available_custom_fields.include?(field) |
|
64 | assert issue.available_custom_fields.include?(field) | |
65 | # No value for the custom field |
|
65 | # No value for the custom field | |
66 | assert !issue.save |
|
66 | assert !issue.save | |
67 | assert_equal ["Database can't be blank"], issue.errors.full_messages |
|
67 | assert_equal ["Database can't be blank"], issue.errors.full_messages | |
68 | # Blank value |
|
68 | # Blank value | |
69 | issue.custom_field_values = { field.id => '' } |
|
69 | issue.custom_field_values = { field.id => '' } | |
70 | assert !issue.save |
|
70 | assert !issue.save | |
71 | assert_equal ["Database can't be blank"], issue.errors.full_messages |
|
71 | assert_equal ["Database can't be blank"], issue.errors.full_messages | |
72 | # Invalid value |
|
72 | # Invalid value | |
73 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
73 | issue.custom_field_values = { field.id => 'SQLServer' } | |
74 | assert !issue.save |
|
74 | assert !issue.save | |
75 | assert_equal ["Database is not included in the list"], issue.errors.full_messages |
|
75 | assert_equal ["Database is not included in the list"], issue.errors.full_messages | |
76 | # Valid value |
|
76 | # Valid value | |
77 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
77 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
78 | assert issue.save |
|
78 | assert issue.save | |
79 | issue.reload |
|
79 | issue.reload | |
80 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
80 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def test_create_with_group_assignment |
|
83 | def test_create_with_group_assignment | |
84 | with_settings :issue_group_assignment => '1' do |
|
84 | with_settings :issue_group_assignment => '1' do | |
85 | assert Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, |
|
85 | assert Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, | |
86 | :subject => 'Group assignment', |
|
86 | :subject => 'Group assignment', | |
87 | :assigned_to_id => 11).save |
|
87 | :assigned_to_id => 11).save | |
88 | issue = Issue.first(:order => 'id DESC') |
|
88 | issue = Issue.first(:order => 'id DESC') | |
89 | assert_kind_of Group, issue.assigned_to |
|
89 | assert_kind_of Group, issue.assigned_to | |
90 | assert_equal Group.find(11), issue.assigned_to |
|
90 | assert_equal Group.find(11), issue.assigned_to | |
91 | end |
|
91 | end | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def assert_visibility_match(user, issues) |
|
94 | def assert_visibility_match(user, issues) | |
95 | assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort |
|
95 | assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_visible_scope_for_anonymous |
|
98 | def test_visible_scope_for_anonymous | |
99 | # Anonymous user should see issues of public projects only |
|
99 | # Anonymous user should see issues of public projects only | |
100 | issues = Issue.visible(User.anonymous).all |
|
100 | issues = Issue.visible(User.anonymous).all | |
101 | assert issues.any? |
|
101 | assert issues.any? | |
102 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
102 | assert_nil issues.detect {|issue| !issue.project.is_public?} | |
103 | assert_nil issues.detect {|issue| issue.is_private?} |
|
103 | assert_nil issues.detect {|issue| issue.is_private?} | |
104 | assert_visibility_match User.anonymous, issues |
|
104 | assert_visibility_match User.anonymous, issues | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_visible_scope_for_anonymous_with_own_issues_visibility |
|
107 | def test_visible_scope_for_anonymous_with_own_issues_visibility | |
108 | Role.anonymous.update_attribute :issues_visibility, 'own' |
|
108 | Role.anonymous.update_attribute :issues_visibility, 'own' | |
109 | Issue.create!(:project_id => 1, :tracker_id => 1, |
|
109 | Issue.create!(:project_id => 1, :tracker_id => 1, | |
110 | :author_id => User.anonymous.id, |
|
110 | :author_id => User.anonymous.id, | |
111 | :subject => 'Issue by anonymous') |
|
111 | :subject => 'Issue by anonymous') | |
112 |
|
112 | |||
113 | issues = Issue.visible(User.anonymous).all |
|
113 | issues = Issue.visible(User.anonymous).all | |
114 | assert issues.any? |
|
114 | assert issues.any? | |
115 | assert_nil issues.detect {|issue| issue.author != User.anonymous} |
|
115 | assert_nil issues.detect {|issue| issue.author != User.anonymous} | |
116 | assert_visibility_match User.anonymous, issues |
|
116 | assert_visibility_match User.anonymous, issues | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_visible_scope_for_anonymous_without_view_issues_permissions |
|
119 | def test_visible_scope_for_anonymous_without_view_issues_permissions | |
120 | # Anonymous user should not see issues without permission |
|
120 | # Anonymous user should not see issues without permission | |
121 | Role.anonymous.remove_permission!(:view_issues) |
|
121 | Role.anonymous.remove_permission!(:view_issues) | |
122 | issues = Issue.visible(User.anonymous).all |
|
122 | issues = Issue.visible(User.anonymous).all | |
123 | assert issues.empty? |
|
123 | assert issues.empty? | |
124 | assert_visibility_match User.anonymous, issues |
|
124 | assert_visibility_match User.anonymous, issues | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_visible_scope_for_non_member |
|
127 | def test_visible_scope_for_non_member | |
128 | user = User.find(9) |
|
128 | user = User.find(9) | |
129 | assert user.projects.empty? |
|
129 | assert user.projects.empty? | |
130 | # Non member user should see issues of public projects only |
|
130 | # Non member user should see issues of public projects only | |
131 | issues = Issue.visible(user).all |
|
131 | issues = Issue.visible(user).all | |
132 | assert issues.any? |
|
132 | assert issues.any? | |
133 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
133 | assert_nil issues.detect {|issue| !issue.project.is_public?} | |
134 | assert_nil issues.detect {|issue| issue.is_private?} |
|
134 | assert_nil issues.detect {|issue| issue.is_private?} | |
135 | assert_visibility_match user, issues |
|
135 | assert_visibility_match user, issues | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def test_visible_scope_for_non_member_with_own_issues_visibility |
|
138 | def test_visible_scope_for_non_member_with_own_issues_visibility | |
139 | Role.non_member.update_attribute :issues_visibility, 'own' |
|
139 | Role.non_member.update_attribute :issues_visibility, 'own' | |
140 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') |
|
140 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') | |
141 | user = User.find(9) |
|
141 | user = User.find(9) | |
142 |
|
142 | |||
143 | issues = Issue.visible(user).all |
|
143 | issues = Issue.visible(user).all | |
144 | assert issues.any? |
|
144 | assert issues.any? | |
145 | assert_nil issues.detect {|issue| issue.author != user} |
|
145 | assert_nil issues.detect {|issue| issue.author != user} | |
146 | assert_visibility_match user, issues |
|
146 | assert_visibility_match user, issues | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def test_visible_scope_for_non_member_without_view_issues_permissions |
|
149 | def test_visible_scope_for_non_member_without_view_issues_permissions | |
150 | # Non member user should not see issues without permission |
|
150 | # Non member user should not see issues without permission | |
151 | Role.non_member.remove_permission!(:view_issues) |
|
151 | Role.non_member.remove_permission!(:view_issues) | |
152 | user = User.find(9) |
|
152 | user = User.find(9) | |
153 | assert user.projects.empty? |
|
153 | assert user.projects.empty? | |
154 | issues = Issue.visible(user).all |
|
154 | issues = Issue.visible(user).all | |
155 | assert issues.empty? |
|
155 | assert issues.empty? | |
156 | assert_visibility_match user, issues |
|
156 | assert_visibility_match user, issues | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def test_visible_scope_for_member |
|
159 | def test_visible_scope_for_member | |
160 | user = User.find(9) |
|
160 | user = User.find(9) | |
161 | # User should see issues of projects for which he has view_issues permissions only |
|
161 | # User should see issues of projects for which he has view_issues permissions only | |
162 | Role.non_member.remove_permission!(:view_issues) |
|
162 | Role.non_member.remove_permission!(:view_issues) | |
163 | Member.create!(:principal => user, :project_id => 3, :role_ids => [2]) |
|
163 | Member.create!(:principal => user, :project_id => 3, :role_ids => [2]) | |
164 | issues = Issue.visible(user).all |
|
164 | issues = Issue.visible(user).all | |
165 | assert issues.any? |
|
165 | assert issues.any? | |
166 | assert_nil issues.detect {|issue| issue.project_id != 3} |
|
166 | assert_nil issues.detect {|issue| issue.project_id != 3} | |
167 | assert_nil issues.detect {|issue| issue.is_private?} |
|
167 | assert_nil issues.detect {|issue| issue.is_private?} | |
168 | assert_visibility_match user, issues |
|
168 | assert_visibility_match user, issues | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | def test_visible_scope_for_member_with_groups_should_return_assigned_issues |
|
171 | def test_visible_scope_for_member_with_groups_should_return_assigned_issues | |
172 | user = User.find(8) |
|
172 | user = User.find(8) | |
173 | assert user.groups.any? |
|
173 | assert user.groups.any? | |
174 | Member.create!(:principal => user.groups.first, :project_id => 1, :role_ids => [2]) |
|
174 | Member.create!(:principal => user.groups.first, :project_id => 1, :role_ids => [2]) | |
175 | Role.non_member.remove_permission!(:view_issues) |
|
175 | Role.non_member.remove_permission!(:view_issues) | |
176 |
|
176 | |||
177 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
177 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
178 | :status_id => 1, :priority => IssuePriority.all.first, |
|
178 | :status_id => 1, :priority => IssuePriority.all.first, | |
179 | :subject => 'Assignment test', |
|
179 | :subject => 'Assignment test', | |
180 | :assigned_to => user.groups.first, |
|
180 | :assigned_to => user.groups.first, | |
181 | :is_private => true) |
|
181 | :is_private => true) | |
182 |
|
182 | |||
183 | Role.find(2).update_attribute :issues_visibility, 'default' |
|
183 | Role.find(2).update_attribute :issues_visibility, 'default' | |
184 | issues = Issue.visible(User.find(8)).all |
|
184 | issues = Issue.visible(User.find(8)).all | |
185 | assert issues.any? |
|
185 | assert issues.any? | |
186 | assert issues.include?(issue) |
|
186 | assert issues.include?(issue) | |
187 |
|
187 | |||
188 | Role.find(2).update_attribute :issues_visibility, 'own' |
|
188 | Role.find(2).update_attribute :issues_visibility, 'own' | |
189 | issues = Issue.visible(User.find(8)).all |
|
189 | issues = Issue.visible(User.find(8)).all | |
190 | assert issues.any? |
|
190 | assert issues.any? | |
191 | assert issues.include?(issue) |
|
191 | assert issues.include?(issue) | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def test_visible_scope_for_admin |
|
194 | def test_visible_scope_for_admin | |
195 | user = User.find(1) |
|
195 | user = User.find(1) | |
196 | user.members.each(&:destroy) |
|
196 | user.members.each(&:destroy) | |
197 | assert user.projects.empty? |
|
197 | assert user.projects.empty? | |
198 | issues = Issue.visible(user).all |
|
198 | issues = Issue.visible(user).all | |
199 | assert issues.any? |
|
199 | assert issues.any? | |
200 | # Admin should see issues on private projects that he does not belong to |
|
200 | # Admin should see issues on private projects that he does not belong to | |
201 | assert issues.detect {|issue| !issue.project.is_public?} |
|
201 | assert issues.detect {|issue| !issue.project.is_public?} | |
202 | # Admin should see private issues of other users |
|
202 | # Admin should see private issues of other users | |
203 | assert issues.detect {|issue| issue.is_private? && issue.author != user} |
|
203 | assert issues.detect {|issue| issue.is_private? && issue.author != user} | |
204 | assert_visibility_match user, issues |
|
204 | assert_visibility_match user, issues | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | def test_visible_scope_with_project |
|
207 | def test_visible_scope_with_project | |
208 | project = Project.find(1) |
|
208 | project = Project.find(1) | |
209 | issues = Issue.visible(User.find(2), :project => project).all |
|
209 | issues = Issue.visible(User.find(2), :project => project).all | |
210 | projects = issues.collect(&:project).uniq |
|
210 | projects = issues.collect(&:project).uniq | |
211 | assert_equal 1, projects.size |
|
211 | assert_equal 1, projects.size | |
212 | assert_equal project, projects.first |
|
212 | assert_equal project, projects.first | |
213 | end |
|
213 | end | |
214 |
|
214 | |||
215 | def test_visible_scope_with_project_and_subprojects |
|
215 | def test_visible_scope_with_project_and_subprojects | |
216 | project = Project.find(1) |
|
216 | project = Project.find(1) | |
217 | issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all |
|
217 | issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all | |
218 | projects = issues.collect(&:project).uniq |
|
218 | projects = issues.collect(&:project).uniq | |
219 | assert projects.size > 1 |
|
219 | assert projects.size > 1 | |
220 | assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} |
|
220 | assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} | |
221 | end |
|
221 | end | |
222 |
|
222 | |||
223 | def test_visible_and_nested_set_scopes |
|
223 | def test_visible_and_nested_set_scopes | |
224 | assert_equal 0, Issue.find(1).descendants.visible.all.size |
|
224 | assert_equal 0, Issue.find(1).descendants.visible.all.size | |
225 | end |
|
225 | end | |
226 |
|
226 | |||
227 | def test_open_scope |
|
227 | def test_open_scope | |
228 | issues = Issue.open.all |
|
228 | issues = Issue.open.all | |
229 | assert_nil issues.detect(&:closed?) |
|
229 | assert_nil issues.detect(&:closed?) | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | def test_open_scope_with_arg |
|
232 | def test_open_scope_with_arg | |
233 | issues = Issue.open(false).all |
|
233 | issues = Issue.open(false).all | |
234 | assert_equal issues, issues.select(&:closed?) |
|
234 | assert_equal issues, issues.select(&:closed?) | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | def test_errors_full_messages_should_include_custom_fields_errors |
|
237 | def test_errors_full_messages_should_include_custom_fields_errors | |
238 | field = IssueCustomField.find_by_name('Database') |
|
238 | field = IssueCustomField.find_by_name('Database') | |
239 |
|
239 | |||
240 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, |
|
240 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
241 | :status_id => 1, :subject => 'test_create', |
|
241 | :status_id => 1, :subject => 'test_create', | |
242 | :description => 'IssueTest#test_create_with_required_custom_field') |
|
242 | :description => 'IssueTest#test_create_with_required_custom_field') | |
243 | assert issue.available_custom_fields.include?(field) |
|
243 | assert issue.available_custom_fields.include?(field) | |
244 | # Invalid value |
|
244 | # Invalid value | |
245 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
245 | issue.custom_field_values = { field.id => 'SQLServer' } | |
246 |
|
246 | |||
247 | assert !issue.valid? |
|
247 | assert !issue.valid? | |
248 | assert_equal 1, issue.errors.full_messages.size |
|
248 | assert_equal 1, issue.errors.full_messages.size | |
249 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", |
|
249 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", | |
250 | issue.errors.full_messages.first |
|
250 | issue.errors.full_messages.first | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
253 | def test_update_issue_with_required_custom_field |
|
253 | def test_update_issue_with_required_custom_field | |
254 | field = IssueCustomField.find_by_name('Database') |
|
254 | field = IssueCustomField.find_by_name('Database') | |
255 | field.update_attribute(:is_required, true) |
|
255 | field.update_attribute(:is_required, true) | |
256 |
|
256 | |||
257 | issue = Issue.find(1) |
|
257 | issue = Issue.find(1) | |
258 | assert_nil issue.custom_value_for(field) |
|
258 | assert_nil issue.custom_value_for(field) | |
259 | assert issue.available_custom_fields.include?(field) |
|
259 | assert issue.available_custom_fields.include?(field) | |
260 | # No change to custom values, issue can be saved |
|
260 | # No change to custom values, issue can be saved | |
261 | assert issue.save |
|
261 | assert issue.save | |
262 | # Blank value |
|
262 | # Blank value | |
263 | issue.custom_field_values = { field.id => '' } |
|
263 | issue.custom_field_values = { field.id => '' } | |
264 | assert !issue.save |
|
264 | assert !issue.save | |
265 | # Valid value |
|
265 | # Valid value | |
266 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
266 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
267 | assert issue.save |
|
267 | assert issue.save | |
268 | issue.reload |
|
268 | issue.reload | |
269 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
269 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
270 | end |
|
270 | end | |
271 |
|
271 | |||
272 | def test_should_not_update_attributes_if_custom_fields_validation_fails |
|
272 | def test_should_not_update_attributes_if_custom_fields_validation_fails | |
273 | issue = Issue.find(1) |
|
273 | issue = Issue.find(1) | |
274 | field = IssueCustomField.find_by_name('Database') |
|
274 | field = IssueCustomField.find_by_name('Database') | |
275 | assert issue.available_custom_fields.include?(field) |
|
275 | assert issue.available_custom_fields.include?(field) | |
276 |
|
276 | |||
277 | issue.custom_field_values = { field.id => 'Invalid' } |
|
277 | issue.custom_field_values = { field.id => 'Invalid' } | |
278 | issue.subject = 'Should be not be saved' |
|
278 | issue.subject = 'Should be not be saved' | |
279 | assert !issue.save |
|
279 | assert !issue.save | |
280 |
|
280 | |||
281 | issue.reload |
|
281 | issue.reload | |
282 | assert_equal "Can't print recipes", issue.subject |
|
282 | assert_equal "Can't print recipes", issue.subject | |
283 | end |
|
283 | end | |
284 |
|
284 | |||
285 | def test_should_not_recreate_custom_values_objects_on_update |
|
285 | def test_should_not_recreate_custom_values_objects_on_update | |
286 | field = IssueCustomField.find_by_name('Database') |
|
286 | field = IssueCustomField.find_by_name('Database') | |
287 |
|
287 | |||
288 | issue = Issue.find(1) |
|
288 | issue = Issue.find(1) | |
289 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
289 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
290 | assert issue.save |
|
290 | assert issue.save | |
291 | custom_value = issue.custom_value_for(field) |
|
291 | custom_value = issue.custom_value_for(field) | |
292 | issue.reload |
|
292 | issue.reload | |
293 | issue.custom_field_values = { field.id => 'MySQL' } |
|
293 | issue.custom_field_values = { field.id => 'MySQL' } | |
294 | assert issue.save |
|
294 | assert issue.save | |
295 | issue.reload |
|
295 | issue.reload | |
296 | assert_equal custom_value.id, issue.custom_value_for(field).id |
|
296 | assert_equal custom_value.id, issue.custom_value_for(field).id | |
297 | end |
|
297 | end | |
298 |
|
298 | |||
299 | def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields |
|
299 | def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields | |
300 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'}) |
|
300 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'}) | |
301 | assert !Tracker.find(2).custom_field_ids.include?(2) |
|
301 | assert !Tracker.find(2).custom_field_ids.include?(2) | |
302 |
|
302 | |||
303 | issue = Issue.find(issue.id) |
|
303 | issue = Issue.find(issue.id) | |
304 | issue.attributes = {:tracker_id => 2, :custom_field_values => {'1' => ''}} |
|
304 | issue.attributes = {:tracker_id => 2, :custom_field_values => {'1' => ''}} | |
305 |
|
305 | |||
306 | issue = Issue.find(issue.id) |
|
306 | issue = Issue.find(issue.id) | |
307 | custom_value = issue.custom_value_for(2) |
|
307 | custom_value = issue.custom_value_for(2) | |
308 | assert_not_nil custom_value |
|
308 | assert_not_nil custom_value | |
309 | assert_equal 'Test', custom_value.value |
|
309 | assert_equal 'Test', custom_value.value | |
310 | end |
|
310 | end | |
311 |
|
311 | |||
312 | def test_assigning_tracker_id_should_reload_custom_fields_values |
|
312 | def test_assigning_tracker_id_should_reload_custom_fields_values | |
313 | issue = Issue.new(:project => Project.find(1)) |
|
313 | issue = Issue.new(:project => Project.find(1)) | |
314 | assert issue.custom_field_values.empty? |
|
314 | assert issue.custom_field_values.empty? | |
315 | issue.tracker_id = 1 |
|
315 | issue.tracker_id = 1 | |
316 | assert issue.custom_field_values.any? |
|
316 | assert issue.custom_field_values.any? | |
317 | end |
|
317 | end | |
318 |
|
318 | |||
319 | def test_assigning_attributes_should_assign_project_and_tracker_first |
|
319 | def test_assigning_attributes_should_assign_project_and_tracker_first | |
320 | seq = sequence('seq') |
|
320 | seq = sequence('seq') | |
321 | issue = Issue.new |
|
321 | issue = Issue.new | |
322 | issue.expects(:project_id=).in_sequence(seq) |
|
322 | issue.expects(:project_id=).in_sequence(seq) | |
323 | issue.expects(:tracker_id=).in_sequence(seq) |
|
323 | issue.expects(:tracker_id=).in_sequence(seq) | |
324 | issue.expects(:subject=).in_sequence(seq) |
|
324 | issue.expects(:subject=).in_sequence(seq) | |
325 | issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'} |
|
325 | issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'} | |
326 | end |
|
326 | end | |
327 |
|
327 | |||
328 | def test_assigning_tracker_and_custom_fields_should_assign_custom_fields |
|
328 | def test_assigning_tracker_and_custom_fields_should_assign_custom_fields | |
329 | attributes = ActiveSupport::OrderedHash.new |
|
329 | attributes = ActiveSupport::OrderedHash.new | |
330 | attributes['custom_field_values'] = { '1' => 'MySQL' } |
|
330 | attributes['custom_field_values'] = { '1' => 'MySQL' } | |
331 | attributes['tracker_id'] = '1' |
|
331 | attributes['tracker_id'] = '1' | |
332 | issue = Issue.new(:project => Project.find(1)) |
|
332 | issue = Issue.new(:project => Project.find(1)) | |
333 | issue.attributes = attributes |
|
333 | issue.attributes = attributes | |
334 | assert_equal 'MySQL', issue.custom_field_value(1) |
|
334 | assert_equal 'MySQL', issue.custom_field_value(1) | |
335 | end |
|
335 | end | |
336 |
|
336 | |||
337 | def test_should_update_issue_with_disabled_tracker |
|
337 | def test_should_update_issue_with_disabled_tracker | |
338 | p = Project.find(1) |
|
338 | p = Project.find(1) | |
339 | issue = Issue.find(1) |
|
339 | issue = Issue.find(1) | |
340 |
|
340 | |||
341 | p.trackers.delete(issue.tracker) |
|
341 | p.trackers.delete(issue.tracker) | |
342 | assert !p.trackers.include?(issue.tracker) |
|
342 | assert !p.trackers.include?(issue.tracker) | |
343 |
|
343 | |||
344 | issue.reload |
|
344 | issue.reload | |
345 | issue.subject = 'New subject' |
|
345 | issue.subject = 'New subject' | |
346 | assert issue.save |
|
346 | assert issue.save | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | def test_should_not_set_a_disabled_tracker |
|
349 | def test_should_not_set_a_disabled_tracker | |
350 | p = Project.find(1) |
|
350 | p = Project.find(1) | |
351 | p.trackers.delete(Tracker.find(2)) |
|
351 | p.trackers.delete(Tracker.find(2)) | |
352 |
|
352 | |||
353 | issue = Issue.find(1) |
|
353 | issue = Issue.find(1) | |
354 | issue.tracker_id = 2 |
|
354 | issue.tracker_id = 2 | |
355 | issue.subject = 'New subject' |
|
355 | issue.subject = 'New subject' | |
356 | assert !issue.save |
|
356 | assert !issue.save | |
357 | assert_not_nil issue.errors[:tracker_id] |
|
357 | assert_not_nil issue.errors[:tracker_id] | |
358 | end |
|
358 | end | |
359 |
|
359 | |||
360 | def test_category_based_assignment |
|
360 | def test_category_based_assignment | |
361 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
361 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
362 | :status_id => 1, :priority => IssuePriority.all.first, |
|
362 | :status_id => 1, :priority => IssuePriority.all.first, | |
363 | :subject => 'Assignment test', |
|
363 | :subject => 'Assignment test', | |
364 | :description => 'Assignment test', :category_id => 1) |
|
364 | :description => 'Assignment test', :category_id => 1) | |
365 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
365 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | def test_new_statuses_allowed_to |
|
368 | def test_new_statuses_allowed_to | |
369 | WorkflowTransition.delete_all |
|
369 | WorkflowTransition.delete_all | |
370 |
|
370 | |||
371 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false) |
|
371 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false) | |
372 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false) |
|
372 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false) | |
373 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true) |
|
373 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true) | |
374 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5, :author => true, :assignee => true) |
|
374 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5, :author => true, :assignee => true) | |
375 | status = IssueStatus.find(1) |
|
375 | status = IssueStatus.find(1) | |
376 | role = Role.find(1) |
|
376 | role = Role.find(1) | |
377 | tracker = Tracker.find(1) |
|
377 | tracker = Tracker.find(1) | |
378 | user = User.find(2) |
|
378 | user = User.find(2) | |
379 |
|
379 | |||
380 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author_id => 1) |
|
380 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author_id => 1) | |
381 | assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id) |
|
381 | assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id) | |
382 |
|
382 | |||
383 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user) |
|
383 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user) | |
384 | assert_equal [1, 2, 3, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
384 | assert_equal [1, 2, 3, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
385 |
|
385 | |||
386 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author_id => 1, :assigned_to => user) |
|
386 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author_id => 1, :assigned_to => user) | |
387 | assert_equal [1, 2, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
387 | assert_equal [1, 2, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
388 |
|
388 | |||
389 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user, :assigned_to => user) |
|
389 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user, :assigned_to => user) | |
390 | assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
390 | assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
391 | end |
|
391 | end | |
392 |
|
392 | |||
393 | def test_new_statuses_allowed_to_should_return_all_transitions_for_admin |
|
393 | def test_new_statuses_allowed_to_should_return_all_transitions_for_admin | |
394 | admin = User.find(1) |
|
394 | admin = User.find(1) | |
395 | issue = Issue.find(1) |
|
395 | issue = Issue.find(1) | |
396 | assert !admin.member_of?(issue.project) |
|
396 | assert !admin.member_of?(issue.project) | |
397 | expected_statuses = [issue.status] + WorkflowTransition.find_all_by_old_status_id(issue.status_id).map(&:new_status).uniq.sort |
|
397 | expected_statuses = [issue.status] + WorkflowTransition.find_all_by_old_status_id(issue.status_id).map(&:new_status).uniq.sort | |
398 |
|
398 | |||
399 | assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) |
|
399 | assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) | |
400 | end |
|
400 | end | |
401 |
|
401 | |||
402 | def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying |
|
402 | def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying | |
403 | issue = Issue.find(1).copy |
|
403 | issue = Issue.find(1).copy | |
404 | assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id) |
|
404 | assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id) | |
405 |
|
405 | |||
406 | issue = Issue.find(2).copy |
|
406 | issue = Issue.find(2).copy | |
407 | assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id) |
|
407 | assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id) | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | def test_safe_attributes_names_should_not_include_disabled_field |
|
410 | def test_safe_attributes_names_should_not_include_disabled_field | |
411 | tracker = Tracker.new(:core_fields => %w(assigned_to_id fixed_version_id)) |
|
411 | tracker = Tracker.new(:core_fields => %w(assigned_to_id fixed_version_id)) | |
412 |
|
412 | |||
413 | issue = Issue.new(:tracker => tracker) |
|
413 | issue = Issue.new(:tracker => tracker) | |
414 | assert_include 'tracker_id', issue.safe_attribute_names |
|
414 | assert_include 'tracker_id', issue.safe_attribute_names | |
415 | assert_include 'status_id', issue.safe_attribute_names |
|
415 | assert_include 'status_id', issue.safe_attribute_names | |
416 | assert_include 'subject', issue.safe_attribute_names |
|
416 | assert_include 'subject', issue.safe_attribute_names | |
417 | assert_include 'description', issue.safe_attribute_names |
|
417 | assert_include 'description', issue.safe_attribute_names | |
418 | assert_include 'custom_field_values', issue.safe_attribute_names |
|
418 | assert_include 'custom_field_values', issue.safe_attribute_names | |
419 | assert_include 'custom_fields', issue.safe_attribute_names |
|
419 | assert_include 'custom_fields', issue.safe_attribute_names | |
420 | assert_include 'lock_version', issue.safe_attribute_names |
|
420 | assert_include 'lock_version', issue.safe_attribute_names | |
421 |
|
421 | |||
422 | tracker.core_fields.each do |field| |
|
422 | tracker.core_fields.each do |field| | |
423 | assert_include field, issue.safe_attribute_names |
|
423 | assert_include field, issue.safe_attribute_names | |
424 | end |
|
424 | end | |
425 |
|
425 | |||
426 | tracker.disabled_core_fields.each do |field| |
|
426 | tracker.disabled_core_fields.each do |field| | |
427 | assert_not_include field, issue.safe_attribute_names |
|
427 | assert_not_include field, issue.safe_attribute_names | |
428 | end |
|
428 | end | |
429 | end |
|
429 | end | |
430 |
|
430 | |||
431 | def test_safe_attributes_should_ignore_disabled_fields |
|
431 | def test_safe_attributes_should_ignore_disabled_fields | |
432 | tracker = Tracker.find(1) |
|
432 | tracker = Tracker.find(1) | |
433 | tracker.core_fields = %w(assigned_to_id due_date) |
|
433 | tracker.core_fields = %w(assigned_to_id due_date) | |
434 | tracker.save! |
|
434 | tracker.save! | |
435 |
|
435 | |||
436 | issue = Issue.new(:tracker => tracker) |
|
436 | issue = Issue.new(:tracker => tracker) | |
437 | issue.safe_attributes = {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'} |
|
437 | issue.safe_attributes = {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'} | |
438 | assert_nil issue.start_date |
|
438 | assert_nil issue.start_date | |
439 | assert_equal Date.parse('2012-07-14'), issue.due_date |
|
439 | assert_equal Date.parse('2012-07-14'), issue.due_date | |
440 | end |
|
440 | end | |
441 |
|
441 | |||
442 | def test_safe_attributes_should_accept_target_tracker_enabled_fields |
|
442 | def test_safe_attributes_should_accept_target_tracker_enabled_fields | |
443 | source = Tracker.find(1) |
|
443 | source = Tracker.find(1) | |
444 | source.core_fields = [] |
|
444 | source.core_fields = [] | |
445 | source.save! |
|
445 | source.save! | |
446 | target = Tracker.find(2) |
|
446 | target = Tracker.find(2) | |
447 | target.core_fields = %w(assigned_to_id due_date) |
|
447 | target.core_fields = %w(assigned_to_id due_date) | |
448 | target.save! |
|
448 | target.save! | |
449 |
|
449 | |||
450 | issue = Issue.new(:tracker => source) |
|
450 | issue = Issue.new(:tracker => source) | |
451 | issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'} |
|
451 | issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'} | |
452 | assert_equal target, issue.tracker |
|
452 | assert_equal target, issue.tracker | |
453 | assert_equal Date.parse('2012-07-14'), issue.due_date |
|
453 | assert_equal Date.parse('2012-07-14'), issue.due_date | |
454 | end |
|
454 | end | |
455 |
|
455 | |||
456 | def test_safe_attributes_should_not_include_readonly_fields |
|
456 | def test_safe_attributes_should_not_include_readonly_fields | |
457 | WorkflowPermission.delete_all |
|
457 | WorkflowPermission.delete_all | |
458 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
458 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') | |
459 | user = User.find(2) |
|
459 | user = User.find(2) | |
460 |
|
460 | |||
461 | issue = Issue.new(:project_id => 1, :tracker_id => 1) |
|
461 | issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
462 | assert_equal %w(due_date), issue.read_only_attribute_names(user) |
|
462 | assert_equal %w(due_date), issue.read_only_attribute_names(user) | |
463 | assert_not_include 'due_date', issue.safe_attribute_names(user) |
|
463 | assert_not_include 'due_date', issue.safe_attribute_names(user) | |
464 |
|
464 | |||
465 | issue.send :safe_attributes=, {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'}, user |
|
465 | issue.send :safe_attributes=, {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'}, user | |
466 | assert_equal Date.parse('2012-07-14'), issue.start_date |
|
466 | assert_equal Date.parse('2012-07-14'), issue.start_date | |
467 | assert_nil issue.due_date |
|
467 | assert_nil issue.due_date | |
468 | end |
|
468 | end | |
469 |
|
469 | |||
470 | def test_safe_attributes_should_not_include_readonly_custom_fields |
|
470 | def test_safe_attributes_should_not_include_readonly_custom_fields | |
471 | cf1 = IssueCustomField.create!(:name => 'Writable field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1]) |
|
471 | cf1 = IssueCustomField.create!(:name => 'Writable field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1]) | |
472 | cf2 = IssueCustomField.create!(:name => 'Readonly field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1]) |
|
472 | cf2 = IssueCustomField.create!(:name => 'Readonly field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1]) | |
473 |
|
473 | |||
474 | WorkflowPermission.delete_all |
|
474 | WorkflowPermission.delete_all | |
475 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') |
|
475 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') | |
476 | user = User.find(2) |
|
476 | user = User.find(2) | |
477 |
|
477 | |||
478 | issue = Issue.new(:project_id => 1, :tracker_id => 1) |
|
478 | issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
479 | assert_equal [cf2.id.to_s], issue.read_only_attribute_names(user) |
|
479 | assert_equal [cf2.id.to_s], issue.read_only_attribute_names(user) | |
480 | assert_not_include cf2.id.to_s, issue.safe_attribute_names(user) |
|
480 | assert_not_include cf2.id.to_s, issue.safe_attribute_names(user) | |
481 |
|
481 | |||
482 | issue.send :safe_attributes=, {'custom_field_values' => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}}, user |
|
482 | issue.send :safe_attributes=, {'custom_field_values' => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}}, user | |
483 | assert_equal 'value1', issue.custom_field_value(cf1) |
|
483 | assert_equal 'value1', issue.custom_field_value(cf1) | |
484 | assert_nil issue.custom_field_value(cf2) |
|
484 | assert_nil issue.custom_field_value(cf2) | |
485 |
|
485 | |||
486 | issue.send :safe_attributes=, {'custom_fields' => [{'id' => cf1.id.to_s, 'value' => 'valuea'}, {'id' => cf2.id.to_s, 'value' => 'valueb'}]}, user |
|
486 | issue.send :safe_attributes=, {'custom_fields' => [{'id' => cf1.id.to_s, 'value' => 'valuea'}, {'id' => cf2.id.to_s, 'value' => 'valueb'}]}, user | |
487 | assert_equal 'valuea', issue.custom_field_value(cf1) |
|
487 | assert_equal 'valuea', issue.custom_field_value(cf1) | |
488 | assert_nil issue.custom_field_value(cf2) |
|
488 | assert_nil issue.custom_field_value(cf2) | |
489 | end |
|
489 | end | |
490 |
|
490 | |||
491 | def test_editable_custom_field_values_should_return_non_readonly_custom_values |
|
491 | def test_editable_custom_field_values_should_return_non_readonly_custom_values | |
492 | cf1 = IssueCustomField.create!(:name => 'Writable field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
492 | cf1 = IssueCustomField.create!(:name => 'Writable field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
493 | cf2 = IssueCustomField.create!(:name => 'Readonly field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
493 | cf2 = IssueCustomField.create!(:name => 'Readonly field', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
494 |
|
494 | |||
495 | WorkflowPermission.delete_all |
|
495 | WorkflowPermission.delete_all | |
496 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') |
|
496 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') | |
497 | user = User.find(2) |
|
497 | user = User.find(2) | |
498 |
|
498 | |||
499 | issue = Issue.new(:project_id => 1, :tracker_id => 1) |
|
499 | issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
500 | values = issue.editable_custom_field_values(user) |
|
500 | values = issue.editable_custom_field_values(user) | |
501 | assert values.detect {|value| value.custom_field == cf1} |
|
501 | assert values.detect {|value| value.custom_field == cf1} | |
502 | assert_nil values.detect {|value| value.custom_field == cf2} |
|
502 | assert_nil values.detect {|value| value.custom_field == cf2} | |
503 |
|
503 | |||
504 | issue.tracker_id = 2 |
|
504 | issue.tracker_id = 2 | |
505 | values = issue.editable_custom_field_values(user) |
|
505 | values = issue.editable_custom_field_values(user) | |
506 | assert values.detect {|value| value.custom_field == cf1} |
|
506 | assert values.detect {|value| value.custom_field == cf1} | |
507 | assert values.detect {|value| value.custom_field == cf2} |
|
507 | assert values.detect {|value| value.custom_field == cf2} | |
508 | end |
|
508 | end | |
509 |
|
509 | |||
510 | def test_safe_attributes_should_accept_target_tracker_writable_fields |
|
510 | def test_safe_attributes_should_accept_target_tracker_writable_fields | |
511 | WorkflowPermission.delete_all |
|
511 | WorkflowPermission.delete_all | |
512 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
512 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') | |
513 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'start_date', :rule => 'readonly') |
|
513 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'start_date', :rule => 'readonly') | |
514 | user = User.find(2) |
|
514 | user = User.find(2) | |
515 |
|
515 | |||
516 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) |
|
516 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
517 |
|
517 | |||
518 | issue.send :safe_attributes=, {'start_date' => '2012-07-12', 'due_date' => '2012-07-14'}, user |
|
518 | issue.send :safe_attributes=, {'start_date' => '2012-07-12', 'due_date' => '2012-07-14'}, user | |
519 | assert_equal Date.parse('2012-07-12'), issue.start_date |
|
519 | assert_equal Date.parse('2012-07-12'), issue.start_date | |
520 | assert_nil issue.due_date |
|
520 | assert_nil issue.due_date | |
521 |
|
521 | |||
522 | issue.send :safe_attributes=, {'start_date' => '2012-07-15', 'due_date' => '2012-07-16', 'tracker_id' => 2}, user |
|
522 | issue.send :safe_attributes=, {'start_date' => '2012-07-15', 'due_date' => '2012-07-16', 'tracker_id' => 2}, user | |
523 | assert_equal Date.parse('2012-07-12'), issue.start_date |
|
523 | assert_equal Date.parse('2012-07-12'), issue.start_date | |
524 | assert_equal Date.parse('2012-07-16'), issue.due_date |
|
524 | assert_equal Date.parse('2012-07-16'), issue.due_date | |
525 | end |
|
525 | end | |
526 |
|
526 | |||
527 | def test_safe_attributes_should_accept_target_status_writable_fields |
|
527 | def test_safe_attributes_should_accept_target_status_writable_fields | |
528 | WorkflowPermission.delete_all |
|
528 | WorkflowPermission.delete_all | |
529 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
529 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') | |
530 | WorkflowPermission.create!(:old_status_id => 2, :tracker_id => 1, :role_id => 1, :field_name => 'start_date', :rule => 'readonly') |
|
530 | WorkflowPermission.create!(:old_status_id => 2, :tracker_id => 1, :role_id => 1, :field_name => 'start_date', :rule => 'readonly') | |
531 | user = User.find(2) |
|
531 | user = User.find(2) | |
532 |
|
532 | |||
533 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) |
|
533 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
534 |
|
534 | |||
535 | issue.send :safe_attributes=, {'start_date' => '2012-07-12', 'due_date' => '2012-07-14'}, user |
|
535 | issue.send :safe_attributes=, {'start_date' => '2012-07-12', 'due_date' => '2012-07-14'}, user | |
536 | assert_equal Date.parse('2012-07-12'), issue.start_date |
|
536 | assert_equal Date.parse('2012-07-12'), issue.start_date | |
537 | assert_nil issue.due_date |
|
537 | assert_nil issue.due_date | |
538 |
|
538 | |||
539 | issue.send :safe_attributes=, {'start_date' => '2012-07-15', 'due_date' => '2012-07-16', 'status_id' => 2}, user |
|
539 | issue.send :safe_attributes=, {'start_date' => '2012-07-15', 'due_date' => '2012-07-16', 'status_id' => 2}, user | |
540 | assert_equal Date.parse('2012-07-12'), issue.start_date |
|
540 | assert_equal Date.parse('2012-07-12'), issue.start_date | |
541 | assert_equal Date.parse('2012-07-16'), issue.due_date |
|
541 | assert_equal Date.parse('2012-07-16'), issue.due_date | |
542 | end |
|
542 | end | |
543 |
|
543 | |||
544 | def test_required_attributes_should_be_validated |
|
544 | def test_required_attributes_should_be_validated | |
545 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
545 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
546 |
|
546 | |||
547 | WorkflowPermission.delete_all |
|
547 | WorkflowPermission.delete_all | |
548 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') |
|
548 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') | |
549 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'category_id', :rule => 'required') |
|
549 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'category_id', :rule => 'required') | |
550 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf.id.to_s, :rule => 'required') |
|
550 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf.id.to_s, :rule => 'required') | |
551 |
|
551 | |||
552 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'start_date', :rule => 'required') |
|
552 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'start_date', :rule => 'required') | |
553 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf.id.to_s, :rule => 'required') |
|
553 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf.id.to_s, :rule => 'required') | |
554 | user = User.find(2) |
|
554 | user = User.find(2) | |
555 |
|
555 | |||
556 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Required fields', :author => user) |
|
556 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Required fields', :author => user) | |
557 | assert_equal [cf.id.to_s, "category_id", "due_date"], issue.required_attribute_names(user).sort |
|
557 | assert_equal [cf.id.to_s, "category_id", "due_date"], issue.required_attribute_names(user).sort | |
558 | assert !issue.save, "Issue was saved" |
|
558 | assert !issue.save, "Issue was saved" | |
559 | assert_equal ["Category can't be blank", "Due date can't be blank", "Foo can't be blank"], issue.errors.full_messages.sort |
|
559 | assert_equal ["Category can't be blank", "Due date can't be blank", "Foo can't be blank"], issue.errors.full_messages.sort | |
560 |
|
560 | |||
561 | issue.tracker_id = 2 |
|
561 | issue.tracker_id = 2 | |
562 | assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort |
|
562 | assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort | |
563 | assert !issue.save, "Issue was saved" |
|
563 | assert !issue.save, "Issue was saved" | |
564 | assert_equal ["Foo can't be blank", "Start date can't be blank"], issue.errors.full_messages.sort |
|
564 | assert_equal ["Foo can't be blank", "Start date can't be blank"], issue.errors.full_messages.sort | |
565 |
|
565 | |||
566 | issue.start_date = Date.today |
|
566 | issue.start_date = Date.today | |
567 | issue.custom_field_values = {cf.id.to_s => 'bar'} |
|
567 | issue.custom_field_values = {cf.id.to_s => 'bar'} | |
568 | assert issue.save |
|
568 | assert issue.save | |
569 | end |
|
569 | end | |
570 |
|
570 | |||
571 | def test_required_attribute_names_for_multiple_roles_should_intersect_rules |
|
571 | def test_required_attribute_names_for_multiple_roles_should_intersect_rules | |
572 | WorkflowPermission.delete_all |
|
572 | WorkflowPermission.delete_all | |
573 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') |
|
573 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') | |
574 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'start_date', :rule => 'required') |
|
574 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'start_date', :rule => 'required') | |
575 | user = User.find(2) |
|
575 | user = User.find(2) | |
576 | member = Member.find(1) |
|
576 | member = Member.find(1) | |
577 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) |
|
577 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
578 |
|
578 | |||
579 | assert_equal %w(due_date start_date), issue.required_attribute_names(user).sort |
|
579 | assert_equal %w(due_date start_date), issue.required_attribute_names(user).sort | |
580 |
|
580 | |||
581 | member.role_ids = [1, 2] |
|
581 | member.role_ids = [1, 2] | |
582 | member.save! |
|
582 | member.save! | |
583 | assert_equal [], issue.required_attribute_names(user.reload) |
|
583 | assert_equal [], issue.required_attribute_names(user.reload) | |
584 |
|
584 | |||
585 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 2, :field_name => 'due_date', :rule => 'required') |
|
585 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 2, :field_name => 'due_date', :rule => 'required') | |
586 | assert_equal %w(due_date), issue.required_attribute_names(user) |
|
586 | assert_equal %w(due_date), issue.required_attribute_names(user) | |
587 |
|
587 | |||
588 | member.role_ids = [1, 2, 3] |
|
588 | member.role_ids = [1, 2, 3] | |
589 | member.save! |
|
589 | member.save! | |
590 | assert_equal [], issue.required_attribute_names(user.reload) |
|
590 | assert_equal [], issue.required_attribute_names(user.reload) | |
591 |
|
591 | |||
592 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 2, :field_name => 'due_date', :rule => 'readonly') |
|
592 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 2, :field_name => 'due_date', :rule => 'readonly') | |
593 | # required + readonly => required |
|
593 | # required + readonly => required | |
594 | assert_equal %w(due_date), issue.required_attribute_names(user) |
|
594 | assert_equal %w(due_date), issue.required_attribute_names(user) | |
595 | end |
|
595 | end | |
596 |
|
596 | |||
597 | def test_read_only_attribute_names_for_multiple_roles_should_intersect_rules |
|
597 | def test_read_only_attribute_names_for_multiple_roles_should_intersect_rules | |
598 | WorkflowPermission.delete_all |
|
598 | WorkflowPermission.delete_all | |
599 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
599 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') | |
600 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'start_date', :rule => 'readonly') |
|
600 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'start_date', :rule => 'readonly') | |
601 | user = User.find(2) |
|
601 | user = User.find(2) | |
602 | member = Member.find(1) |
|
602 | member = Member.find(1) | |
603 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) |
|
603 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
604 |
|
604 | |||
605 | assert_equal %w(due_date start_date), issue.read_only_attribute_names(user).sort |
|
605 | assert_equal %w(due_date start_date), issue.read_only_attribute_names(user).sort | |
606 |
|
606 | |||
607 | member.role_ids = [1, 2] |
|
607 | member.role_ids = [1, 2] | |
608 | member.save! |
|
608 | member.save! | |
609 | assert_equal [], issue.read_only_attribute_names(user.reload) |
|
609 | assert_equal [], issue.read_only_attribute_names(user.reload) | |
610 |
|
610 | |||
611 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 2, :field_name => 'due_date', :rule => 'readonly') |
|
611 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 2, :field_name => 'due_date', :rule => 'readonly') | |
612 | assert_equal %w(due_date), issue.read_only_attribute_names(user) |
|
612 | assert_equal %w(due_date), issue.read_only_attribute_names(user) | |
613 | end |
|
613 | end | |
614 |
|
614 | |||
615 | def test_copy |
|
615 | def test_copy | |
616 | issue = Issue.new.copy_from(1) |
|
616 | issue = Issue.new.copy_from(1) | |
617 | assert issue.copy? |
|
617 | assert issue.copy? | |
618 | assert issue.save |
|
618 | assert issue.save | |
619 | issue.reload |
|
619 | issue.reload | |
620 | orig = Issue.find(1) |
|
620 | orig = Issue.find(1) | |
621 | assert_equal orig.subject, issue.subject |
|
621 | assert_equal orig.subject, issue.subject | |
622 | assert_equal orig.tracker, issue.tracker |
|
622 | assert_equal orig.tracker, issue.tracker | |
623 | assert_equal "125", issue.custom_value_for(2).value |
|
623 | assert_equal "125", issue.custom_value_for(2).value | |
624 | end |
|
624 | end | |
625 |
|
625 | |||
626 | def test_copy_should_copy_status |
|
626 | def test_copy_should_copy_status | |
627 | orig = Issue.find(8) |
|
627 | orig = Issue.find(8) | |
628 | assert orig.status != IssueStatus.default |
|
628 | assert orig.status != IssueStatus.default | |
629 |
|
629 | |||
630 | issue = Issue.new.copy_from(orig) |
|
630 | issue = Issue.new.copy_from(orig) | |
631 | assert issue.save |
|
631 | assert issue.save | |
632 | issue.reload |
|
632 | issue.reload | |
633 | assert_equal orig.status, issue.status |
|
633 | assert_equal orig.status, issue.status | |
634 | end |
|
634 | end | |
635 |
|
635 | |||
636 | def test_should_not_call_after_project_change_on_creation |
|
636 | def test_should_not_call_after_project_change_on_creation | |
637 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Test', :author_id => 1) |
|
637 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Test', :author_id => 1) | |
638 | issue.expects(:after_project_change).never |
|
638 | issue.expects(:after_project_change).never | |
639 | issue.save! |
|
639 | issue.save! | |
640 | end |
|
640 | end | |
641 |
|
641 | |||
642 | def test_should_not_call_after_project_change_on_update |
|
642 | def test_should_not_call_after_project_change_on_update | |
643 | issue = Issue.find(1) |
|
643 | issue = Issue.find(1) | |
644 | issue.project = Project.find(1) |
|
644 | issue.project = Project.find(1) | |
645 | issue.subject = 'No project change' |
|
645 | issue.subject = 'No project change' | |
646 | issue.expects(:after_project_change).never |
|
646 | issue.expects(:after_project_change).never | |
647 | issue.save! |
|
647 | issue.save! | |
648 | end |
|
648 | end | |
649 |
|
649 | |||
650 | def test_should_call_after_project_change_on_project_change |
|
650 | def test_should_call_after_project_change_on_project_change | |
651 | issue = Issue.find(1) |
|
651 | issue = Issue.find(1) | |
652 | issue.project = Project.find(2) |
|
652 | issue.project = Project.find(2) | |
653 | issue.expects(:after_project_change).once |
|
653 | issue.expects(:after_project_change).once | |
654 | issue.save! |
|
654 | issue.save! | |
655 | end |
|
655 | end | |
656 |
|
656 | |||
657 | def test_adding_journal_should_update_timestamp |
|
657 | def test_adding_journal_should_update_timestamp | |
658 | issue = Issue.find(1) |
|
658 | issue = Issue.find(1) | |
659 | updated_on_was = issue.updated_on |
|
659 | updated_on_was = issue.updated_on | |
660 |
|
660 | |||
661 | issue.init_journal(User.first, "Adding notes") |
|
661 | issue.init_journal(User.first, "Adding notes") | |
662 | assert_difference 'Journal.count' do |
|
662 | assert_difference 'Journal.count' do | |
663 | assert issue.save |
|
663 | assert issue.save | |
664 | end |
|
664 | end | |
665 | issue.reload |
|
665 | issue.reload | |
666 |
|
666 | |||
667 | assert_not_equal updated_on_was, issue.updated_on |
|
667 | assert_not_equal updated_on_was, issue.updated_on | |
668 | end |
|
668 | end | |
669 |
|
669 | |||
670 | def test_should_close_duplicates |
|
670 | def test_should_close_duplicates | |
671 | # Create 3 issues |
|
671 | # Create 3 issues | |
672 | project = Project.find(1) |
|
672 | project = Project.find(1) | |
673 | issue1 = Issue.generate_for_project!(project) |
|
673 | issue1 = Issue.generate_for_project!(project) | |
674 | issue2 = Issue.generate_for_project!(project) |
|
674 | issue2 = Issue.generate_for_project!(project) | |
675 | issue3 = Issue.generate_for_project!(project) |
|
675 | issue3 = Issue.generate_for_project!(project) | |
676 |
|
676 | |||
677 | # 2 is a dupe of 1 |
|
677 | # 2 is a dupe of 1 | |
678 | IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
678 | IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
679 | # And 3 is a dupe of 2 |
|
679 | # And 3 is a dupe of 2 | |
680 | IssueRelation.create!(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
680 | IssueRelation.create!(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
681 | # And 3 is a dupe of 1 (circular duplicates) |
|
681 | # And 3 is a dupe of 1 (circular duplicates) | |
682 | IssueRelation.create!(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
682 | IssueRelation.create!(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
683 |
|
683 | |||
684 | assert issue1.reload.duplicates.include?(issue2) |
|
684 | assert issue1.reload.duplicates.include?(issue2) | |
685 |
|
685 | |||
686 | # Closing issue 1 |
|
686 | # Closing issue 1 | |
687 | issue1.init_journal(User.find(:first), "Closing issue1") |
|
687 | issue1.init_journal(User.find(:first), "Closing issue1") | |
688 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
688 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
689 | assert issue1.save |
|
689 | assert issue1.save | |
690 | # 2 and 3 should be also closed |
|
690 | # 2 and 3 should be also closed | |
691 | assert issue2.reload.closed? |
|
691 | assert issue2.reload.closed? | |
692 | assert issue3.reload.closed? |
|
692 | assert issue3.reload.closed? | |
693 | end |
|
693 | end | |
694 |
|
694 | |||
695 | def test_should_not_close_duplicated_issue |
|
695 | def test_should_not_close_duplicated_issue | |
696 | project = Project.find(1) |
|
696 | project = Project.find(1) | |
697 | issue1 = Issue.generate_for_project!(project) |
|
697 | issue1 = Issue.generate_for_project!(project) | |
698 | issue2 = Issue.generate_for_project!(project) |
|
698 | issue2 = Issue.generate_for_project!(project) | |
699 |
|
699 | |||
700 | # 2 is a dupe of 1 |
|
700 | # 2 is a dupe of 1 | |
701 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
701 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
702 | # 2 is a dup of 1 but 1 is not a duplicate of 2 |
|
702 | # 2 is a dup of 1 but 1 is not a duplicate of 2 | |
703 | assert !issue2.reload.duplicates.include?(issue1) |
|
703 | assert !issue2.reload.duplicates.include?(issue1) | |
704 |
|
704 | |||
705 | # Closing issue 2 |
|
705 | # Closing issue 2 | |
706 | issue2.init_journal(User.find(:first), "Closing issue2") |
|
706 | issue2.init_journal(User.find(:first), "Closing issue2") | |
707 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
707 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
708 | assert issue2.save |
|
708 | assert issue2.save | |
709 | # 1 should not be also closed |
|
709 | # 1 should not be also closed | |
710 | assert !issue1.reload.closed? |
|
710 | assert !issue1.reload.closed? | |
711 | end |
|
711 | end | |
712 |
|
712 | |||
713 | def test_assignable_versions |
|
713 | def test_assignable_versions | |
714 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
714 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') | |
715 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq |
|
715 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq | |
716 | end |
|
716 | end | |
717 |
|
717 | |||
718 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version |
|
718 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version | |
719 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
719 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') | |
720 | assert !issue.save |
|
720 | assert !issue.save | |
721 | assert_not_nil issue.errors[:fixed_version_id] |
|
721 | assert_not_nil issue.errors[:fixed_version_id] | |
722 | end |
|
722 | end | |
723 |
|
723 | |||
724 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version |
|
724 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version | |
725 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') |
|
725 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') | |
726 | assert !issue.save |
|
726 | assert !issue.save | |
727 | assert_not_nil issue.errors[:fixed_version_id] |
|
727 | assert_not_nil issue.errors[:fixed_version_id] | |
728 | end |
|
728 | end | |
729 |
|
729 | |||
730 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version |
|
730 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version | |
731 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') |
|
731 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') | |
732 | assert issue.save |
|
732 | assert issue.save | |
733 | end |
|
733 | end | |
734 |
|
734 | |||
735 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version |
|
735 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version | |
736 | issue = Issue.find(11) |
|
736 | issue = Issue.find(11) | |
737 | assert_equal 'closed', issue.fixed_version.status |
|
737 | assert_equal 'closed', issue.fixed_version.status | |
738 | issue.subject = 'Subject changed' |
|
738 | issue.subject = 'Subject changed' | |
739 | assert issue.save |
|
739 | assert issue.save | |
740 | end |
|
740 | end | |
741 |
|
741 | |||
742 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version |
|
742 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version | |
743 | issue = Issue.find(11) |
|
743 | issue = Issue.find(11) | |
744 | issue.status_id = 1 |
|
744 | issue.status_id = 1 | |
745 | assert !issue.save |
|
745 | assert !issue.save | |
746 | assert_not_nil issue.errors[:base] |
|
746 | assert_not_nil issue.errors[:base] | |
747 | end |
|
747 | end | |
748 |
|
748 | |||
749 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version |
|
749 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version | |
750 | issue = Issue.find(11) |
|
750 | issue = Issue.find(11) | |
751 | issue.status_id = 1 |
|
751 | issue.status_id = 1 | |
752 | issue.fixed_version_id = 3 |
|
752 | issue.fixed_version_id = 3 | |
753 | assert issue.save |
|
753 | assert issue.save | |
754 | end |
|
754 | end | |
755 |
|
755 | |||
756 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version |
|
756 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version | |
757 | issue = Issue.find(12) |
|
757 | issue = Issue.find(12) | |
758 | assert_equal 'locked', issue.fixed_version.status |
|
758 | assert_equal 'locked', issue.fixed_version.status | |
759 | issue.status_id = 1 |
|
759 | issue.status_id = 1 | |
760 | assert issue.save |
|
760 | assert issue.save | |
761 | end |
|
761 | end | |
762 |
|
762 | |||
763 | def test_should_not_be_able_to_keep_unshared_version_when_changing_project |
|
763 | def test_should_not_be_able_to_keep_unshared_version_when_changing_project | |
764 | issue = Issue.find(2) |
|
764 | issue = Issue.find(2) | |
765 | assert_equal 2, issue.fixed_version_id |
|
765 | assert_equal 2, issue.fixed_version_id | |
766 | issue.project_id = 3 |
|
766 | issue.project_id = 3 | |
767 | assert_nil issue.fixed_version_id |
|
767 | assert_nil issue.fixed_version_id | |
768 | issue.fixed_version_id = 2 |
|
768 | issue.fixed_version_id = 2 | |
769 | assert !issue.save |
|
769 | assert !issue.save | |
770 | assert_include 'Target version is not included in the list', issue.errors.full_messages |
|
770 | assert_include 'Target version is not included in the list', issue.errors.full_messages | |
771 | end |
|
771 | end | |
772 |
|
772 | |||
773 | def test_should_keep_shared_version_when_changing_project |
|
773 | def test_should_keep_shared_version_when_changing_project | |
774 | Version.find(2).update_attribute :sharing, 'tree' |
|
774 | Version.find(2).update_attribute :sharing, 'tree' | |
775 |
|
775 | |||
776 | issue = Issue.find(2) |
|
776 | issue = Issue.find(2) | |
777 | assert_equal 2, issue.fixed_version_id |
|
777 | assert_equal 2, issue.fixed_version_id | |
778 | issue.project_id = 3 |
|
778 | issue.project_id = 3 | |
779 | assert_equal 2, issue.fixed_version_id |
|
779 | assert_equal 2, issue.fixed_version_id | |
780 | assert issue.save |
|
780 | assert issue.save | |
781 | end |
|
781 | end | |
782 |
|
782 | |||
783 | def test_allowed_target_projects_on_move_should_include_projects_with_issue_tracking_enabled |
|
783 | def test_allowed_target_projects_on_move_should_include_projects_with_issue_tracking_enabled | |
784 | assert_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2)) |
|
784 | assert_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2)) | |
785 | end |
|
785 | end | |
786 |
|
786 | |||
787 | def test_allowed_target_projects_on_move_should_not_include_projects_with_issue_tracking_disabled |
|
787 | def test_allowed_target_projects_on_move_should_not_include_projects_with_issue_tracking_disabled | |
788 | Project.find(2).disable_module! :issue_tracking |
|
788 | Project.find(2).disable_module! :issue_tracking | |
789 | assert_not_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2)) |
|
789 | assert_not_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2)) | |
790 | end |
|
790 | end | |
791 |
|
791 | |||
792 | def test_move_to_another_project_with_same_category |
|
792 | def test_move_to_another_project_with_same_category | |
793 | issue = Issue.find(1) |
|
793 | issue = Issue.find(1) | |
794 | issue.project = Project.find(2) |
|
794 | issue.project = Project.find(2) | |
795 | assert issue.save |
|
795 | assert issue.save | |
796 | issue.reload |
|
796 | issue.reload | |
797 | assert_equal 2, issue.project_id |
|
797 | assert_equal 2, issue.project_id | |
798 | # Category changes |
|
798 | # Category changes | |
799 | assert_equal 4, issue.category_id |
|
799 | assert_equal 4, issue.category_id | |
800 | # Make sure time entries were move to the target project |
|
800 | # Make sure time entries were move to the target project | |
801 | assert_equal 2, issue.time_entries.first.project_id |
|
801 | assert_equal 2, issue.time_entries.first.project_id | |
802 | end |
|
802 | end | |
803 |
|
803 | |||
804 | def test_move_to_another_project_without_same_category |
|
804 | def test_move_to_another_project_without_same_category | |
805 | issue = Issue.find(2) |
|
805 | issue = Issue.find(2) | |
806 | issue.project = Project.find(2) |
|
806 | issue.project = Project.find(2) | |
807 | assert issue.save |
|
807 | assert issue.save | |
808 | issue.reload |
|
808 | issue.reload | |
809 | assert_equal 2, issue.project_id |
|
809 | assert_equal 2, issue.project_id | |
810 | # Category cleared |
|
810 | # Category cleared | |
811 | assert_nil issue.category_id |
|
811 | assert_nil issue.category_id | |
812 | end |
|
812 | end | |
813 |
|
813 | |||
814 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared |
|
814 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared | |
815 | issue = Issue.find(1) |
|
815 | issue = Issue.find(1) | |
816 | issue.update_attribute(:fixed_version_id, 1) |
|
816 | issue.update_attribute(:fixed_version_id, 1) | |
817 | issue.project = Project.find(2) |
|
817 | issue.project = Project.find(2) | |
818 | assert issue.save |
|
818 | assert issue.save | |
819 | issue.reload |
|
819 | issue.reload | |
820 | assert_equal 2, issue.project_id |
|
820 | assert_equal 2, issue.project_id | |
821 | # Cleared fixed_version |
|
821 | # Cleared fixed_version | |
822 | assert_equal nil, issue.fixed_version |
|
822 | assert_equal nil, issue.fixed_version | |
823 | end |
|
823 | end | |
824 |
|
824 | |||
825 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project |
|
825 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project | |
826 | issue = Issue.find(1) |
|
826 | issue = Issue.find(1) | |
827 | issue.update_attribute(:fixed_version_id, 4) |
|
827 | issue.update_attribute(:fixed_version_id, 4) | |
828 | issue.project = Project.find(5) |
|
828 | issue.project = Project.find(5) | |
829 | assert issue.save |
|
829 | assert issue.save | |
830 | issue.reload |
|
830 | issue.reload | |
831 | assert_equal 5, issue.project_id |
|
831 | assert_equal 5, issue.project_id | |
832 | # Keep fixed_version |
|
832 | # Keep fixed_version | |
833 | assert_equal 4, issue.fixed_version_id |
|
833 | assert_equal 4, issue.fixed_version_id | |
834 | end |
|
834 | end | |
835 |
|
835 | |||
836 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project |
|
836 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project | |
837 | issue = Issue.find(1) |
|
837 | issue = Issue.find(1) | |
838 | issue.update_attribute(:fixed_version_id, 1) |
|
838 | issue.update_attribute(:fixed_version_id, 1) | |
839 | issue.project = Project.find(5) |
|
839 | issue.project = Project.find(5) | |
840 | assert issue.save |
|
840 | assert issue.save | |
841 | issue.reload |
|
841 | issue.reload | |
842 | assert_equal 5, issue.project_id |
|
842 | assert_equal 5, issue.project_id | |
843 | # Cleared fixed_version |
|
843 | # Cleared fixed_version | |
844 | assert_equal nil, issue.fixed_version |
|
844 | assert_equal nil, issue.fixed_version | |
845 | end |
|
845 | end | |
846 |
|
846 | |||
847 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide |
|
847 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide | |
848 | issue = Issue.find(1) |
|
848 | issue = Issue.find(1) | |
849 | issue.update_attribute(:fixed_version_id, 7) |
|
849 | issue.update_attribute(:fixed_version_id, 7) | |
850 | issue.project = Project.find(2) |
|
850 | issue.project = Project.find(2) | |
851 | assert issue.save |
|
851 | assert issue.save | |
852 | issue.reload |
|
852 | issue.reload | |
853 | assert_equal 2, issue.project_id |
|
853 | assert_equal 2, issue.project_id | |
854 | # Keep fixed_version |
|
854 | # Keep fixed_version | |
855 | assert_equal 7, issue.fixed_version_id |
|
855 | assert_equal 7, issue.fixed_version_id | |
856 | end |
|
856 | end | |
857 |
|
857 | |||
858 | def test_move_to_another_project_with_disabled_tracker |
|
858 | def test_move_to_another_project_with_disabled_tracker | |
859 | issue = Issue.find(1) |
|
859 | issue = Issue.find(1) | |
860 | target = Project.find(2) |
|
860 | target = Project.find(2) | |
861 | target.tracker_ids = [3] |
|
861 | target.tracker_ids = [3] | |
862 | target.save |
|
862 | target.save | |
863 | issue.project = target |
|
863 | issue.project = target | |
864 | assert issue.save |
|
864 | assert issue.save | |
865 | issue.reload |
|
865 | issue.reload | |
866 | assert_equal 2, issue.project_id |
|
866 | assert_equal 2, issue.project_id | |
867 | assert_equal 3, issue.tracker_id |
|
867 | assert_equal 3, issue.tracker_id | |
868 | end |
|
868 | end | |
869 |
|
869 | |||
870 | def test_copy_to_the_same_project |
|
870 | def test_copy_to_the_same_project | |
871 | issue = Issue.find(1) |
|
871 | issue = Issue.find(1) | |
872 | copy = issue.copy |
|
872 | copy = issue.copy | |
873 | assert_difference 'Issue.count' do |
|
873 | assert_difference 'Issue.count' do | |
874 | copy.save! |
|
874 | copy.save! | |
875 | end |
|
875 | end | |
876 | assert_kind_of Issue, copy |
|
876 | assert_kind_of Issue, copy | |
877 | assert_equal issue.project, copy.project |
|
877 | assert_equal issue.project, copy.project | |
878 | assert_equal "125", copy.custom_value_for(2).value |
|
878 | assert_equal "125", copy.custom_value_for(2).value | |
879 | end |
|
879 | end | |
880 |
|
880 | |||
881 | def test_copy_to_another_project_and_tracker |
|
881 | def test_copy_to_another_project_and_tracker | |
882 | issue = Issue.find(1) |
|
882 | issue = Issue.find(1) | |
883 | copy = issue.copy(:project_id => 3, :tracker_id => 2) |
|
883 | copy = issue.copy(:project_id => 3, :tracker_id => 2) | |
884 | assert_difference 'Issue.count' do |
|
884 | assert_difference 'Issue.count' do | |
885 | copy.save! |
|
885 | copy.save! | |
886 | end |
|
886 | end | |
887 | copy.reload |
|
887 | copy.reload | |
888 | assert_kind_of Issue, copy |
|
888 | assert_kind_of Issue, copy | |
889 | assert_equal Project.find(3), copy.project |
|
889 | assert_equal Project.find(3), copy.project | |
890 | assert_equal Tracker.find(2), copy.tracker |
|
890 | assert_equal Tracker.find(2), copy.tracker | |
891 | # Custom field #2 is not associated with target tracker |
|
891 | # Custom field #2 is not associated with target tracker | |
892 | assert_nil copy.custom_value_for(2) |
|
892 | assert_nil copy.custom_value_for(2) | |
893 | end |
|
893 | end | |
894 |
|
894 | |||
895 | context "#copy" do |
|
895 | context "#copy" do | |
896 | setup do |
|
896 | setup do | |
897 | @issue = Issue.find(1) |
|
897 | @issue = Issue.find(1) | |
898 | end |
|
898 | end | |
899 |
|
899 | |||
900 | should "not create a journal" do |
|
900 | should "not create a journal" do | |
901 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) |
|
901 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
902 | copy.save! |
|
902 | copy.save! | |
903 | assert_equal 0, copy.reload.journals.size |
|
903 | assert_equal 0, copy.reload.journals.size | |
904 | end |
|
904 | end | |
905 |
|
905 | |||
906 | should "allow assigned_to changes" do |
|
906 | should "allow assigned_to changes" do | |
907 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) |
|
907 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
908 | assert_equal 3, copy.assigned_to_id |
|
908 | assert_equal 3, copy.assigned_to_id | |
909 | end |
|
909 | end | |
910 |
|
910 | |||
911 | should "allow status changes" do |
|
911 | should "allow status changes" do | |
912 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :status_id => 2) |
|
912 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :status_id => 2) | |
913 | assert_equal 2, copy.status_id |
|
913 | assert_equal 2, copy.status_id | |
914 | end |
|
914 | end | |
915 |
|
915 | |||
916 | should "allow start date changes" do |
|
916 | should "allow start date changes" do | |
917 | date = Date.today |
|
917 | date = Date.today | |
918 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) |
|
918 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) | |
919 | assert_equal date, copy.start_date |
|
919 | assert_equal date, copy.start_date | |
920 | end |
|
920 | end | |
921 |
|
921 | |||
922 | should "allow due date changes" do |
|
922 | should "allow due date changes" do | |
923 | date = Date.today |
|
923 | date = Date.today | |
924 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :due_date => date) |
|
924 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :due_date => date) | |
925 | assert_equal date, copy.due_date |
|
925 | assert_equal date, copy.due_date | |
926 | end |
|
926 | end | |
927 |
|
927 | |||
928 | should "set current user as author" do |
|
928 | should "set current user as author" do | |
929 | User.current = User.find(9) |
|
929 | User.current = User.find(9) | |
930 | copy = @issue.copy(:project_id => 3, :tracker_id => 2) |
|
930 | copy = @issue.copy(:project_id => 3, :tracker_id => 2) | |
931 | assert_equal User.current, copy.author |
|
931 | assert_equal User.current, copy.author | |
932 | end |
|
932 | end | |
933 |
|
933 | |||
934 | should "create a journal with notes" do |
|
934 | should "create a journal with notes" do | |
935 | date = Date.today |
|
935 | date = Date.today | |
936 | notes = "Notes added when copying" |
|
936 | notes = "Notes added when copying" | |
937 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) |
|
937 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) | |
938 | copy.init_journal(User.current, notes) |
|
938 | copy.init_journal(User.current, notes) | |
939 | copy.save! |
|
939 | copy.save! | |
940 |
|
940 | |||
941 | assert_equal 1, copy.journals.size |
|
941 | assert_equal 1, copy.journals.size | |
942 | journal = copy.journals.first |
|
942 | journal = copy.journals.first | |
943 | assert_equal 0, journal.details.size |
|
943 | assert_equal 0, journal.details.size | |
944 | assert_equal notes, journal.notes |
|
944 | assert_equal notes, journal.notes | |
945 | end |
|
945 | end | |
946 | end |
|
946 | end | |
947 |
|
947 | |||
948 | def test_recipients_should_include_previous_assignee |
|
948 | def test_recipients_should_include_previous_assignee | |
949 | user = User.find(3) |
|
949 | user = User.find(3) | |
950 | user.members.update_all ["mail_notification = ?", false] |
|
950 | user.members.update_all ["mail_notification = ?", false] | |
951 | user.update_attribute :mail_notification, 'only_assigned' |
|
951 | user.update_attribute :mail_notification, 'only_assigned' | |
952 |
|
952 | |||
953 | issue = Issue.find(2) |
|
953 | issue = Issue.find(2) | |
954 | issue.assigned_to = nil |
|
954 | issue.assigned_to = nil | |
955 | assert_include user.mail, issue.recipients |
|
955 | assert_include user.mail, issue.recipients | |
956 | issue.save! |
|
956 | issue.save! | |
957 | assert !issue.recipients.include?(user.mail) |
|
957 | assert !issue.recipients.include?(user.mail) | |
958 | end |
|
958 | end | |
959 |
|
959 | |||
960 | def test_recipients_should_not_include_users_that_cannot_view_the_issue |
|
960 | def test_recipients_should_not_include_users_that_cannot_view_the_issue | |
961 | issue = Issue.find(12) |
|
961 | issue = Issue.find(12) | |
962 | assert issue.recipients.include?(issue.author.mail) |
|
962 | assert issue.recipients.include?(issue.author.mail) | |
963 | # copy the issue to a private project |
|
963 | # copy the issue to a private project | |
964 | copy = issue.copy(:project_id => 5, :tracker_id => 2) |
|
964 | copy = issue.copy(:project_id => 5, :tracker_id => 2) | |
965 | # author is not a member of project anymore |
|
965 | # author is not a member of project anymore | |
966 | assert !copy.recipients.include?(copy.author.mail) |
|
966 | assert !copy.recipients.include?(copy.author.mail) | |
967 | end |
|
967 | end | |
968 |
|
968 | |||
969 | def test_recipients_should_include_the_assigned_group_members |
|
969 | def test_recipients_should_include_the_assigned_group_members | |
970 | group_member = User.generate! |
|
970 | group_member = User.generate! | |
971 | group = Group.generate! |
|
971 | group = Group.generate! | |
972 | group.users << group_member |
|
972 | group.users << group_member | |
973 |
|
973 | |||
974 | issue = Issue.find(12) |
|
974 | issue = Issue.find(12) | |
975 | issue.assigned_to = group |
|
975 | issue.assigned_to = group | |
976 | assert issue.recipients.include?(group_member.mail) |
|
976 | assert issue.recipients.include?(group_member.mail) | |
977 | end |
|
977 | end | |
978 |
|
978 | |||
979 | def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue |
|
979 | def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue | |
980 | user = User.find(3) |
|
980 | user = User.find(3) | |
981 | issue = Issue.find(9) |
|
981 | issue = Issue.find(9) | |
982 | Watcher.create!(:user => user, :watchable => issue) |
|
982 | Watcher.create!(:user => user, :watchable => issue) | |
983 | assert issue.watched_by?(user) |
|
983 | assert issue.watched_by?(user) | |
984 | assert !issue.watcher_recipients.include?(user.mail) |
|
984 | assert !issue.watcher_recipients.include?(user.mail) | |
985 | end |
|
985 | end | |
986 |
|
986 | |||
987 | def test_issue_destroy |
|
987 | def test_issue_destroy | |
988 | Issue.find(1).destroy |
|
988 | Issue.find(1).destroy | |
989 | assert_nil Issue.find_by_id(1) |
|
989 | assert_nil Issue.find_by_id(1) | |
990 | assert_nil TimeEntry.find_by_issue_id(1) |
|
990 | assert_nil TimeEntry.find_by_issue_id(1) | |
991 | end |
|
991 | end | |
992 |
|
992 | |||
993 | def test_destroying_a_deleted_issue_should_not_raise_an_error |
|
993 | def test_destroying_a_deleted_issue_should_not_raise_an_error | |
994 | issue = Issue.find(1) |
|
994 | issue = Issue.find(1) | |
995 | Issue.find(1).destroy |
|
995 | Issue.find(1).destroy | |
996 |
|
996 | |||
997 | assert_nothing_raised do |
|
997 | assert_nothing_raised do | |
998 | assert_no_difference 'Issue.count' do |
|
998 | assert_no_difference 'Issue.count' do | |
999 | issue.destroy |
|
999 | issue.destroy | |
1000 | end |
|
1000 | end | |
1001 | assert issue.destroyed? |
|
1001 | assert issue.destroyed? | |
1002 | end |
|
1002 | end | |
1003 | end |
|
1003 | end | |
1004 |
|
1004 | |||
1005 | def test_destroying_a_stale_issue_should_not_raise_an_error |
|
1005 | def test_destroying_a_stale_issue_should_not_raise_an_error | |
1006 | issue = Issue.find(1) |
|
1006 | issue = Issue.find(1) | |
1007 | Issue.find(1).update_attribute :subject, "Updated" |
|
1007 | Issue.find(1).update_attribute :subject, "Updated" | |
1008 |
|
1008 | |||
1009 | assert_nothing_raised do |
|
1009 | assert_nothing_raised do | |
1010 | assert_difference 'Issue.count', -1 do |
|
1010 | assert_difference 'Issue.count', -1 do | |
1011 | issue.destroy |
|
1011 | issue.destroy | |
1012 | end |
|
1012 | end | |
1013 | assert issue.destroyed? |
|
1013 | assert issue.destroyed? | |
1014 | end |
|
1014 | end | |
1015 | end |
|
1015 | end | |
1016 |
|
1016 | |||
1017 | def test_blocked |
|
1017 | def test_blocked | |
1018 | blocked_issue = Issue.find(9) |
|
1018 | blocked_issue = Issue.find(9) | |
1019 | blocking_issue = Issue.find(10) |
|
1019 | blocking_issue = Issue.find(10) | |
1020 |
|
1020 | |||
1021 | assert blocked_issue.blocked? |
|
1021 | assert blocked_issue.blocked? | |
1022 | assert !blocking_issue.blocked? |
|
1022 | assert !blocking_issue.blocked? | |
1023 | end |
|
1023 | end | |
1024 |
|
1024 | |||
1025 | def test_blocked_issues_dont_allow_closed_statuses |
|
1025 | def test_blocked_issues_dont_allow_closed_statuses | |
1026 | blocked_issue = Issue.find(9) |
|
1026 | blocked_issue = Issue.find(9) | |
1027 |
|
1027 | |||
1028 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) |
|
1028 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) | |
1029 | assert !allowed_statuses.empty? |
|
1029 | assert !allowed_statuses.empty? | |
1030 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
1030 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
1031 | assert closed_statuses.empty? |
|
1031 | assert closed_statuses.empty? | |
1032 | end |
|
1032 | end | |
1033 |
|
1033 | |||
1034 | def test_unblocked_issues_allow_closed_statuses |
|
1034 | def test_unblocked_issues_allow_closed_statuses | |
1035 | blocking_issue = Issue.find(10) |
|
1035 | blocking_issue = Issue.find(10) | |
1036 |
|
1036 | |||
1037 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) |
|
1037 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) | |
1038 | assert !allowed_statuses.empty? |
|
1038 | assert !allowed_statuses.empty? | |
1039 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
1039 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
1040 | assert !closed_statuses.empty? |
|
1040 | assert !closed_statuses.empty? | |
1041 | end |
|
1041 | end | |
1042 |
|
1042 | |||
1043 | def test_rescheduling_an_issue_should_reschedule_following_issue |
|
1043 | def test_rescheduling_an_issue_should_reschedule_following_issue | |
1044 | issue1 = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => '-', :start_date => Date.today, :due_date => Date.today + 2) |
|
1044 | issue1 = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => '-', :start_date => Date.today, :due_date => Date.today + 2) | |
1045 | issue2 = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => '-', :start_date => Date.today, :due_date => Date.today + 2) |
|
1045 | issue2 = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => '-', :start_date => Date.today, :due_date => Date.today + 2) | |
1046 | IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1046 | IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) | |
1047 | assert_equal issue1.due_date + 1, issue2.reload.start_date |
|
1047 | assert_equal issue1.due_date + 1, issue2.reload.start_date | |
1048 |
|
1048 | |||
1049 | issue1.due_date = Date.today + 5 |
|
1049 | issue1.due_date = Date.today + 5 | |
1050 | issue1.save! |
|
1050 | issue1.save! | |
1051 | assert_equal issue1.due_date + 1, issue2.reload.start_date |
|
1051 | assert_equal issue1.due_date + 1, issue2.reload.start_date | |
1052 | end |
|
1052 | end | |
1053 |
|
1053 | |||
1054 | def test_rescheduling_a_stale_issue_should_not_raise_an_error |
|
1054 | def test_rescheduling_a_stale_issue_should_not_raise_an_error | |
1055 | stale = Issue.find(1) |
|
1055 | stale = Issue.find(1) | |
1056 | issue = Issue.find(1) |
|
1056 | issue = Issue.find(1) | |
1057 | issue.subject = "Updated" |
|
1057 | issue.subject = "Updated" | |
1058 | issue.save! |
|
1058 | issue.save! | |
1059 |
|
1059 | |||
1060 | date = 10.days.from_now.to_date |
|
1060 | date = 10.days.from_now.to_date | |
1061 | assert_nothing_raised do |
|
1061 | assert_nothing_raised do | |
1062 | stale.reschedule_after(date) |
|
1062 | stale.reschedule_after(date) | |
1063 | end |
|
1063 | end | |
1064 | assert_equal date, stale.reload.start_date |
|
1064 | assert_equal date, stale.reload.start_date | |
1065 | end |
|
1065 | end | |
1066 |
|
1066 | |||
1067 | def test_overdue |
|
1067 | def test_overdue | |
1068 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? |
|
1068 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? | |
1069 | assert !Issue.new(:due_date => Date.today).overdue? |
|
1069 | assert !Issue.new(:due_date => Date.today).overdue? | |
1070 | assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? |
|
1070 | assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? | |
1071 | assert !Issue.new(:due_date => nil).overdue? |
|
1071 | assert !Issue.new(:due_date => nil).overdue? | |
1072 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? |
|
1072 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? | |
1073 | end |
|
1073 | end | |
1074 |
|
1074 | |||
1075 | context "#behind_schedule?" do |
|
1075 | context "#behind_schedule?" do | |
1076 | should "be false if the issue has no start_date" do |
|
1076 | should "be false if the issue has no start_date" do | |
1077 | assert !Issue.new(:start_date => nil, :due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule? |
|
1077 | assert !Issue.new(:start_date => nil, :due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule? | |
1078 | end |
|
1078 | end | |
1079 |
|
1079 | |||
1080 | should "be false if the issue has no end_date" do |
|
1080 | should "be false if the issue has no end_date" do | |
1081 | assert !Issue.new(:start_date => 1.day.from_now.to_date, :due_date => nil, :done_ratio => 0).behind_schedule? |
|
1081 | assert !Issue.new(:start_date => 1.day.from_now.to_date, :due_date => nil, :done_ratio => 0).behind_schedule? | |
1082 | end |
|
1082 | end | |
1083 |
|
1083 | |||
1084 | should "be false if the issue has more done than it's calendar time" do |
|
1084 | should "be false if the issue has more done than it's calendar time" do | |
1085 | assert !Issue.new(:start_date => 50.days.ago.to_date, :due_date => 50.days.from_now.to_date, :done_ratio => 90).behind_schedule? |
|
1085 | assert !Issue.new(:start_date => 50.days.ago.to_date, :due_date => 50.days.from_now.to_date, :done_ratio => 90).behind_schedule? | |
1086 | end |
|
1086 | end | |
1087 |
|
1087 | |||
1088 | should "be true if the issue hasn't been started at all" do |
|
1088 | should "be true if the issue hasn't been started at all" do | |
1089 | assert Issue.new(:start_date => 1.day.ago.to_date, :due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule? |
|
1089 | assert Issue.new(:start_date => 1.day.ago.to_date, :due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule? | |
1090 | end |
|
1090 | end | |
1091 |
|
1091 | |||
1092 | should "be true if the issue has used more calendar time than it's done ratio" do |
|
1092 | should "be true if the issue has used more calendar time than it's done ratio" do | |
1093 | assert Issue.new(:start_date => 100.days.ago.to_date, :due_date => Date.today, :done_ratio => 90).behind_schedule? |
|
1093 | assert Issue.new(:start_date => 100.days.ago.to_date, :due_date => Date.today, :done_ratio => 90).behind_schedule? | |
1094 | end |
|
1094 | end | |
1095 | end |
|
1095 | end | |
1096 |
|
1096 | |||
1097 | context "#assignable_users" do |
|
1097 | context "#assignable_users" do | |
1098 | should "be Users" do |
|
1098 | should "be Users" do | |
1099 | assert_kind_of User, Issue.find(1).assignable_users.first |
|
1099 | assert_kind_of User, Issue.find(1).assignable_users.first | |
1100 | end |
|
1100 | end | |
1101 |
|
1101 | |||
1102 | should "include the issue author" do |
|
1102 | should "include the issue author" do | |
1103 | project = Project.find(1) |
|
1103 | project = Project.find(1) | |
1104 | non_project_member = User.generate! |
|
1104 | non_project_member = User.generate! | |
1105 | issue = Issue.generate_for_project!(project, :author => non_project_member) |
|
1105 | issue = Issue.generate_for_project!(project, :author => non_project_member) | |
1106 |
|
1106 | |||
1107 | assert issue.assignable_users.include?(non_project_member) |
|
1107 | assert issue.assignable_users.include?(non_project_member) | |
1108 | end |
|
1108 | end | |
1109 |
|
1109 | |||
1110 | should "include the current assignee" do |
|
1110 | should "include the current assignee" do | |
1111 | project = Project.find(1) |
|
1111 | project = Project.find(1) | |
1112 | user = User.generate! |
|
1112 | user = User.generate! | |
1113 | issue = Issue.generate_for_project!(project, :assigned_to => user) |
|
1113 | issue = Issue.generate_for_project!(project, :assigned_to => user) | |
1114 | user.lock! |
|
1114 | user.lock! | |
1115 |
|
1115 | |||
1116 | assert Issue.find(issue.id).assignable_users.include?(user) |
|
1116 | assert Issue.find(issue.id).assignable_users.include?(user) | |
1117 | end |
|
1117 | end | |
1118 |
|
1118 | |||
1119 | should "not show the issue author twice" do |
|
1119 | should "not show the issue author twice" do | |
1120 | assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) |
|
1120 | assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) | |
1121 | assert_equal 2, assignable_user_ids.length |
|
1121 | assert_equal 2, assignable_user_ids.length | |
1122 |
|
1122 | |||
1123 | assignable_user_ids.each do |user_id| |
|
1123 | assignable_user_ids.each do |user_id| | |
1124 | assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, "User #{user_id} appears more or less than once" |
|
1124 | assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, "User #{user_id} appears more or less than once" | |
1125 | end |
|
1125 | end | |
1126 | end |
|
1126 | end | |
1127 |
|
1127 | |||
1128 | context "with issue_group_assignment" do |
|
1128 | context "with issue_group_assignment" do | |
1129 | should "include groups" do |
|
1129 | should "include groups" do | |
1130 | issue = Issue.new(:project => Project.find(2)) |
|
1130 | issue = Issue.new(:project => Project.find(2)) | |
1131 |
|
1131 | |||
1132 | with_settings :issue_group_assignment => '1' do |
|
1132 | with_settings :issue_group_assignment => '1' do | |
1133 | assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort |
|
1133 | assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort | |
1134 | assert issue.assignable_users.include?(Group.find(11)) |
|
1134 | assert issue.assignable_users.include?(Group.find(11)) | |
1135 | end |
|
1135 | end | |
1136 | end |
|
1136 | end | |
1137 | end |
|
1137 | end | |
1138 |
|
1138 | |||
1139 | context "without issue_group_assignment" do |
|
1139 | context "without issue_group_assignment" do | |
1140 | should "not include groups" do |
|
1140 | should "not include groups" do | |
1141 | issue = Issue.new(:project => Project.find(2)) |
|
1141 | issue = Issue.new(:project => Project.find(2)) | |
1142 |
|
1142 | |||
1143 | with_settings :issue_group_assignment => '0' do |
|
1143 | with_settings :issue_group_assignment => '0' do | |
1144 | assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort |
|
1144 | assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort | |
1145 | assert !issue.assignable_users.include?(Group.find(11)) |
|
1145 | assert !issue.assignable_users.include?(Group.find(11)) | |
1146 | end |
|
1146 | end | |
1147 | end |
|
1147 | end | |
1148 | end |
|
1148 | end | |
1149 | end |
|
1149 | end | |
1150 |
|
1150 | |||
1151 | def test_create_should_send_email_notification |
|
1151 | def test_create_should_send_email_notification | |
1152 | ActionMailer::Base.deliveries.clear |
|
1152 | ActionMailer::Base.deliveries.clear | |
1153 | issue = Issue.new(:project_id => 1, :tracker_id => 1, |
|
1153 | issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
1154 | :author_id => 3, :status_id => 1, |
|
1154 | :author_id => 3, :status_id => 1, | |
1155 | :priority => IssuePriority.all.first, |
|
1155 | :priority => IssuePriority.all.first, | |
1156 | :subject => 'test_create', :estimated_hours => '1:30') |
|
1156 | :subject => 'test_create', :estimated_hours => '1:30') | |
1157 |
|
1157 | |||
1158 | assert issue.save |
|
1158 | assert issue.save | |
1159 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
1159 | assert_equal 1, ActionMailer::Base.deliveries.size | |
1160 | end |
|
1160 | end | |
1161 |
|
1161 | |||
1162 | def test_stale_issue_should_not_send_email_notification |
|
1162 | def test_stale_issue_should_not_send_email_notification | |
1163 | ActionMailer::Base.deliveries.clear |
|
1163 | ActionMailer::Base.deliveries.clear | |
1164 | issue = Issue.find(1) |
|
1164 | issue = Issue.find(1) | |
1165 | stale = Issue.find(1) |
|
1165 | stale = Issue.find(1) | |
1166 |
|
1166 | |||
1167 | issue.init_journal(User.find(1)) |
|
1167 | issue.init_journal(User.find(1)) | |
1168 | issue.subject = 'Subjet update' |
|
1168 | issue.subject = 'Subjet update' | |
1169 | assert issue.save |
|
1169 | assert issue.save | |
1170 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
1170 | assert_equal 1, ActionMailer::Base.deliveries.size | |
1171 | ActionMailer::Base.deliveries.clear |
|
1171 | ActionMailer::Base.deliveries.clear | |
1172 |
|
1172 | |||
1173 | stale.init_journal(User.find(1)) |
|
1173 | stale.init_journal(User.find(1)) | |
1174 | stale.subject = 'Another subjet update' |
|
1174 | stale.subject = 'Another subjet update' | |
1175 | assert_raise ActiveRecord::StaleObjectError do |
|
1175 | assert_raise ActiveRecord::StaleObjectError do | |
1176 | stale.save |
|
1176 | stale.save | |
1177 | end |
|
1177 | end | |
1178 | assert ActionMailer::Base.deliveries.empty? |
|
1178 | assert ActionMailer::Base.deliveries.empty? | |
1179 | end |
|
1179 | end | |
1180 |
|
1180 | |||
1181 | def test_journalized_description |
|
1181 | def test_journalized_description | |
1182 | IssueCustomField.delete_all |
|
1182 | IssueCustomField.delete_all | |
1183 |
|
1183 | |||
1184 | i = Issue.first |
|
1184 | i = Issue.first | |
1185 | old_description = i.description |
|
1185 | old_description = i.description | |
1186 | new_description = "This is the new description" |
|
1186 | new_description = "This is the new description" | |
1187 |
|
1187 | |||
1188 | i.init_journal(User.find(2)) |
|
1188 | i.init_journal(User.find(2)) | |
1189 | i.description = new_description |
|
1189 | i.description = new_description | |
1190 | assert_difference 'Journal.count', 1 do |
|
1190 | assert_difference 'Journal.count', 1 do | |
1191 | assert_difference 'JournalDetail.count', 1 do |
|
1191 | assert_difference 'JournalDetail.count', 1 do | |
1192 | i.save! |
|
1192 | i.save! | |
1193 | end |
|
1193 | end | |
1194 | end |
|
1194 | end | |
1195 |
|
1195 | |||
1196 | detail = JournalDetail.first(:order => 'id DESC') |
|
1196 | detail = JournalDetail.first(:order => 'id DESC') | |
1197 | assert_equal i, detail.journal.journalized |
|
1197 | assert_equal i, detail.journal.journalized | |
1198 | assert_equal 'attr', detail.property |
|
1198 | assert_equal 'attr', detail.property | |
1199 | assert_equal 'description', detail.prop_key |
|
1199 | assert_equal 'description', detail.prop_key | |
1200 | assert_equal old_description, detail.old_value |
|
1200 | assert_equal old_description, detail.old_value | |
1201 | assert_equal new_description, detail.value |
|
1201 | assert_equal new_description, detail.value | |
1202 | end |
|
1202 | end | |
1203 |
|
1203 | |||
1204 | def test_blank_descriptions_should_not_be_journalized |
|
1204 | def test_blank_descriptions_should_not_be_journalized | |
1205 | IssueCustomField.delete_all |
|
1205 | IssueCustomField.delete_all | |
1206 | Issue.update_all("description = NULL", "id=1") |
|
1206 | Issue.update_all("description = NULL", "id=1") | |
1207 |
|
1207 | |||
1208 | i = Issue.find(1) |
|
1208 | i = Issue.find(1) | |
1209 | i.init_journal(User.find(2)) |
|
1209 | i.init_journal(User.find(2)) | |
1210 | i.subject = "blank description" |
|
1210 | i.subject = "blank description" | |
1211 | i.description = "\r\n" |
|
1211 | i.description = "\r\n" | |
1212 |
|
1212 | |||
1213 | assert_difference 'Journal.count', 1 do |
|
1213 | assert_difference 'Journal.count', 1 do | |
1214 | assert_difference 'JournalDetail.count', 1 do |
|
1214 | assert_difference 'JournalDetail.count', 1 do | |
1215 | i.save! |
|
1215 | i.save! | |
1216 | end |
|
1216 | end | |
1217 | end |
|
1217 | end | |
1218 | end |
|
1218 | end | |
1219 |
|
1219 | |||
1220 | def test_journalized_multi_custom_field |
|
1220 | def test_journalized_multi_custom_field | |
1221 | field = IssueCustomField.create!(:name => 'filter', :field_format => 'list', :is_filter => true, :is_for_all => true, |
|
1221 | field = IssueCustomField.create!(:name => 'filter', :field_format => 'list', :is_filter => true, :is_for_all => true, | |
1222 | :tracker_ids => [1], :possible_values => ['value1', 'value2', 'value3'], :multiple => true) |
|
1222 | :tracker_ids => [1], :possible_values => ['value1', 'value2', 'value3'], :multiple => true) | |
1223 |
|
1223 | |||
1224 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'Test', :author_id => 1) |
|
1224 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'Test', :author_id => 1) | |
1225 |
|
1225 | |||
1226 | assert_difference 'Journal.count' do |
|
1226 | assert_difference 'Journal.count' do | |
1227 | assert_difference 'JournalDetail.count' do |
|
1227 | assert_difference 'JournalDetail.count' do | |
1228 | issue.init_journal(User.first) |
|
1228 | issue.init_journal(User.first) | |
1229 | issue.custom_field_values = {field.id => ['value1']} |
|
1229 | issue.custom_field_values = {field.id => ['value1']} | |
1230 | issue.save! |
|
1230 | issue.save! | |
1231 | end |
|
1231 | end | |
1232 | assert_difference 'JournalDetail.count' do |
|
1232 | assert_difference 'JournalDetail.count' do | |
1233 | issue.init_journal(User.first) |
|
1233 | issue.init_journal(User.first) | |
1234 | issue.custom_field_values = {field.id => ['value1', 'value2']} |
|
1234 | issue.custom_field_values = {field.id => ['value1', 'value2']} | |
1235 | issue.save! |
|
1235 | issue.save! | |
1236 | end |
|
1236 | end | |
1237 | assert_difference 'JournalDetail.count', 2 do |
|
1237 | assert_difference 'JournalDetail.count', 2 do | |
1238 | issue.init_journal(User.first) |
|
1238 | issue.init_journal(User.first) | |
1239 | issue.custom_field_values = {field.id => ['value3', 'value2']} |
|
1239 | issue.custom_field_values = {field.id => ['value3', 'value2']} | |
1240 | issue.save! |
|
1240 | issue.save! | |
1241 | end |
|
1241 | end | |
1242 | assert_difference 'JournalDetail.count', 2 do |
|
1242 | assert_difference 'JournalDetail.count', 2 do | |
1243 | issue.init_journal(User.first) |
|
1243 | issue.init_journal(User.first) | |
1244 | issue.custom_field_values = {field.id => nil} |
|
1244 | issue.custom_field_values = {field.id => nil} | |
1245 | issue.save! |
|
1245 | issue.save! | |
1246 | end |
|
1246 | end | |
1247 | end |
|
1247 | end | |
1248 | end |
|
1248 | end | |
1249 |
|
1249 | |||
1250 | def test_description_eol_should_be_normalized |
|
1250 | def test_description_eol_should_be_normalized | |
1251 | i = Issue.new(:description => "CR \r LF \n CRLF \r\n") |
|
1251 | i = Issue.new(:description => "CR \r LF \n CRLF \r\n") | |
1252 | assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description |
|
1252 | assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description | |
1253 | end |
|
1253 | end | |
1254 |
|
1254 | |||
1255 | def test_saving_twice_should_not_duplicate_journal_details |
|
1255 | def test_saving_twice_should_not_duplicate_journal_details | |
1256 | i = Issue.find(:first) |
|
1256 | i = Issue.find(:first) | |
1257 | i.init_journal(User.find(2), 'Some notes') |
|
1257 | i.init_journal(User.find(2), 'Some notes') | |
1258 | # initial changes |
|
1258 | # initial changes | |
1259 | i.subject = 'New subject' |
|
1259 | i.subject = 'New subject' | |
1260 | i.done_ratio = i.done_ratio + 10 |
|
1260 | i.done_ratio = i.done_ratio + 10 | |
1261 | assert_difference 'Journal.count' do |
|
1261 | assert_difference 'Journal.count' do | |
1262 | assert i.save |
|
1262 | assert i.save | |
1263 | end |
|
1263 | end | |
1264 | # 1 more change |
|
1264 | # 1 more change | |
1265 | i.priority = IssuePriority.find(:first, :conditions => ["id <> ?", i.priority_id]) |
|
1265 | i.priority = IssuePriority.find(:first, :conditions => ["id <> ?", i.priority_id]) | |
1266 | assert_no_difference 'Journal.count' do |
|
1266 | assert_no_difference 'Journal.count' do | |
1267 | assert_difference 'JournalDetail.count', 1 do |
|
1267 | assert_difference 'JournalDetail.count', 1 do | |
1268 | i.save |
|
1268 | i.save | |
1269 | end |
|
1269 | end | |
1270 | end |
|
1270 | end | |
1271 | # no more change |
|
1271 | # no more change | |
1272 | assert_no_difference 'Journal.count' do |
|
1272 | assert_no_difference 'Journal.count' do | |
1273 | assert_no_difference 'JournalDetail.count' do |
|
1273 | assert_no_difference 'JournalDetail.count' do | |
1274 | i.save |
|
1274 | i.save | |
1275 | end |
|
1275 | end | |
1276 | end |
|
1276 | end | |
1277 | end |
|
1277 | end | |
1278 |
|
1278 | |||
1279 | def test_all_dependent_issues |
|
1279 | def test_all_dependent_issues | |
1280 | IssueRelation.delete_all |
|
1280 | IssueRelation.delete_all | |
1281 | assert IssueRelation.create!(:issue_from => Issue.find(1), |
|
1281 | assert IssueRelation.create!(:issue_from => Issue.find(1), | |
1282 | :issue_to => Issue.find(2), |
|
1282 | :issue_to => Issue.find(2), | |
1283 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1283 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
1284 | assert IssueRelation.create!(:issue_from => Issue.find(2), |
|
1284 | assert IssueRelation.create!(:issue_from => Issue.find(2), | |
1285 | :issue_to => Issue.find(3), |
|
1285 | :issue_to => Issue.find(3), | |
1286 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1286 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
1287 | assert IssueRelation.create!(:issue_from => Issue.find(3), |
|
1287 | assert IssueRelation.create!(:issue_from => Issue.find(3), | |
1288 | :issue_to => Issue.find(8), |
|
1288 | :issue_to => Issue.find(8), | |
1289 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1289 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
1290 |
|
1290 | |||
1291 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
1291 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
1292 | end |
|
1292 | end | |
1293 |
|
1293 | |||
1294 | def test_all_dependent_issues_with_persistent_circular_dependency |
|
1294 | def test_all_dependent_issues_with_persistent_circular_dependency | |
1295 | IssueRelation.delete_all |
|
1295 | IssueRelation.delete_all | |
1296 | assert IssueRelation.create!(:issue_from => Issue.find(1), |
|
1296 | assert IssueRelation.create!(:issue_from => Issue.find(1), | |
1297 | :issue_to => Issue.find(2), |
|
1297 | :issue_to => Issue.find(2), | |
1298 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1298 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
1299 | assert IssueRelation.create!(:issue_from => Issue.find(2), |
|
1299 | assert IssueRelation.create!(:issue_from => Issue.find(2), | |
1300 | :issue_to => Issue.find(3), |
|
1300 | :issue_to => Issue.find(3), | |
1301 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1301 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
1302 |
|
1302 | |||
1303 | r = IssueRelation.create!(:issue_from => Issue.find(3), |
|
1303 | r = IssueRelation.create!(:issue_from => Issue.find(3), | |
1304 | :issue_to => Issue.find(7), |
|
1304 | :issue_to => Issue.find(7), | |
1305 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
1305 | :relation_type => IssueRelation::TYPE_PRECEDES) | |
1306 | IssueRelation.update_all("issue_to_id = 1", ["id = ?", r.id]) |
|
1306 | IssueRelation.update_all("issue_to_id = 1", ["id = ?", r.id]) | |
1307 |
|
1307 | |||
1308 | assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
1308 | assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
1309 | end |
|
1309 | end | |
1310 |
|
1310 | |||
1311 | def test_all_dependent_issues_with_persistent_multiple_circular_dependencies |
|
1311 | def test_all_dependent_issues_with_persistent_multiple_circular_dependencies | |
1312 | IssueRelation.delete_all |
|
1312 | IssueRelation.delete_all | |
1313 | assert IssueRelation.create!(:issue_from => Issue.find(1), |
|
1313 | assert IssueRelation.create!(:issue_from => Issue.find(1), | |
1314 | :issue_to => Issue.find(2), |
|
1314 | :issue_to => Issue.find(2), | |
1315 | :relation_type => IssueRelation::TYPE_RELATES) |
|
1315 | :relation_type => IssueRelation::TYPE_RELATES) | |
1316 | assert IssueRelation.create!(:issue_from => Issue.find(2), |
|
1316 | assert IssueRelation.create!(:issue_from => Issue.find(2), | |
1317 | :issue_to => Issue.find(3), |
|
1317 | :issue_to => Issue.find(3), | |
1318 | :relation_type => IssueRelation::TYPE_RELATES) |
|
1318 | :relation_type => IssueRelation::TYPE_RELATES) | |
1319 | assert IssueRelation.create!(:issue_from => Issue.find(3), |
|
1319 | assert IssueRelation.create!(:issue_from => Issue.find(3), | |
1320 | :issue_to => Issue.find(8), |
|
1320 | :issue_to => Issue.find(8), | |
1321 | :relation_type => IssueRelation::TYPE_RELATES) |
|
1321 | :relation_type => IssueRelation::TYPE_RELATES) | |
1322 |
|
1322 | |||
1323 | r = IssueRelation.create!(:issue_from => Issue.find(8), |
|
1323 | r = IssueRelation.create!(:issue_from => Issue.find(8), | |
1324 | :issue_to => Issue.find(7), |
|
1324 | :issue_to => Issue.find(7), | |
1325 | :relation_type => IssueRelation::TYPE_RELATES) |
|
1325 | :relation_type => IssueRelation::TYPE_RELATES) | |
1326 | IssueRelation.update_all("issue_to_id = 2", ["id = ?", r.id]) |
|
1326 | IssueRelation.update_all("issue_to_id = 2", ["id = ?", r.id]) | |
1327 |
|
1327 | |||
1328 | r = IssueRelation.create!(:issue_from => Issue.find(3), |
|
1328 | r = IssueRelation.create!(:issue_from => Issue.find(3), | |
1329 | :issue_to => Issue.find(7), |
|
1329 | :issue_to => Issue.find(7), | |
1330 | :relation_type => IssueRelation::TYPE_RELATES) |
|
1330 | :relation_type => IssueRelation::TYPE_RELATES) | |
1331 | IssueRelation.update_all("issue_to_id = 1", ["id = ?", r.id]) |
|
1331 | IssueRelation.update_all("issue_to_id = 1", ["id = ?", r.id]) | |
1332 |
|
1332 | |||
1333 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
1333 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
1334 | end |
|
1334 | end | |
1335 |
|
1335 | |||
1336 | context "#done_ratio" do |
|
1336 | context "#done_ratio" do | |
1337 | setup do |
|
1337 | setup do | |
1338 | @issue = Issue.find(1) |
|
1338 | @issue = Issue.find(1) | |
1339 | @issue_status = IssueStatus.find(1) |
|
1339 | @issue_status = IssueStatus.find(1) | |
1340 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
1340 | @issue_status.update_attribute(:default_done_ratio, 50) | |
1341 | @issue2 = Issue.find(2) |
|
1341 | @issue2 = Issue.find(2) | |
1342 | @issue_status2 = IssueStatus.find(2) |
|
1342 | @issue_status2 = IssueStatus.find(2) | |
1343 | @issue_status2.update_attribute(:default_done_ratio, 0) |
|
1343 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
1344 | end |
|
1344 | end | |
1345 |
|
1345 | |||
1346 | teardown do |
|
1346 | teardown do | |
1347 | Setting.issue_done_ratio = 'issue_field' |
|
1347 | Setting.issue_done_ratio = 'issue_field' | |
1348 | end |
|
1348 | end | |
1349 |
|
1349 | |||
1350 | context "with Setting.issue_done_ratio using the issue_field" do |
|
1350 | context "with Setting.issue_done_ratio using the issue_field" do | |
1351 | setup do |
|
1351 | setup do | |
1352 | Setting.issue_done_ratio = 'issue_field' |
|
1352 | Setting.issue_done_ratio = 'issue_field' | |
1353 | end |
|
1353 | end | |
1354 |
|
1354 | |||
1355 | should "read the issue's field" do |
|
1355 | should "read the issue's field" do | |
1356 | assert_equal 0, @issue.done_ratio |
|
1356 | assert_equal 0, @issue.done_ratio | |
1357 | assert_equal 30, @issue2.done_ratio |
|
1357 | assert_equal 30, @issue2.done_ratio | |
1358 | end |
|
1358 | end | |
1359 | end |
|
1359 | end | |
1360 |
|
1360 | |||
1361 | context "with Setting.issue_done_ratio using the issue_status" do |
|
1361 | context "with Setting.issue_done_ratio using the issue_status" do | |
1362 | setup do |
|
1362 | setup do | |
1363 | Setting.issue_done_ratio = 'issue_status' |
|
1363 | Setting.issue_done_ratio = 'issue_status' | |
1364 | end |
|
1364 | end | |
1365 |
|
1365 | |||
1366 | should "read the Issue Status's default done ratio" do |
|
1366 | should "read the Issue Status's default done ratio" do | |
1367 | assert_equal 50, @issue.done_ratio |
|
1367 | assert_equal 50, @issue.done_ratio | |
1368 | assert_equal 0, @issue2.done_ratio |
|
1368 | assert_equal 0, @issue2.done_ratio | |
1369 | end |
|
1369 | end | |
1370 | end |
|
1370 | end | |
1371 | end |
|
1371 | end | |
1372 |
|
1372 | |||
1373 | context "#update_done_ratio_from_issue_status" do |
|
1373 | context "#update_done_ratio_from_issue_status" do | |
1374 | setup do |
|
1374 | setup do | |
1375 | @issue = Issue.find(1) |
|
1375 | @issue = Issue.find(1) | |
1376 | @issue_status = IssueStatus.find(1) |
|
1376 | @issue_status = IssueStatus.find(1) | |
1377 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
1377 | @issue_status.update_attribute(:default_done_ratio, 50) | |
1378 | @issue2 = Issue.find(2) |
|
1378 | @issue2 = Issue.find(2) | |
1379 | @issue_status2 = IssueStatus.find(2) |
|
1379 | @issue_status2 = IssueStatus.find(2) | |
1380 | @issue_status2.update_attribute(:default_done_ratio, 0) |
|
1380 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
1381 | end |
|
1381 | end | |
1382 |
|
1382 | |||
1383 | context "with Setting.issue_done_ratio using the issue_field" do |
|
1383 | context "with Setting.issue_done_ratio using the issue_field" do | |
1384 | setup do |
|
1384 | setup do | |
1385 | Setting.issue_done_ratio = 'issue_field' |
|
1385 | Setting.issue_done_ratio = 'issue_field' | |
1386 | end |
|
1386 | end | |
1387 |
|
1387 | |||
1388 | should "not change the issue" do |
|
1388 | should "not change the issue" do | |
1389 | @issue.update_done_ratio_from_issue_status |
|
1389 | @issue.update_done_ratio_from_issue_status | |
1390 | @issue2.update_done_ratio_from_issue_status |
|
1390 | @issue2.update_done_ratio_from_issue_status | |
1391 |
|
1391 | |||
1392 | assert_equal 0, @issue.read_attribute(:done_ratio) |
|
1392 | assert_equal 0, @issue.read_attribute(:done_ratio) | |
1393 | assert_equal 30, @issue2.read_attribute(:done_ratio) |
|
1393 | assert_equal 30, @issue2.read_attribute(:done_ratio) | |
1394 | end |
|
1394 | end | |
1395 | end |
|
1395 | end | |
1396 |
|
1396 | |||
1397 | context "with Setting.issue_done_ratio using the issue_status" do |
|
1397 | context "with Setting.issue_done_ratio using the issue_status" do | |
1398 | setup do |
|
1398 | setup do | |
1399 | Setting.issue_done_ratio = 'issue_status' |
|
1399 | Setting.issue_done_ratio = 'issue_status' | |
1400 | end |
|
1400 | end | |
1401 |
|
1401 | |||
1402 | should "change the issue's done ratio" do |
|
1402 | should "change the issue's done ratio" do | |
1403 | @issue.update_done_ratio_from_issue_status |
|
1403 | @issue.update_done_ratio_from_issue_status | |
1404 | @issue2.update_done_ratio_from_issue_status |
|
1404 | @issue2.update_done_ratio_from_issue_status | |
1405 |
|
1405 | |||
1406 | assert_equal 50, @issue.read_attribute(:done_ratio) |
|
1406 | assert_equal 50, @issue.read_attribute(:done_ratio) | |
1407 | assert_equal 0, @issue2.read_attribute(:done_ratio) |
|
1407 | assert_equal 0, @issue2.read_attribute(:done_ratio) | |
1408 | end |
|
1408 | end | |
1409 | end |
|
1409 | end | |
1410 | end |
|
1410 | end | |
1411 |
|
1411 | |||
1412 | test "#by_tracker" do |
|
1412 | test "#by_tracker" do | |
1413 | User.current = User.anonymous |
|
1413 | User.current = User.anonymous | |
1414 | groups = Issue.by_tracker(Project.find(1)) |
|
1414 | groups = Issue.by_tracker(Project.find(1)) | |
1415 | assert_equal 3, groups.size |
|
1415 | assert_equal 3, groups.size | |
1416 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1416 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1417 | end |
|
1417 | end | |
1418 |
|
1418 | |||
1419 | test "#by_version" do |
|
1419 | test "#by_version" do | |
1420 | User.current = User.anonymous |
|
1420 | User.current = User.anonymous | |
1421 | groups = Issue.by_version(Project.find(1)) |
|
1421 | groups = Issue.by_version(Project.find(1)) | |
1422 | assert_equal 3, groups.size |
|
1422 | assert_equal 3, groups.size | |
1423 | assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1423 | assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1424 | end |
|
1424 | end | |
1425 |
|
1425 | |||
1426 | test "#by_priority" do |
|
1426 | test "#by_priority" do | |
1427 | User.current = User.anonymous |
|
1427 | User.current = User.anonymous | |
1428 | groups = Issue.by_priority(Project.find(1)) |
|
1428 | groups = Issue.by_priority(Project.find(1)) | |
1429 | assert_equal 4, groups.size |
|
1429 | assert_equal 4, groups.size | |
1430 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1430 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1431 | end |
|
1431 | end | |
1432 |
|
1432 | |||
1433 | test "#by_category" do |
|
1433 | test "#by_category" do | |
1434 | User.current = User.anonymous |
|
1434 | User.current = User.anonymous | |
1435 | groups = Issue.by_category(Project.find(1)) |
|
1435 | groups = Issue.by_category(Project.find(1)) | |
1436 | assert_equal 2, groups.size |
|
1436 | assert_equal 2, groups.size | |
1437 | assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1437 | assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1438 | end |
|
1438 | end | |
1439 |
|
1439 | |||
1440 | test "#by_assigned_to" do |
|
1440 | test "#by_assigned_to" do | |
1441 | User.current = User.anonymous |
|
1441 | User.current = User.anonymous | |
1442 | groups = Issue.by_assigned_to(Project.find(1)) |
|
1442 | groups = Issue.by_assigned_to(Project.find(1)) | |
1443 | assert_equal 2, groups.size |
|
1443 | assert_equal 2, groups.size | |
1444 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1444 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1445 | end |
|
1445 | end | |
1446 |
|
1446 | |||
1447 | test "#by_author" do |
|
1447 | test "#by_author" do | |
1448 | User.current = User.anonymous |
|
1448 | User.current = User.anonymous | |
1449 | groups = Issue.by_author(Project.find(1)) |
|
1449 | groups = Issue.by_author(Project.find(1)) | |
1450 | assert_equal 4, groups.size |
|
1450 | assert_equal 4, groups.size | |
1451 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1451 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1452 | end |
|
1452 | end | |
1453 |
|
1453 | |||
1454 | test "#by_subproject" do |
|
1454 | test "#by_subproject" do | |
1455 | User.current = User.anonymous |
|
1455 | User.current = User.anonymous | |
1456 | groups = Issue.by_subproject(Project.find(1)) |
|
1456 | groups = Issue.by_subproject(Project.find(1)) | |
1457 | # Private descendant not visible |
|
1457 | # Private descendant not visible | |
1458 | assert_equal 1, groups.size |
|
1458 | assert_equal 1, groups.size | |
1459 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1459 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
1460 | end |
|
1460 | end | |
1461 |
|
1461 | |||
1462 |
def test_recently_updated_ |
|
1462 | def test_recently_updated_scope | |
1463 | #should return the last updated issue |
|
1463 | #should return the last updated issue | |
1464 |
assert_equal |
|
1464 | assert_equal Issue.reorder("updated_on DESC").first, Issue.recently_updated.limit(1).first | |
1465 | assert_equal Issue.find(:first, :order => "updated_on DESC"), Issue.recently_updated.with_limit(1).first |
|
|||
1466 | end |
|
1465 | end | |
1467 |
|
1466 | |||
1468 | def test_on_active_projects_scope |
|
1467 | def test_on_active_projects_scope | |
1469 | assert Project.find(2).archive |
|
1468 | assert Project.find(2).archive | |
1470 |
|
1469 | |||
1471 | before = Issue.on_active_project.length |
|
1470 | before = Issue.on_active_project.length | |
1472 | # test inclusion to results |
|
1471 | # test inclusion to results | |
1473 | issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first) |
|
1472 | issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first) | |
1474 | assert_equal before + 1, Issue.on_active_project.length |
|
1473 | assert_equal before + 1, Issue.on_active_project.length | |
1475 |
|
1474 | |||
1476 | # Move to an archived project |
|
1475 | # Move to an archived project | |
1477 | issue.project = Project.find(2) |
|
1476 | issue.project = Project.find(2) | |
1478 | assert issue.save |
|
1477 | assert issue.save | |
1479 | assert_equal before, Issue.on_active_project.length |
|
1478 | assert_equal before, Issue.on_active_project.length | |
1480 | end |
|
1479 | end | |
1481 |
|
1480 | |||
1482 | context "Issue#recipients" do |
|
1481 | context "Issue#recipients" do | |
1483 | setup do |
|
1482 | setup do | |
1484 | @project = Project.find(1) |
|
1483 | @project = Project.find(1) | |
1485 | @author = User.generate! |
|
1484 | @author = User.generate! | |
1486 | @assignee = User.generate! |
|
1485 | @assignee = User.generate! | |
1487 | @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) |
|
1486 | @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) | |
1488 | end |
|
1487 | end | |
1489 |
|
1488 | |||
1490 | should "include project recipients" do |
|
1489 | should "include project recipients" do | |
1491 | assert @project.recipients.present? |
|
1490 | assert @project.recipients.present? | |
1492 | @project.recipients.each do |project_recipient| |
|
1491 | @project.recipients.each do |project_recipient| | |
1493 | assert @issue.recipients.include?(project_recipient) |
|
1492 | assert @issue.recipients.include?(project_recipient) | |
1494 | end |
|
1493 | end | |
1495 | end |
|
1494 | end | |
1496 |
|
1495 | |||
1497 | should "include the author if the author is active" do |
|
1496 | should "include the author if the author is active" do | |
1498 | assert @issue.author, "No author set for Issue" |
|
1497 | assert @issue.author, "No author set for Issue" | |
1499 | assert @issue.recipients.include?(@issue.author.mail) |
|
1498 | assert @issue.recipients.include?(@issue.author.mail) | |
1500 | end |
|
1499 | end | |
1501 |
|
1500 | |||
1502 | should "include the assigned to user if the assigned to user is active" do |
|
1501 | should "include the assigned to user if the assigned to user is active" do | |
1503 | assert @issue.assigned_to, "No assigned_to set for Issue" |
|
1502 | assert @issue.assigned_to, "No assigned_to set for Issue" | |
1504 | assert @issue.recipients.include?(@issue.assigned_to.mail) |
|
1503 | assert @issue.recipients.include?(@issue.assigned_to.mail) | |
1505 | end |
|
1504 | end | |
1506 |
|
1505 | |||
1507 | should "not include users who opt out of all email" do |
|
1506 | should "not include users who opt out of all email" do | |
1508 | @author.update_attribute(:mail_notification, :none) |
|
1507 | @author.update_attribute(:mail_notification, :none) | |
1509 |
|
1508 | |||
1510 | assert !@issue.recipients.include?(@issue.author.mail) |
|
1509 | assert !@issue.recipients.include?(@issue.author.mail) | |
1511 | end |
|
1510 | end | |
1512 |
|
1511 | |||
1513 | should "not include the issue author if they are only notified of assigned issues" do |
|
1512 | should "not include the issue author if they are only notified of assigned issues" do | |
1514 | @author.update_attribute(:mail_notification, :only_assigned) |
|
1513 | @author.update_attribute(:mail_notification, :only_assigned) | |
1515 |
|
1514 | |||
1516 | assert !@issue.recipients.include?(@issue.author.mail) |
|
1515 | assert !@issue.recipients.include?(@issue.author.mail) | |
1517 | end |
|
1516 | end | |
1518 |
|
1517 | |||
1519 | should "not include the assigned user if they are only notified of owned issues" do |
|
1518 | should "not include the assigned user if they are only notified of owned issues" do | |
1520 | @assignee.update_attribute(:mail_notification, :only_owner) |
|
1519 | @assignee.update_attribute(:mail_notification, :only_owner) | |
1521 |
|
1520 | |||
1522 | assert !@issue.recipients.include?(@issue.assigned_to.mail) |
|
1521 | assert !@issue.recipients.include?(@issue.assigned_to.mail) | |
1523 | end |
|
1522 | end | |
1524 | end |
|
1523 | end | |
1525 |
|
1524 | |||
1526 | def test_last_journal_id_with_journals_should_return_the_journal_id |
|
1525 | def test_last_journal_id_with_journals_should_return_the_journal_id | |
1527 | assert_equal 2, Issue.find(1).last_journal_id |
|
1526 | assert_equal 2, Issue.find(1).last_journal_id | |
1528 | end |
|
1527 | end | |
1529 |
|
1528 | |||
1530 | def test_last_journal_id_without_journals_should_return_nil |
|
1529 | def test_last_journal_id_without_journals_should_return_nil | |
1531 | assert_nil Issue.find(3).last_journal_id |
|
1530 | assert_nil Issue.find(3).last_journal_id | |
1532 | end |
|
1531 | end | |
1533 |
|
1532 | |||
1534 | def test_journals_after_should_return_journals_with_greater_id |
|
1533 | def test_journals_after_should_return_journals_with_greater_id | |
1535 | assert_equal [Journal.find(2)], Issue.find(1).journals_after('1') |
|
1534 | assert_equal [Journal.find(2)], Issue.find(1).journals_after('1') | |
1536 | assert_equal [], Issue.find(1).journals_after('2') |
|
1535 | assert_equal [], Issue.find(1).journals_after('2') | |
1537 | end |
|
1536 | end | |
1538 |
|
1537 | |||
1539 | def test_journals_after_with_blank_arg_should_return_all_journals |
|
1538 | def test_journals_after_with_blank_arg_should_return_all_journals | |
1540 | assert_equal [Journal.find(1), Journal.find(2)], Issue.find(1).journals_after('') |
|
1539 | assert_equal [Journal.find(1), Journal.find(2)], Issue.find(1).journals_after('') | |
1541 | end |
|
1540 | end | |
1542 | end |
|
1541 | end |
General Comments 0
You need to be logged in to leave comments.
Login now