Patch #2132 ยป cant_close_blocked_issues.diff
| test/unit/issue_test.rb (working copy) | ||
|---|---|---|
| 20 | 20 |
class IssueTest < Test::Unit::TestCase |
| 21 | 21 |
fixtures :projects, :users, :members, |
| 22 | 22 |
:trackers, :projects_trackers, |
| 23 |
:issue_statuses, :issue_categories, |
|
| 23 |
:issue_statuses, :issue_categories, :issue_relations, :workflows,
|
|
| 24 | 24 |
:enumerations, |
| 25 | 25 |
:issues, |
| 26 | 26 |
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
| ... | ... | |
| 190 | 190 |
assert_nil Issue.find_by_id(1) |
| 191 | 191 |
assert_nil TimeEntry.find_by_issue_id(1) |
| 192 | 192 |
end |
| 193 |
|
|
| 194 |
def test_blocked |
|
| 195 |
blocked_issue = Issue.find(7) |
|
| 196 |
blocking_issue = Issue.find(8) |
|
| 197 |
|
|
| 198 |
assert blocked_issue.blocked? |
|
| 199 |
assert !blocking_issue.blocked? |
|
| 200 |
end |
|
| 201 |
|
|
| 202 |
def test_blocked_issues_dont_allow_closed_statuses |
|
| 203 |
blocked_issue = Issue.find(7) |
|
| 204 | ||
| 205 |
allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) |
|
| 206 |
assert !allowed_statuses.empty? |
|
| 207 | ||
| 208 |
allowed_statuses.each do |status| |
|
| 209 |
assert !status.is_closed? |
|
| 210 |
end |
|
| 211 | ||
| 212 |
closed_statuses = allowed_statuses.find_all {|st| st.is_closed?}
|
|
| 213 |
assert closed_statuses.empty? |
|
| 214 |
end |
|
| 215 | ||
| 216 |
def test_unblocked_issues_allow_closed_statuses |
|
| 217 |
blocking_issue = Issue.find(8) |
|
| 218 | ||
| 219 |
allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) |
|
| 220 |
assert !allowed_statuses.empty? |
|
| 221 | ||
| 222 |
closed_statuses = allowed_statuses.find_all {|st| st.is_closed?}
|
|
| 223 |
assert !closed_statuses.empty? |
|
| 224 |
end |
|
| 193 | 225 |
end |
| test/fixtures/issues.yml (working copy) | ||
|---|---|---|
| 91 | 91 |
status_id: 1 |
| 92 | 92 |
start_date: <%= Date.today.to_s(:db) %> |
| 93 | 93 |
due_date: <%= 1.days.from_now.to_date.to_s(:db) %> |
| 94 |
|
|
| 94 |
issues_007: |
|
| 95 |
created_on: <%= 1.minute.ago.to_date.to_s(:db) %> |
|
| 96 |
project_id: 5 |
|
| 97 |
updated_on: <%= 1.minute.ago.to_date.to_s(:db) %> |
|
| 98 |
priority_id: 3 |
|
| 99 |
subject: Blocked Issue |
|
| 100 |
id: 7 |
|
| 101 |
fixed_version_id: |
|
| 102 |
category_id: |
|
| 103 |
description: This is an issue that is blocked by another |
|
| 104 |
tracker_id: 1 |
|
| 105 |
assigned_to_id: |
|
| 106 |
author_id: 2 |
|
| 107 |
status_id: 1 |
|
| 108 |
start_date: <%= Date.today.to_s(:db) %> |
|
| 109 |
due_date: <%= 1.days.from_now.to_date.to_s(:db) %> |
|
| 110 |
issues_008: |
|
| 111 |
created_on: <%= 1.minute.ago.to_date.to_s(:db) %> |
|
| 112 |
project_id: 5 |
|
| 113 |
updated_on: <%= 1.minute.ago.to_date.to_s(:db) %> |
|
| 114 |
priority_id: 3 |
|
| 115 |
subject: Issue Doing the Blocking |
|
| 116 |
id: 8 |
|
| 117 |
fixed_version_id: |
|
| 118 |
category_id: |
|
| 119 |
description: This is an issue that blocks issue 7 |
|
| 120 |
tracker_id: 1 |
|
| 121 |
assigned_to_id: |
|
| 122 |
author_id: 2 |
|
| 123 |
status_id: 1 |
|
| 124 |
start_date: <%= Date.today.to_s(:db) %> |
|
| 125 |
due_date: <%= 1.days.from_now.to_date.to_s(:db) %> |
|
| test/fixtures/issue_relations.yml (revision 0) | ||
|---|---|---|
| 1 |
issue_relation_001: |
|
| 2 |
id: 1 |
|
| 3 |
issue_from_id: 8 |
|
| 4 |
issue_to_id: 7 |
|
| 5 |
relation_type: blocks |
|
| 6 |
delay: |
|
| 7 | ||
| 8 |
|
|
| app/models/issue.rb (working copy) | ||
|---|---|---|
| 199 | 199 |
project.assignable_users |
| 200 | 200 |
end |
| 201 | 201 |
|
| 202 |
# Returns true if this issue is blocked by another issue that is still open |
|
| 203 |
def blocked? |
|
| 204 |
!(relations_to.find_all {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.empty?)
|
|
| 205 |
end |
|
| 206 |
|
|
| 202 | 207 |
# Returns an array of status that user is able to apply |
| 203 | 208 |
def new_statuses_allowed_to(user) |
| 204 | 209 |
statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker) |
| 205 | 210 |
statuses << status unless statuses.empty? |
| 206 |
statuses.uniq.sort |
|
| 211 | ||
| 212 |
unified_list = statuses.uniq.sort |
|
| 213 |
|
|
| 214 |
blocked? ? unified_list.reject {|s| s.is_closed?} : unified_list
|
|
| 207 | 215 |
end |
| 208 | 216 |
|
| 209 | 217 |
# Returns the mail adresses of users that should be notified for the issue |