##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r13126:c0f082ad0252
parent child
Show More
@@ -227,7 +227,7 class Changeset < ActiveRecord::Base
227 227 # the issue may have been updated by the closure of another one (eg. duplicate)
228 228 issue.reload
229 229 # don't change the status is the issue is closed
230 return if issue.status && issue.status.is_closed?
230 return if issue.closed?
231 231
232 232 journal = issue.init_journal(user || User.anonymous,
233 233 ll(Setting.default_language,
@@ -588,7 +588,7 class Issue < ActiveRecord::Base
588 588 if fixed_version
589 589 if !assignable_versions.include?(fixed_version)
590 590 errors.add :fixed_version_id, :inclusion
591 elsif reopened? && fixed_version.closed?
591 elsif reopening? && fixed_version.closed?
592 592 errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version)
593 593 end
594 594 end
@@ -691,31 +691,33 class Issue < ActiveRecord::Base
691 691 status.present? && status.is_closed?
692 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 699 # Return true if the issue is being reopened
695 def reopened?
696 if !new_record? && status_id_changed?
697 status_was = IssueStatus.find_by_id(status_id_was)
698 status_new = IssueStatus.find_by_id(status_id)
699 if status_was && status_new && status_was.is_closed? && !status_new.is_closed?
700 return true
701 end
700 def reopening?
701 if new_record?
702 false
703 else
704 status_id_changed? && !closed? && was_closed?
702 705 end
703 false
704 706 end
707 alias :reopened? :reopening?
705 708
706 709 # Return true if the issue is being closed
707 710 def closing?
708 if !new_record? && status_id_changed?
709 if closed? && status_was && !status_was.is_closed?
710 return true
711 end
711 if new_record?
712 closed?
713 else
714 status_id_changed? && closed? && !was_closed?
712 715 end
713 false
714 716 end
715 717
716 718 # Returns true if the issue is overdue
717 719 def overdue?
718 !due_date.nil? && (due_date < Date.today) && !status.is_closed?
720 due_date.present? && (due_date < Date.today) && !closed?
719 721 end
720 722
721 723 # Is the amount of work done less than it should for the due date
@@ -1511,7 +1513,7 class Issue < ActiveRecord::Base
1511 1513 # The closed_on attribute stores the time of the last closing
1512 1514 # and is preserved when the issue is reopened.
1513 1515 def update_closed_on
1514 if closing? || (new_record? && closed?)
1516 if closing?
1515 1517 self.closed_on = updated_on
1516 1518 end
1517 1519 end
@@ -2398,6 +2398,13 class IssueTest < ActiveSupport::TestCase
2398 2398 assert_equal IssueStatus.find(1), issue.status_was
2399 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 2408 def test_status_was_should_be_reset_on_save
2402 2409 issue = Issue.find(1)
2403 2410 issue.status = IssueStatus.find(2)
@@ -2405,4 +2412,72 class IssueTest < ActiveSupport::TestCase
2405 2412 assert issue.save!
2406 2413 assert_equal IssueStatus.find(2), issue.status_was
2407 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 2483 end
@@ -212,7 +212,7 class RepositoryTest < ActiveSupport::TestCase
212 212
213 213 # make sure issue 1 is not already closed
214 214 fixed_issue = Issue.find(1)
215 assert !fixed_issue.status.is_closed?
215 assert !fixed_issue.closed?
216 216 old_status = fixed_issue.status
217 217
218 218 with_settings :notified_events => %w(issue_added issue_updated) do
@@ -222,7 +222,7 class RepositoryTest < ActiveSupport::TestCase
222 222
223 223 # fixed issues
224 224 fixed_issue.reload
225 assert fixed_issue.status.is_closed?
225 assert fixed_issue.closed?
226 226 assert_equal 90, fixed_issue.done_ratio
227 227 assert_equal [101], fixed_issue.changeset_ids
228 228
General Comments 0
You need to be logged in to leave comments. Login now