@@ -227,7 +227,7 class Changeset < ActiveRecord::Base | |||||
227 | # the issue may have been updated by the closure of another one (eg. duplicate) |
|
227 | # the issue may have been updated by the closure of another one (eg. duplicate) | |
228 | issue.reload |
|
228 | issue.reload | |
229 | # don't change the status is the issue is closed |
|
229 | # don't change the status is the issue is closed | |
230 |
return if issue. |
|
230 | return if issue.closed? | |
231 |
|
231 | |||
232 | journal = issue.init_journal(user || User.anonymous, |
|
232 | journal = issue.init_journal(user || User.anonymous, | |
233 | ll(Setting.default_language, |
|
233 | ll(Setting.default_language, |
@@ -588,7 +588,7 class Issue < ActiveRecord::Base | |||||
588 | if fixed_version |
|
588 | if fixed_version | |
589 | if !assignable_versions.include?(fixed_version) |
|
589 | if !assignable_versions.include?(fixed_version) | |
590 | errors.add :fixed_version_id, :inclusion |
|
590 | errors.add :fixed_version_id, :inclusion | |
591 |
elsif reopen |
|
591 | elsif reopening? && fixed_version.closed? | |
592 | errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version) |
|
592 | errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version) | |
593 | end |
|
593 | end | |
594 | end |
|
594 | end | |
@@ -691,31 +691,33 class Issue < ActiveRecord::Base | |||||
691 | status.present? && status.is_closed? |
|
691 | status.present? && status.is_closed? | |
692 | end |
|
692 | end | |
693 |
|
693 | |||
|
694 | # Returns true if the issue was closed when loaded | |||
|
695 | def was_closed? | |||
|
696 | status_was.present? && status_was.is_closed? | |||
|
697 | end | |||
|
698 | ||||
694 | # Return true if the issue is being reopened |
|
699 | # Return true if the issue is being reopened | |
695 |
def reopen |
|
700 | def reopening? | |
696 |
if |
|
701 | if new_record? | |
697 | status_was = IssueStatus.find_by_id(status_id_was) |
|
702 | false | |
698 | status_new = IssueStatus.find_by_id(status_id) |
|
703 | else | |
699 | if status_was && status_new && status_was.is_closed? && !status_new.is_closed? |
|
704 | status_id_changed? && !closed? && was_closed? | |
700 | return true |
|
|||
701 | end |
|
|||
702 | end |
|
705 | end | |
703 | false |
|
|||
704 | end |
|
706 | end | |
|
707 | alias :reopened? :reopening? | |||
705 |
|
708 | |||
706 | # Return true if the issue is being closed |
|
709 | # Return true if the issue is being closed | |
707 | def closing? |
|
710 | def closing? | |
708 |
if |
|
711 | if new_record? | |
709 | if closed? && status_was && !status_was.is_closed? |
|
712 | closed? | |
710 | return true |
|
713 | else | |
711 | end |
|
714 | status_id_changed? && closed? && !was_closed? | |
712 | end |
|
715 | end | |
713 | false |
|
|||
714 | end |
|
716 | end | |
715 |
|
717 | |||
716 | # Returns true if the issue is overdue |
|
718 | # Returns true if the issue is overdue | |
717 | def overdue? |
|
719 | def overdue? | |
718 |
|
|
720 | due_date.present? && (due_date < Date.today) && !closed? | |
719 | end |
|
721 | end | |
720 |
|
722 | |||
721 | # Is the amount of work done less than it should for the due date |
|
723 | # Is the amount of work done less than it should for the due date | |
@@ -1511,7 +1513,7 class Issue < ActiveRecord::Base | |||||
1511 | # The closed_on attribute stores the time of the last closing |
|
1513 | # The closed_on attribute stores the time of the last closing | |
1512 | # and is preserved when the issue is reopened. |
|
1514 | # and is preserved when the issue is reopened. | |
1513 | def update_closed_on |
|
1515 | def update_closed_on | |
1514 | if closing? || (new_record? && closed?) |
|
1516 | if closing? | |
1515 | self.closed_on = updated_on |
|
1517 | self.closed_on = updated_on | |
1516 | end |
|
1518 | end | |
1517 | end |
|
1519 | end |
@@ -2398,6 +2398,13 class IssueTest < ActiveSupport::TestCase | |||||
2398 | assert_equal IssueStatus.find(1), issue.status_was |
|
2398 | assert_equal IssueStatus.find(1), issue.status_was | |
2399 | end |
|
2399 | end | |
2400 |
|
2400 | |||
|
2401 | def test_status_was_should_return_status_before_change_with_status_id | |||
|
2402 | issue = Issue.find(1) | |||
|
2403 | assert_equal IssueStatus.find(1), issue.status | |||
|
2404 | issue.status_id = 2 | |||
|
2405 | assert_equal IssueStatus.find(1), issue.status_was | |||
|
2406 | end | |||
|
2407 | ||||
2401 | def test_status_was_should_be_reset_on_save |
|
2408 | def test_status_was_should_be_reset_on_save | |
2402 | issue = Issue.find(1) |
|
2409 | issue = Issue.find(1) | |
2403 | issue.status = IssueStatus.find(2) |
|
2410 | issue.status = IssueStatus.find(2) | |
@@ -2405,4 +2412,72 class IssueTest < ActiveSupport::TestCase | |||||
2405 | assert issue.save! |
|
2412 | assert issue.save! | |
2406 | assert_equal IssueStatus.find(2), issue.status_was |
|
2413 | assert_equal IssueStatus.find(2), issue.status_was | |
2407 | end |
|
2414 | end | |
|
2415 | ||||
|
2416 | def test_closing_should_return_true_when_closing_an_issue | |||
|
2417 | issue = Issue.find(1) | |||
|
2418 | issue.status = IssueStatus.find(2) | |||
|
2419 | assert_equal false, issue.closing? | |||
|
2420 | issue.status = IssueStatus.find(5) | |||
|
2421 | assert_equal true, issue.closing? | |||
|
2422 | end | |||
|
2423 | ||||
|
2424 | def test_closing_should_return_true_when_closing_an_issue_with_status_id | |||
|
2425 | issue = Issue.find(1) | |||
|
2426 | issue.status_id = 2 | |||
|
2427 | assert_equal false, issue.closing? | |||
|
2428 | issue.status_id = 5 | |||
|
2429 | assert_equal true, issue.closing? | |||
|
2430 | end | |||
|
2431 | ||||
|
2432 | def test_closing_should_return_true_for_new_closed_issue | |||
|
2433 | issue = Issue.new | |||
|
2434 | assert_equal false, issue.closing? | |||
|
2435 | issue.status = IssueStatus.find(5) | |||
|
2436 | assert_equal true, issue.closing? | |||
|
2437 | end | |||
|
2438 | ||||
|
2439 | def test_closing_should_return_true_for_new_closed_issue_with_status_id | |||
|
2440 | issue = Issue.new | |||
|
2441 | assert_equal false, issue.closing? | |||
|
2442 | issue.status_id = 5 | |||
|
2443 | assert_equal true, issue.closing? | |||
|
2444 | end | |||
|
2445 | ||||
|
2446 | def test_closing_should_be_reset_after_save | |||
|
2447 | issue = Issue.find(1) | |||
|
2448 | issue.status_id = 5 | |||
|
2449 | assert_equal true, issue.closing? | |||
|
2450 | issue.save! | |||
|
2451 | assert_equal false, issue.closing? | |||
|
2452 | end | |||
|
2453 | ||||
|
2454 | def test_reopening_should_return_true_when_reopening_an_issue | |||
|
2455 | issue = Issue.find(8) | |||
|
2456 | issue.status = IssueStatus.find(6) | |||
|
2457 | assert_equal false, issue.reopening? | |||
|
2458 | issue.status = IssueStatus.find(2) | |||
|
2459 | assert_equal true, issue.reopening? | |||
|
2460 | end | |||
|
2461 | ||||
|
2462 | def test_reopening_should_return_true_when_reopening_an_issue_with_status_id | |||
|
2463 | issue = Issue.find(8) | |||
|
2464 | issue.status_id = 6 | |||
|
2465 | assert_equal false, issue.reopening? | |||
|
2466 | issue.status_id = 2 | |||
|
2467 | assert_equal true, issue.reopening? | |||
|
2468 | end | |||
|
2469 | ||||
|
2470 | def test_reopening_should_return_false_for_new_open_issue | |||
|
2471 | issue = Issue.new | |||
|
2472 | issue.status = IssueStatus.find(1) | |||
|
2473 | assert_equal false, issue.reopening? | |||
|
2474 | end | |||
|
2475 | ||||
|
2476 | def test_reopening_should_be_reset_after_save | |||
|
2477 | issue = Issue.find(8) | |||
|
2478 | issue.status_id = 2 | |||
|
2479 | assert_equal true, issue.reopening? | |||
|
2480 | issue.save! | |||
|
2481 | assert_equal false, issue.reopening? | |||
|
2482 | end | |||
2408 | end |
|
2483 | end |
@@ -212,7 +212,7 class RepositoryTest < ActiveSupport::TestCase | |||||
212 |
|
212 | |||
213 | # make sure issue 1 is not already closed |
|
213 | # make sure issue 1 is not already closed | |
214 | fixed_issue = Issue.find(1) |
|
214 | fixed_issue = Issue.find(1) | |
215 |
assert !fixed_issue. |
|
215 | assert !fixed_issue.closed? | |
216 | old_status = fixed_issue.status |
|
216 | old_status = fixed_issue.status | |
217 |
|
217 | |||
218 | with_settings :notified_events => %w(issue_added issue_updated) do |
|
218 | with_settings :notified_events => %w(issue_added issue_updated) do | |
@@ -222,7 +222,7 class RepositoryTest < ActiveSupport::TestCase | |||||
222 |
|
222 | |||
223 | # fixed issues |
|
223 | # fixed issues | |
224 | fixed_issue.reload |
|
224 | fixed_issue.reload | |
225 |
assert fixed_issue. |
|
225 | assert fixed_issue.closed? | |
226 | assert_equal 90, fixed_issue.done_ratio |
|
226 | assert_equal 90, fixed_issue.done_ratio | |
227 | assert_equal [101], fixed_issue.changeset_ids |
|
227 | assert_equal [101], fixed_issue.changeset_ids | |
228 |
|
228 |
General Comments 0
You need to be logged in to leave comments.
Login now