@@ -5,12 +5,12 | |||||
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. | |
@@ -22,7 +22,7 class IssueTest < ActiveSupport::TestCase | |||||
22 | :trackers, :projects_trackers, |
|
22 | :trackers, :projects_trackers, | |
23 | :enabled_modules, |
|
23 | :enabled_modules, | |
24 | :versions, |
|
24 | :versions, | |
25 |
:issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
25 | :issue_statuses, :issue_categories, :issue_relations, :workflows, | |
26 | :enumerations, |
|
26 | :enumerations, | |
27 | :issues, |
|
27 | :issues, | |
28 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
|
28 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | |
@@ -34,17 +34,17 class IssueTest < ActiveSupport::TestCase | |||||
34 | issue.reload |
|
34 | issue.reload | |
35 | assert_equal 1.5, issue.estimated_hours |
|
35 | assert_equal 1.5, issue.estimated_hours | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_create_minimal |
|
38 | def test_create_minimal | |
39 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create') |
|
39 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create') | |
40 | assert issue.save |
|
40 | assert issue.save | |
41 | assert issue.description.nil? |
|
41 | assert issue.description.nil? | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_create_with_required_custom_field |
|
44 | def test_create_with_required_custom_field | |
45 | field = IssueCustomField.find_by_name('Database') |
|
45 | field = IssueCustomField.find_by_name('Database') | |
46 | field.update_attribute(:is_required, true) |
|
46 | field.update_attribute(:is_required, true) | |
47 |
|
47 | |||
48 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
|
48 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') | |
49 | assert issue.available_custom_fields.include?(field) |
|
49 | assert issue.available_custom_fields.include?(field) | |
50 | # No value for the custom field |
|
50 | # No value for the custom field | |
@@ -64,7 +64,7 class IssueTest < ActiveSupport::TestCase | |||||
64 | issue.reload |
|
64 | issue.reload | |
65 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
65 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def assert_visibility_match(user, issues) |
|
68 | def assert_visibility_match(user, issues) | |
69 | assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort |
|
69 | assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort | |
70 | end |
|
70 | end | |
@@ -77,17 +77,17 class IssueTest < ActiveSupport::TestCase | |||||
77 | assert_nil issues.detect {|issue| issue.is_private?} |
|
77 | assert_nil issues.detect {|issue| issue.is_private?} | |
78 | assert_visibility_match User.anonymous, issues |
|
78 | assert_visibility_match User.anonymous, issues | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_visible_scope_for_anonymous_with_own_issues_visibility |
|
81 | def test_visible_scope_for_anonymous_with_own_issues_visibility | |
82 | Role.anonymous.update_attribute :issues_visibility, 'own' |
|
82 | Role.anonymous.update_attribute :issues_visibility, 'own' | |
83 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => User.anonymous.id, :subject => 'Issue by anonymous') |
|
83 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => User.anonymous.id, :subject => 'Issue by anonymous') | |
84 |
|
84 | |||
85 | issues = Issue.visible(User.anonymous).all |
|
85 | issues = Issue.visible(User.anonymous).all | |
86 | assert issues.any? |
|
86 | assert issues.any? | |
87 | assert_nil issues.detect {|issue| issue.author != User.anonymous} |
|
87 | assert_nil issues.detect {|issue| issue.author != User.anonymous} | |
88 | assert_visibility_match User.anonymous, issues |
|
88 | assert_visibility_match User.anonymous, issues | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def test_visible_scope_for_anonymous_without_view_issues_permissions |
|
91 | def test_visible_scope_for_anonymous_without_view_issues_permissions | |
92 | # Anonymous user should not see issues without permission |
|
92 | # Anonymous user should not see issues without permission | |
93 | Role.anonymous.remove_permission!(:view_issues) |
|
93 | Role.anonymous.remove_permission!(:view_issues) | |
@@ -95,7 +95,7 class IssueTest < ActiveSupport::TestCase | |||||
95 | assert issues.empty? |
|
95 | assert issues.empty? | |
96 | assert_visibility_match User.anonymous, issues |
|
96 | assert_visibility_match User.anonymous, issues | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_visible_scope_for_non_member |
|
99 | def test_visible_scope_for_non_member | |
100 | user = User.find(9) |
|
100 | user = User.find(9) | |
101 | assert user.projects.empty? |
|
101 | assert user.projects.empty? | |
@@ -106,18 +106,18 class IssueTest < ActiveSupport::TestCase | |||||
106 | assert_nil issues.detect {|issue| issue.is_private?} |
|
106 | assert_nil issues.detect {|issue| issue.is_private?} | |
107 | assert_visibility_match user, issues |
|
107 | assert_visibility_match user, issues | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_visible_scope_for_non_member_with_own_issues_visibility |
|
110 | def test_visible_scope_for_non_member_with_own_issues_visibility | |
111 | Role.non_member.update_attribute :issues_visibility, 'own' |
|
111 | Role.non_member.update_attribute :issues_visibility, 'own' | |
112 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') |
|
112 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') | |
113 | user = User.find(9) |
|
113 | user = User.find(9) | |
114 |
|
114 | |||
115 | issues = Issue.visible(user).all |
|
115 | issues = Issue.visible(user).all | |
116 | assert issues.any? |
|
116 | assert issues.any? | |
117 | assert_nil issues.detect {|issue| issue.author != user} |
|
117 | assert_nil issues.detect {|issue| issue.author != user} | |
118 | assert_visibility_match user, issues |
|
118 | assert_visibility_match user, issues | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_visible_scope_for_non_member_without_view_issues_permissions |
|
121 | def test_visible_scope_for_non_member_without_view_issues_permissions | |
122 | # Non member user should not see issues without permission |
|
122 | # Non member user should not see issues without permission | |
123 | Role.non_member.remove_permission!(:view_issues) |
|
123 | Role.non_member.remove_permission!(:view_issues) | |
@@ -127,7 +127,7 class IssueTest < ActiveSupport::TestCase | |||||
127 | assert issues.empty? |
|
127 | assert issues.empty? | |
128 | assert_visibility_match user, issues |
|
128 | assert_visibility_match user, issues | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def test_visible_scope_for_member |
|
131 | def test_visible_scope_for_member | |
132 | user = User.find(9) |
|
132 | user = User.find(9) | |
133 | # User should see issues of projects for which he has view_issues permissions only |
|
133 | # User should see issues of projects for which he has view_issues permissions only | |
@@ -139,7 +139,7 class IssueTest < ActiveSupport::TestCase | |||||
139 | assert_nil issues.detect {|issue| issue.is_private?} |
|
139 | assert_nil issues.detect {|issue| issue.is_private?} | |
140 | assert_visibility_match user, issues |
|
140 | assert_visibility_match user, issues | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_visible_scope_for_admin |
|
143 | def test_visible_scope_for_admin | |
144 | user = User.find(1) |
|
144 | user = User.find(1) | |
145 | user.members.each(&:destroy) |
|
145 | user.members.each(&:destroy) | |
@@ -152,7 +152,7 class IssueTest < ActiveSupport::TestCase | |||||
152 | assert issues.detect {|issue| issue.is_private? && issue.author != user} |
|
152 | assert issues.detect {|issue| issue.is_private? && issue.author != user} | |
153 | assert_visibility_match user, issues |
|
153 | assert_visibility_match user, issues | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def test_visible_scope_with_project |
|
156 | def test_visible_scope_with_project | |
157 | project = Project.find(1) |
|
157 | project = Project.find(1) | |
158 | issues = Issue.visible(User.find(2), :project => project).all |
|
158 | issues = Issue.visible(User.find(2), :project => project).all | |
@@ -160,7 +160,7 class IssueTest < ActiveSupport::TestCase | |||||
160 | assert_equal 1, projects.size |
|
160 | assert_equal 1, projects.size | |
161 | assert_equal project, projects.first |
|
161 | assert_equal project, projects.first | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def test_visible_scope_with_project_and_subprojects |
|
164 | def test_visible_scope_with_project_and_subprojects | |
165 | project = Project.find(1) |
|
165 | project = Project.find(1) | |
166 | issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all |
|
166 | issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all | |
@@ -168,28 +168,28 class IssueTest < ActiveSupport::TestCase | |||||
168 | assert projects.size > 1 |
|
168 | assert projects.size > 1 | |
169 | assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} |
|
169 | assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | def test_visible_and_nested_set_scopes |
|
172 | def test_visible_and_nested_set_scopes | |
173 | assert_equal 0, Issue.find(1).descendants.visible.all.size |
|
173 | assert_equal 0, Issue.find(1).descendants.visible.all.size | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | def test_errors_full_messages_should_include_custom_fields_errors |
|
176 | def test_errors_full_messages_should_include_custom_fields_errors | |
177 | field = IssueCustomField.find_by_name('Database') |
|
177 | field = IssueCustomField.find_by_name('Database') | |
178 |
|
178 | |||
179 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
|
179 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') | |
180 | assert issue.available_custom_fields.include?(field) |
|
180 | assert issue.available_custom_fields.include?(field) | |
181 | # Invalid value |
|
181 | # Invalid value | |
182 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
182 | issue.custom_field_values = { field.id => 'SQLServer' } | |
183 |
|
183 | |||
184 | assert !issue.valid? |
|
184 | assert !issue.valid? | |
185 | assert_equal 1, issue.errors.full_messages.size |
|
185 | assert_equal 1, issue.errors.full_messages.size | |
186 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first |
|
186 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | def test_update_issue_with_required_custom_field |
|
189 | def test_update_issue_with_required_custom_field | |
190 | field = IssueCustomField.find_by_name('Database') |
|
190 | field = IssueCustomField.find_by_name('Database') | |
191 | field.update_attribute(:is_required, true) |
|
191 | field.update_attribute(:is_required, true) | |
192 |
|
192 | |||
193 | issue = Issue.find(1) |
|
193 | issue = Issue.find(1) | |
194 | assert_nil issue.custom_value_for(field) |
|
194 | assert_nil issue.custom_value_for(field) | |
195 | assert issue.available_custom_fields.include?(field) |
|
195 | assert issue.available_custom_fields.include?(field) | |
@@ -204,23 +204,23 class IssueTest < ActiveSupport::TestCase | |||||
204 | issue.reload |
|
204 | issue.reload | |
205 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
205 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def test_should_not_update_attributes_if_custom_fields_validation_fails |
|
208 | def test_should_not_update_attributes_if_custom_fields_validation_fails | |
209 | issue = Issue.find(1) |
|
209 | issue = Issue.find(1) | |
210 | field = IssueCustomField.find_by_name('Database') |
|
210 | field = IssueCustomField.find_by_name('Database') | |
211 | assert issue.available_custom_fields.include?(field) |
|
211 | assert issue.available_custom_fields.include?(field) | |
212 |
|
212 | |||
213 | issue.custom_field_values = { field.id => 'Invalid' } |
|
213 | issue.custom_field_values = { field.id => 'Invalid' } | |
214 | issue.subject = 'Should be not be saved' |
|
214 | issue.subject = 'Should be not be saved' | |
215 | assert !issue.save |
|
215 | assert !issue.save | |
216 |
|
216 | |||
217 | issue.reload |
|
217 | issue.reload | |
218 | assert_equal "Can't print recipes", issue.subject |
|
218 | assert_equal "Can't print recipes", issue.subject | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def test_should_not_recreate_custom_values_objects_on_update |
|
221 | def test_should_not_recreate_custom_values_objects_on_update | |
222 | field = IssueCustomField.find_by_name('Database') |
|
222 | field = IssueCustomField.find_by_name('Database') | |
223 |
|
223 | |||
224 | issue = Issue.find(1) |
|
224 | issue = Issue.find(1) | |
225 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
225 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
226 | assert issue.save |
|
226 | assert issue.save | |
@@ -231,14 +231,14 class IssueTest < ActiveSupport::TestCase | |||||
231 | issue.reload |
|
231 | issue.reload | |
232 | assert_equal custom_value.id, issue.custom_value_for(field).id |
|
232 | assert_equal custom_value.id, issue.custom_value_for(field).id | |
233 | end |
|
233 | end | |
234 |
|
234 | |||
235 | def test_assigning_tracker_id_should_reload_custom_fields_values |
|
235 | def test_assigning_tracker_id_should_reload_custom_fields_values | |
236 | issue = Issue.new(:project => Project.find(1)) |
|
236 | issue = Issue.new(:project => Project.find(1)) | |
237 | assert issue.custom_field_values.empty? |
|
237 | assert issue.custom_field_values.empty? | |
238 | issue.tracker_id = 1 |
|
238 | issue.tracker_id = 1 | |
239 | assert issue.custom_field_values.any? |
|
239 | assert issue.custom_field_values.any? | |
240 | end |
|
240 | end | |
241 |
|
241 | |||
242 | def test_assigning_attributes_should_assign_tracker_id_first |
|
242 | def test_assigning_attributes_should_assign_tracker_id_first | |
243 | attributes = ActiveSupport::OrderedHash.new |
|
243 | attributes = ActiveSupport::OrderedHash.new | |
244 | attributes['custom_field_values'] = { '1' => 'MySQL' } |
|
244 | attributes['custom_field_values'] = { '1' => 'MySQL' } | |
@@ -248,40 +248,38 class IssueTest < ActiveSupport::TestCase | |||||
248 | assert_not_nil issue.custom_value_for(1) |
|
248 | assert_not_nil issue.custom_value_for(1) | |
249 | assert_equal 'MySQL', issue.custom_value_for(1).value |
|
249 | assert_equal 'MySQL', issue.custom_value_for(1).value | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | def test_should_update_issue_with_disabled_tracker |
|
252 | def test_should_update_issue_with_disabled_tracker | |
253 | p = Project.find(1) |
|
253 | p = Project.find(1) | |
254 | issue = Issue.find(1) |
|
254 | issue = Issue.find(1) | |
255 |
|
255 | |||
256 | p.trackers.delete(issue.tracker) |
|
256 | p.trackers.delete(issue.tracker) | |
257 | assert !p.trackers.include?(issue.tracker) |
|
257 | assert !p.trackers.include?(issue.tracker) | |
258 |
|
258 | |||
259 | issue.reload |
|
259 | issue.reload | |
260 | issue.subject = 'New subject' |
|
260 | issue.subject = 'New subject' | |
261 | assert issue.save |
|
261 | assert issue.save | |
262 | end |
|
262 | end | |
263 |
|
263 | |||
264 | def test_should_not_set_a_disabled_tracker |
|
264 | def test_should_not_set_a_disabled_tracker | |
265 | p = Project.find(1) |
|
265 | p = Project.find(1) | |
266 | p.trackers.delete(Tracker.find(2)) |
|
266 | p.trackers.delete(Tracker.find(2)) | |
267 |
|
267 | |||
268 | issue = Issue.find(1) |
|
268 | issue = Issue.find(1) | |
269 | issue.tracker_id = 2 |
|
269 | issue.tracker_id = 2 | |
270 | issue.subject = 'New subject' |
|
270 | issue.subject = 'New subject' | |
271 | assert !issue.save |
|
271 | assert !issue.save | |
272 | assert_not_nil issue.errors.on(:tracker_id) |
|
272 | assert_not_nil issue.errors.on(:tracker_id) | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | def test_category_based_assignment |
|
275 | def test_category_based_assignment | |
276 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) |
|
276 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) | |
277 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
277 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to | |
278 | end |
|
278 | end | |
279 |
|
279 | |||
280 |
|
||||
281 |
|
||||
282 | def test_new_statuses_allowed_to |
|
280 | def test_new_statuses_allowed_to | |
283 | Workflow.delete_all |
|
281 | Workflow.delete_all | |
284 |
|
282 | |||
285 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false) |
|
283 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false) | |
286 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false) |
|
284 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false) | |
287 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true) |
|
285 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true) | |
@@ -290,20 +288,20 class IssueTest < ActiveSupport::TestCase | |||||
290 | role = Role.find(1) |
|
288 | role = Role.find(1) | |
291 | tracker = Tracker.find(1) |
|
289 | tracker = Tracker.find(1) | |
292 | user = User.find(2) |
|
290 | user = User.find(2) | |
293 |
|
291 | |||
294 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1) |
|
292 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1) | |
295 | assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id) |
|
293 | assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id) | |
296 |
|
294 | |||
297 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user) |
|
295 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user) | |
298 | assert_equal [1, 2, 3], issue.new_statuses_allowed_to(user).map(&:id) |
|
296 | assert_equal [1, 2, 3], issue.new_statuses_allowed_to(user).map(&:id) | |
299 |
|
297 | |||
300 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :assigned_to => user) |
|
298 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :assigned_to => user) | |
301 | assert_equal [1, 2, 4], issue.new_statuses_allowed_to(user).map(&:id) |
|
299 | assert_equal [1, 2, 4], issue.new_statuses_allowed_to(user).map(&:id) | |
302 |
|
300 | |||
303 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user, :assigned_to => user) |
|
301 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user, :assigned_to => user) | |
304 | assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
302 | assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
305 | end |
|
303 | end | |
306 |
|
304 | |||
307 | def test_copy |
|
305 | def test_copy | |
308 | issue = Issue.new.copy_from(1) |
|
306 | issue = Issue.new.copy_from(1) | |
309 | assert issue.save |
|
307 | assert issue.save | |
@@ -317,13 +315,13 class IssueTest < ActiveSupport::TestCase | |||||
317 | def test_copy_should_copy_status |
|
315 | def test_copy_should_copy_status | |
318 | orig = Issue.find(8) |
|
316 | orig = Issue.find(8) | |
319 | assert orig.status != IssueStatus.default |
|
317 | assert orig.status != IssueStatus.default | |
320 |
|
318 | |||
321 | issue = Issue.new.copy_from(orig) |
|
319 | issue = Issue.new.copy_from(orig) | |
322 | assert issue.save |
|
320 | assert issue.save | |
323 | issue.reload |
|
321 | issue.reload | |
324 | assert_equal orig.status, issue.status |
|
322 | assert_equal orig.status, issue.status | |
325 | end |
|
323 | end | |
326 |
|
324 | |||
327 | def test_should_close_duplicates |
|
325 | def test_should_close_duplicates | |
328 | # Create 3 issues |
|
326 | # Create 3 issues | |
329 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') |
|
327 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') | |
@@ -332,37 +330,37 class IssueTest < ActiveSupport::TestCase | |||||
332 | assert issue2.save |
|
330 | assert issue2.save | |
333 | issue3 = issue1.clone |
|
331 | issue3 = issue1.clone | |
334 | assert issue3.save |
|
332 | assert issue3.save | |
335 |
|
333 | |||
336 | # 2 is a dupe of 1 |
|
334 | # 2 is a dupe of 1 | |
337 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
335 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
338 | # And 3 is a dupe of 2 |
|
336 | # And 3 is a dupe of 2 | |
339 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
337 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
340 | # And 3 is a dupe of 1 (circular duplicates) |
|
338 | # And 3 is a dupe of 1 (circular duplicates) | |
341 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
339 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
342 |
|
340 | |||
343 | assert issue1.reload.duplicates.include?(issue2) |
|
341 | assert issue1.reload.duplicates.include?(issue2) | |
344 |
|
342 | |||
345 | # Closing issue 1 |
|
343 | # Closing issue 1 | |
346 | issue1.init_journal(User.find(:first), "Closing issue1") |
|
344 | issue1.init_journal(User.find(:first), "Closing issue1") | |
347 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
345 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
348 | assert issue1.save |
|
346 | assert issue1.save | |
349 | # 2 and 3 should be also closed |
|
347 | # 2 and 3 should be also closed | |
350 | assert issue2.reload.closed? |
|
348 | assert issue2.reload.closed? | |
351 |
assert issue3.reload.closed? |
|
349 | assert issue3.reload.closed? | |
352 | end |
|
350 | end | |
353 |
|
351 | |||
354 | def test_should_not_close_duplicated_issue |
|
352 | def test_should_not_close_duplicated_issue | |
355 | # Create 3 issues |
|
353 | # Create 3 issues | |
356 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') |
|
354 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') | |
357 | assert issue1.save |
|
355 | assert issue1.save | |
358 | issue2 = issue1.clone |
|
356 | issue2 = issue1.clone | |
359 | assert issue2.save |
|
357 | assert issue2.save | |
360 |
|
358 | |||
361 | # 2 is a dupe of 1 |
|
359 | # 2 is a dupe of 1 | |
362 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
360 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
363 | # 2 is a dup of 1 but 1 is not a duplicate of 2 |
|
361 | # 2 is a dup of 1 but 1 is not a duplicate of 2 | |
364 | assert !issue2.reload.duplicates.include?(issue1) |
|
362 | assert !issue2.reload.duplicates.include?(issue1) | |
365 |
|
363 | |||
366 | # Closing issue 2 |
|
364 | # Closing issue 2 | |
367 | issue2.init_journal(User.find(:first), "Closing issue2") |
|
365 | issue2.init_journal(User.find(:first), "Closing issue2") | |
368 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
366 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
@@ -370,57 +368,57 class IssueTest < ActiveSupport::TestCase | |||||
370 | # 1 should not be also closed |
|
368 | # 1 should not be also closed | |
371 | assert !issue1.reload.closed? |
|
369 | assert !issue1.reload.closed? | |
372 | end |
|
370 | end | |
373 |
|
371 | |||
374 | def test_assignable_versions |
|
372 | def test_assignable_versions | |
375 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
373 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') | |
376 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq |
|
374 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq | |
377 | end |
|
375 | end | |
378 |
|
376 | |||
379 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version |
|
377 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version | |
380 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
378 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') | |
381 | assert !issue.save |
|
379 | assert !issue.save | |
382 | assert_not_nil issue.errors.on(:fixed_version_id) |
|
380 | assert_not_nil issue.errors.on(:fixed_version_id) | |
383 | end |
|
381 | end | |
384 |
|
382 | |||
385 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version |
|
383 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version | |
386 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') |
|
384 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') | |
387 | assert !issue.save |
|
385 | assert !issue.save | |
388 | assert_not_nil issue.errors.on(:fixed_version_id) |
|
386 | assert_not_nil issue.errors.on(:fixed_version_id) | |
389 | end |
|
387 | end | |
390 |
|
388 | |||
391 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version |
|
389 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version | |
392 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') |
|
390 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') | |
393 | assert issue.save |
|
391 | assert issue.save | |
394 | end |
|
392 | end | |
395 |
|
393 | |||
396 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version |
|
394 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version | |
397 | issue = Issue.find(11) |
|
395 | issue = Issue.find(11) | |
398 | assert_equal 'closed', issue.fixed_version.status |
|
396 | assert_equal 'closed', issue.fixed_version.status | |
399 | issue.subject = 'Subject changed' |
|
397 | issue.subject = 'Subject changed' | |
400 | assert issue.save |
|
398 | assert issue.save | |
401 | end |
|
399 | end | |
402 |
|
400 | |||
403 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version |
|
401 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version | |
404 | issue = Issue.find(11) |
|
402 | issue = Issue.find(11) | |
405 | issue.status_id = 1 |
|
403 | issue.status_id = 1 | |
406 | assert !issue.save |
|
404 | assert !issue.save | |
407 | assert_not_nil issue.errors.on_base |
|
405 | assert_not_nil issue.errors.on_base | |
408 | end |
|
406 | end | |
409 |
|
407 | |||
410 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version |
|
408 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version | |
411 | issue = Issue.find(11) |
|
409 | issue = Issue.find(11) | |
412 | issue.status_id = 1 |
|
410 | issue.status_id = 1 | |
413 | issue.fixed_version_id = 3 |
|
411 | issue.fixed_version_id = 3 | |
414 | assert issue.save |
|
412 | assert issue.save | |
415 | end |
|
413 | end | |
416 |
|
414 | |||
417 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version |
|
415 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version | |
418 | issue = Issue.find(12) |
|
416 | issue = Issue.find(12) | |
419 | assert_equal 'locked', issue.fixed_version.status |
|
417 | assert_equal 'locked', issue.fixed_version.status | |
420 | issue.status_id = 1 |
|
418 | issue.status_id = 1 | |
421 | assert issue.save |
|
419 | assert issue.save | |
422 | end |
|
420 | end | |
423 |
|
421 | |||
424 | def test_move_to_another_project_with_same_category |
|
422 | def test_move_to_another_project_with_same_category | |
425 | issue = Issue.find(1) |
|
423 | issue = Issue.find(1) | |
426 | assert issue.move_to_project(Project.find(2)) |
|
424 | assert issue.move_to_project(Project.find(2)) | |
@@ -431,7 +429,7 class IssueTest < ActiveSupport::TestCase | |||||
431 | # Make sure time entries were move to the target project |
|
429 | # Make sure time entries were move to the target project | |
432 | assert_equal 2, issue.time_entries.first.project_id |
|
430 | assert_equal 2, issue.time_entries.first.project_id | |
433 | end |
|
431 | end | |
434 |
|
432 | |||
435 | def test_move_to_another_project_without_same_category |
|
433 | def test_move_to_another_project_without_same_category | |
436 | issue = Issue.find(2) |
|
434 | issue = Issue.find(2) | |
437 | assert issue.move_to_project(Project.find(2)) |
|
435 | assert issue.move_to_project(Project.find(2)) | |
@@ -440,7 +438,7 class IssueTest < ActiveSupport::TestCase | |||||
440 | # Category cleared |
|
438 | # Category cleared | |
441 | assert_nil issue.category_id |
|
439 | assert_nil issue.category_id | |
442 | end |
|
440 | end | |
443 |
|
441 | |||
444 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared |
|
442 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared | |
445 | issue = Issue.find(1) |
|
443 | issue = Issue.find(1) | |
446 | issue.update_attribute(:fixed_version_id, 1) |
|
444 | issue.update_attribute(:fixed_version_id, 1) | |
@@ -450,7 +448,7 class IssueTest < ActiveSupport::TestCase | |||||
450 | # Cleared fixed_version |
|
448 | # Cleared fixed_version | |
451 | assert_equal nil, issue.fixed_version |
|
449 | assert_equal nil, issue.fixed_version | |
452 | end |
|
450 | end | |
453 |
|
451 | |||
454 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project |
|
452 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project | |
455 | issue = Issue.find(1) |
|
453 | issue = Issue.find(1) | |
456 | issue.update_attribute(:fixed_version_id, 4) |
|
454 | issue.update_attribute(:fixed_version_id, 4) | |
@@ -460,7 +458,7 class IssueTest < ActiveSupport::TestCase | |||||
460 | # Keep fixed_version |
|
458 | # Keep fixed_version | |
461 | assert_equal 4, issue.fixed_version_id |
|
459 | assert_equal 4, issue.fixed_version_id | |
462 | end |
|
460 | end | |
463 |
|
461 | |||
464 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project |
|
462 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project | |
465 | issue = Issue.find(1) |
|
463 | issue = Issue.find(1) | |
466 | issue.update_attribute(:fixed_version_id, 1) |
|
464 | issue.update_attribute(:fixed_version_id, 1) | |
@@ -470,7 +468,7 class IssueTest < ActiveSupport::TestCase | |||||
470 | # Cleared fixed_version |
|
468 | # Cleared fixed_version | |
471 | assert_equal nil, issue.fixed_version |
|
469 | assert_equal nil, issue.fixed_version | |
472 | end |
|
470 | end | |
473 |
|
471 | |||
474 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide |
|
472 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide | |
475 | issue = Issue.find(1) |
|
473 | issue = Issue.find(1) | |
476 | issue.update_attribute(:fixed_version_id, 7) |
|
474 | issue.update_attribute(:fixed_version_id, 7) | |
@@ -480,7 +478,7 class IssueTest < ActiveSupport::TestCase | |||||
480 | # Keep fixed_version |
|
478 | # Keep fixed_version | |
481 | assert_equal 7, issue.fixed_version_id |
|
479 | assert_equal 7, issue.fixed_version_id | |
482 | end |
|
480 | end | |
483 |
|
481 | |||
484 | def test_move_to_another_project_with_disabled_tracker |
|
482 | def test_move_to_another_project_with_disabled_tracker | |
485 | issue = Issue.find(1) |
|
483 | issue = Issue.find(1) | |
486 | target = Project.find(2) |
|
484 | target = Project.find(2) | |
@@ -490,7 +488,7 class IssueTest < ActiveSupport::TestCase | |||||
490 | issue.reload |
|
488 | issue.reload | |
491 | assert_equal 1, issue.project_id |
|
489 | assert_equal 1, issue.project_id | |
492 | end |
|
490 | end | |
493 |
|
491 | |||
494 | def test_copy_to_the_same_project |
|
492 | def test_copy_to_the_same_project | |
495 | issue = Issue.find(1) |
|
493 | issue = Issue.find(1) | |
496 | copy = nil |
|
494 | copy = nil | |
@@ -501,7 +499,7 class IssueTest < ActiveSupport::TestCase | |||||
501 | assert_equal issue.project, copy.project |
|
499 | assert_equal issue.project, copy.project | |
502 | assert_equal "125", copy.custom_value_for(2).value |
|
500 | assert_equal "125", copy.custom_value_for(2).value | |
503 | end |
|
501 | end | |
504 |
|
502 | |||
505 | def test_copy_to_another_project_and_tracker |
|
503 | def test_copy_to_another_project_and_tracker | |
506 | issue = Issue.find(1) |
|
504 | issue = Issue.find(1) | |
507 | copy = nil |
|
505 | copy = nil | |
@@ -522,7 +520,7 class IssueTest < ActiveSupport::TestCase | |||||
522 | @issue = Issue.find(1) |
|
520 | @issue = Issue.find(1) | |
523 | @copy = nil |
|
521 | @copy = nil | |
524 | end |
|
522 | end | |
525 |
|
523 | |||
526 | should "not create a journal" do |
|
524 | should "not create a journal" do | |
527 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) |
|
525 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) | |
528 | assert_equal 0, @copy.reload.journals.size |
|
526 | assert_equal 0, @copy.reload.journals.size | |
@@ -550,14 +548,14 class IssueTest < ActiveSupport::TestCase | |||||
550 |
|
548 | |||
551 | assert_equal date, @copy.due_date |
|
549 | assert_equal date, @copy.due_date | |
552 | end |
|
550 | end | |
553 |
|
551 | |||
554 | should "set current user as author" do |
|
552 | should "set current user as author" do | |
555 | User.current = User.find(9) |
|
553 | User.current = User.find(9) | |
556 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {}}) |
|
554 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {}}) | |
557 |
|
555 | |||
558 | assert_equal User.current, @copy.author |
|
556 | assert_equal User.current, @copy.author | |
559 | end |
|
557 | end | |
560 |
|
558 | |||
561 | should "keep journal notes" do |
|
559 | should "keep journal notes" do | |
562 | date = Date.today |
|
560 | date = Date.today | |
563 | notes = "Notes added when copying" |
|
561 | notes = "Notes added when copying" | |
@@ -572,7 +570,7 class IssueTest < ActiveSupport::TestCase | |||||
572 | end |
|
570 | end | |
573 | end |
|
571 | end | |
574 | end |
|
572 | end | |
575 |
|
573 | |||
576 | def test_recipients_should_not_include_users_that_cannot_view_the_issue |
|
574 | def test_recipients_should_not_include_users_that_cannot_view_the_issue | |
577 | issue = Issue.find(12) |
|
575 | issue = Issue.find(12) | |
578 | assert issue.recipients.include?(issue.author.mail) |
|
576 | assert issue.recipients.include?(issue.author.mail) | |
@@ -589,50 +587,50 class IssueTest < ActiveSupport::TestCase | |||||
589 | assert issue.watched_by?(user) |
|
587 | assert issue.watched_by?(user) | |
590 | assert !issue.watcher_recipients.include?(user.mail) |
|
588 | assert !issue.watcher_recipients.include?(user.mail) | |
591 | end |
|
589 | end | |
592 |
|
590 | |||
593 | def test_issue_destroy |
|
591 | def test_issue_destroy | |
594 | Issue.find(1).destroy |
|
592 | Issue.find(1).destroy | |
595 | assert_nil Issue.find_by_id(1) |
|
593 | assert_nil Issue.find_by_id(1) | |
596 | assert_nil TimeEntry.find_by_issue_id(1) |
|
594 | assert_nil TimeEntry.find_by_issue_id(1) | |
597 | end |
|
595 | end | |
598 |
|
596 | |||
599 | def test_blocked |
|
597 | def test_blocked | |
600 | blocked_issue = Issue.find(9) |
|
598 | blocked_issue = Issue.find(9) | |
601 | blocking_issue = Issue.find(10) |
|
599 | blocking_issue = Issue.find(10) | |
602 |
|
600 | |||
603 | assert blocked_issue.blocked? |
|
601 | assert blocked_issue.blocked? | |
604 | assert !blocking_issue.blocked? |
|
602 | assert !blocking_issue.blocked? | |
605 | end |
|
603 | end | |
606 |
|
604 | |||
607 | def test_blocked_issues_dont_allow_closed_statuses |
|
605 | def test_blocked_issues_dont_allow_closed_statuses | |
608 | blocked_issue = Issue.find(9) |
|
606 | blocked_issue = Issue.find(9) | |
609 |
|
607 | |||
610 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) |
|
608 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) | |
611 | assert !allowed_statuses.empty? |
|
609 | assert !allowed_statuses.empty? | |
612 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
610 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
613 | assert closed_statuses.empty? |
|
611 | assert closed_statuses.empty? | |
614 | end |
|
612 | end | |
615 |
|
613 | |||
616 | def test_unblocked_issues_allow_closed_statuses |
|
614 | def test_unblocked_issues_allow_closed_statuses | |
617 | blocking_issue = Issue.find(10) |
|
615 | blocking_issue = Issue.find(10) | |
618 |
|
616 | |||
619 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) |
|
617 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) | |
620 | assert !allowed_statuses.empty? |
|
618 | assert !allowed_statuses.empty? | |
621 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
619 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
622 | assert !closed_statuses.empty? |
|
620 | assert !closed_statuses.empty? | |
623 | end |
|
621 | end | |
624 |
|
622 | |||
625 | def test_rescheduling_an_issue_should_reschedule_following_issue |
|
623 | def test_rescheduling_an_issue_should_reschedule_following_issue | |
626 | 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) |
|
624 | 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) | |
627 | 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) |
|
625 | 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) | |
628 | IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) |
|
626 | IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) | |
629 | assert_equal issue1.due_date + 1, issue2.reload.start_date |
|
627 | assert_equal issue1.due_date + 1, issue2.reload.start_date | |
630 |
|
628 | |||
631 | issue1.due_date = Date.today + 5 |
|
629 | issue1.due_date = Date.today + 5 | |
632 | issue1.save! |
|
630 | issue1.save! | |
633 | assert_equal issue1.due_date + 1, issue2.reload.start_date |
|
631 | assert_equal issue1.due_date + 1, issue2.reload.start_date | |
634 | end |
|
632 | end | |
635 |
|
633 | |||
636 | def test_overdue |
|
634 | def test_overdue | |
637 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? |
|
635 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? | |
638 | assert !Issue.new(:due_date => Date.today).overdue? |
|
636 | assert !Issue.new(:due_date => Date.today).overdue? | |
@@ -679,13 +677,13 class IssueTest < ActiveSupport::TestCase | |||||
679 | should "not show the issue author twice" do |
|
677 | should "not show the issue author twice" do | |
680 | assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) |
|
678 | assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) | |
681 | assert_equal 2, assignable_user_ids.length |
|
679 | assert_equal 2, assignable_user_ids.length | |
682 |
|
680 | |||
683 | assignable_user_ids.each do |user_id| |
|
681 | assignable_user_ids.each do |user_id| | |
684 | assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, "User #{user_id} appears more or less than once" |
|
682 | assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, "User #{user_id} appears more or less than once" | |
685 | end |
|
683 | end | |
686 | end |
|
684 | end | |
687 | end |
|
685 | end | |
688 |
|
686 | |||
689 | def test_create_should_send_email_notification |
|
687 | def test_create_should_send_email_notification | |
690 | ActionMailer::Base.deliveries.clear |
|
688 | ActionMailer::Base.deliveries.clear | |
691 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30') |
|
689 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30') | |
@@ -698,13 +696,13 class IssueTest < ActiveSupport::TestCase | |||||
698 | ActionMailer::Base.deliveries.clear |
|
696 | ActionMailer::Base.deliveries.clear | |
699 | issue = Issue.find(1) |
|
697 | issue = Issue.find(1) | |
700 | stale = Issue.find(1) |
|
698 | stale = Issue.find(1) | |
701 |
|
699 | |||
702 | issue.init_journal(User.find(1)) |
|
700 | issue.init_journal(User.find(1)) | |
703 | issue.subject = 'Subjet update' |
|
701 | issue.subject = 'Subjet update' | |
704 | assert issue.save |
|
702 | assert issue.save | |
705 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
703 | assert_equal 1, ActionMailer::Base.deliveries.size | |
706 | ActionMailer::Base.deliveries.clear |
|
704 | ActionMailer::Base.deliveries.clear | |
707 |
|
705 | |||
708 | stale.init_journal(User.find(1)) |
|
706 | stale.init_journal(User.find(1)) | |
709 | stale.subject = 'Another subjet update' |
|
707 | stale.subject = 'Another subjet update' | |
710 | assert_raise ActiveRecord::StaleObjectError do |
|
708 | assert_raise ActiveRecord::StaleObjectError do | |
@@ -712,14 +710,14 class IssueTest < ActiveSupport::TestCase | |||||
712 | end |
|
710 | end | |
713 | assert ActionMailer::Base.deliveries.empty? |
|
711 | assert ActionMailer::Base.deliveries.empty? | |
714 | end |
|
712 | end | |
715 |
|
713 | |||
716 | def test_journalized_description |
|
714 | def test_journalized_description | |
717 | IssueCustomField.delete_all |
|
715 | IssueCustomField.delete_all | |
718 |
|
716 | |||
719 | i = Issue.first |
|
717 | i = Issue.first | |
720 | old_description = i.description |
|
718 | old_description = i.description | |
721 | new_description = "This is the new description" |
|
719 | new_description = "This is the new description" | |
722 |
|
720 | |||
723 | i.init_journal(User.find(2)) |
|
721 | i.init_journal(User.find(2)) | |
724 | i.description = new_description |
|
722 | i.description = new_description | |
725 | assert_difference 'Journal.count', 1 do |
|
723 | assert_difference 'Journal.count', 1 do | |
@@ -727,7 +725,7 class IssueTest < ActiveSupport::TestCase | |||||
727 | i.save! |
|
725 | i.save! | |
728 | end |
|
726 | end | |
729 | end |
|
727 | end | |
730 |
|
728 | |||
731 | detail = JournalDetail.first(:order => 'id DESC') |
|
729 | detail = JournalDetail.first(:order => 'id DESC') | |
732 | assert_equal i, detail.journal.journalized |
|
730 | assert_equal i, detail.journal.journalized | |
733 | assert_equal 'attr', detail.property |
|
731 | assert_equal 'attr', detail.property | |
@@ -735,7 +733,7 class IssueTest < ActiveSupport::TestCase | |||||
735 | assert_equal old_description, detail.old_value |
|
733 | assert_equal old_description, detail.old_value | |
736 | assert_equal new_description, detail.value |
|
734 | assert_equal new_description, detail.value | |
737 | end |
|
735 | end | |
738 |
|
736 | |||
739 | def test_saving_twice_should_not_duplicate_journal_details |
|
737 | def test_saving_twice_should_not_duplicate_journal_details | |
740 | i = Issue.find(:first) |
|
738 | i = Issue.find(:first) | |
741 | i.init_journal(User.find(2), 'Some notes') |
|
739 | i.init_journal(User.find(2), 'Some notes') | |
@@ -765,7 +763,7 class IssueTest < ActiveSupport::TestCase | |||||
765 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
763 | assert IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_PRECEDES) | |
766 | assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
764 | assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) | |
767 | assert IssueRelation.create!(:issue_from => Issue.find(3), :issue_to => Issue.find(8), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
765 | assert IssueRelation.create!(:issue_from => Issue.find(3), :issue_to => Issue.find(8), :relation_type => IssueRelation::TYPE_PRECEDES) | |
768 |
|
766 | |||
769 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
767 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
770 | end |
|
768 | end | |
771 |
|
769 | |||
@@ -775,7 +773,7 class IssueTest < ActiveSupport::TestCase | |||||
775 | assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) |
|
773 | assert IssueRelation.create!(:issue_from => Issue.find(2), :issue_to => Issue.find(3), :relation_type => IssueRelation::TYPE_PRECEDES) | |
776 | # Validation skipping |
|
774 | # Validation skipping | |
777 | assert IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES).save(false) |
|
775 | assert IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_PRECEDES).save(false) | |
778 |
|
776 | |||
779 | assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
777 | assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
780 | end |
|
778 | end | |
781 |
|
779 | |||
@@ -787,10 +785,10 class IssueTest < ActiveSupport::TestCase | |||||
787 | # Validation skipping |
|
785 | # Validation skipping | |
788 | assert IssueRelation.new(:issue_from => Issue.find(8), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_RELATES).save(false) |
|
786 | assert IssueRelation.new(:issue_from => Issue.find(8), :issue_to => Issue.find(2), :relation_type => IssueRelation::TYPE_RELATES).save(false) | |
789 | assert IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_RELATES).save(false) |
|
787 | assert IssueRelation.new(:issue_from => Issue.find(3), :issue_to => Issue.find(1), :relation_type => IssueRelation::TYPE_RELATES).save(false) | |
790 |
|
788 | |||
791 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
789 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
792 | end |
|
790 | end | |
793 |
|
791 | |||
794 | context "#done_ratio" do |
|
792 | context "#done_ratio" do | |
795 | setup do |
|
793 | setup do | |
796 | @issue = Issue.find(1) |
|
794 | @issue = Issue.find(1) | |
@@ -800,12 +798,12 class IssueTest < ActiveSupport::TestCase | |||||
800 | @issue_status2 = IssueStatus.find(2) |
|
798 | @issue_status2 = IssueStatus.find(2) | |
801 | @issue_status2.update_attribute(:default_done_ratio, 0) |
|
799 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
802 | end |
|
800 | end | |
803 |
|
801 | |||
804 | context "with Setting.issue_done_ratio using the issue_field" do |
|
802 | context "with Setting.issue_done_ratio using the issue_field" do | |
805 | setup do |
|
803 | setup do | |
806 | Setting.issue_done_ratio = 'issue_field' |
|
804 | Setting.issue_done_ratio = 'issue_field' | |
807 | end |
|
805 | end | |
808 |
|
806 | |||
809 | should "read the issue's field" do |
|
807 | should "read the issue's field" do | |
810 | assert_equal 0, @issue.done_ratio |
|
808 | assert_equal 0, @issue.done_ratio | |
811 | assert_equal 30, @issue2.done_ratio |
|
809 | assert_equal 30, @issue2.done_ratio | |
@@ -816,7 +814,7 class IssueTest < ActiveSupport::TestCase | |||||
816 | setup do |
|
814 | setup do | |
817 | Setting.issue_done_ratio = 'issue_status' |
|
815 | Setting.issue_done_ratio = 'issue_status' | |
818 | end |
|
816 | end | |
819 |
|
817 | |||
820 | should "read the Issue Status's default done ratio" do |
|
818 | should "read the Issue Status's default done ratio" do | |
821 | assert_equal 50, @issue.done_ratio |
|
819 | assert_equal 50, @issue.done_ratio | |
822 | assert_equal 0, @issue2.done_ratio |
|
820 | assert_equal 0, @issue2.done_ratio | |
@@ -833,12 +831,12 class IssueTest < ActiveSupport::TestCase | |||||
833 | @issue_status2 = IssueStatus.find(2) |
|
831 | @issue_status2 = IssueStatus.find(2) | |
834 | @issue_status2.update_attribute(:default_done_ratio, 0) |
|
832 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
835 | end |
|
833 | end | |
836 |
|
834 | |||
837 | context "with Setting.issue_done_ratio using the issue_field" do |
|
835 | context "with Setting.issue_done_ratio using the issue_field" do | |
838 | setup do |
|
836 | setup do | |
839 | Setting.issue_done_ratio = 'issue_field' |
|
837 | Setting.issue_done_ratio = 'issue_field' | |
840 | end |
|
838 | end | |
841 |
|
839 | |||
842 | should "not change the issue" do |
|
840 | should "not change the issue" do | |
843 | @issue.update_done_ratio_from_issue_status |
|
841 | @issue.update_done_ratio_from_issue_status | |
844 | @issue2.update_done_ratio_from_issue_status |
|
842 | @issue2.update_done_ratio_from_issue_status | |
@@ -852,7 +850,7 class IssueTest < ActiveSupport::TestCase | |||||
852 | setup do |
|
850 | setup do | |
853 | Setting.issue_done_ratio = 'issue_status' |
|
851 | Setting.issue_done_ratio = 'issue_status' | |
854 | end |
|
852 | end | |
855 |
|
853 | |||
856 | should "change the issue's done ratio" do |
|
854 | should "change the issue's done ratio" do | |
857 | @issue.update_done_ratio_from_issue_status |
|
855 | @issue.update_done_ratio_from_issue_status | |
858 | @issue2.update_done_ratio_from_issue_status |
|
856 | @issue2.update_done_ratio_from_issue_status | |
@@ -912,19 +910,18 class IssueTest < ActiveSupport::TestCase | |||||
912 | assert_equal 1, groups.size |
|
910 | assert_equal 1, groups.size | |
913 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
911 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
914 | end |
|
912 | end | |
915 |
|
913 | |||
916 |
|
||||
917 | context ".allowed_target_projects_on_move" do |
|
914 | context ".allowed_target_projects_on_move" do | |
918 | should "return all active projects for admin users" do |
|
915 | should "return all active projects for admin users" do | |
919 | User.current = User.find(1) |
|
916 | User.current = User.find(1) | |
920 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size |
|
917 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size | |
921 | end |
|
918 | end | |
922 |
|
919 | |||
923 | should "return allowed projects for non admin users" do |
|
920 | should "return allowed projects for non admin users" do | |
924 | User.current = User.find(2) |
|
921 | User.current = User.find(2) | |
925 | Role.non_member.remove_permission! :move_issues |
|
922 | Role.non_member.remove_permission! :move_issues | |
926 | assert_equal 3, Issue.allowed_target_projects_on_move.size |
|
923 | assert_equal 3, Issue.allowed_target_projects_on_move.size | |
927 |
|
924 | |||
928 | Role.non_member.add_permission! :move_issues |
|
925 | Role.non_member.add_permission! :move_issues | |
929 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size |
|
926 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size | |
930 | end |
|
927 | end | |
@@ -938,7 +935,7 class IssueTest < ActiveSupport::TestCase | |||||
938 |
|
935 | |||
939 | def test_on_active_projects_scope |
|
936 | def test_on_active_projects_scope | |
940 | assert Project.find(2).archive |
|
937 | assert Project.find(2).archive | |
941 |
|
938 | |||
942 | before = Issue.on_active_project.length |
|
939 | before = Issue.on_active_project.length | |
943 | # test inclusion to results |
|
940 | # test inclusion to results | |
944 | issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first) |
|
941 | issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first) | |
@@ -957,7 +954,7 class IssueTest < ActiveSupport::TestCase | |||||
957 | @assignee = User.generate_with_protected! |
|
954 | @assignee = User.generate_with_protected! | |
958 | @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) |
|
955 | @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) | |
959 | end |
|
956 | end | |
960 |
|
957 | |||
961 | should "include project recipients" do |
|
958 | should "include project recipients" do | |
962 | assert @project.recipients.present? |
|
959 | assert @project.recipients.present? | |
963 | @project.recipients.each do |project_recipient| |
|
960 | @project.recipients.each do |project_recipient| | |
@@ -969,7 +966,7 class IssueTest < ActiveSupport::TestCase | |||||
969 | assert @issue.author, "No author set for Issue" |
|
966 | assert @issue.author, "No author set for Issue" | |
970 | assert @issue.recipients.include?(@issue.author.mail) |
|
967 | assert @issue.recipients.include?(@issue.author.mail) | |
971 | end |
|
968 | end | |
972 |
|
969 | |||
973 | should "include the assigned to user if the assigned to user is active" do |
|
970 | should "include the assigned to user if the assigned to user is active" do | |
974 | assert @issue.assigned_to, "No assigned_to set for Issue" |
|
971 | assert @issue.assigned_to, "No assigned_to set for Issue" | |
975 | assert @issue.recipients.include?(@issue.assigned_to.mail) |
|
972 | assert @issue.recipients.include?(@issue.assigned_to.mail) |
General Comments 0
You need to be logged in to leave comments.
Login now