if fixed_version
if !assignable_versions.include?(fixed_version)
errors.add :fixed_version_id, :inclusion
- elsif reopened? && fixed_version.closed?
+ elsif reopening? && fixed_version.closed?
errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version)
end
end
status.present? && status.is_closed?
end
+ # Returns true if the issue was closed when loaded
+ def was_closed?
+ status_was.present? && status_was.is_closed?
+ end
+
# Return true if the issue is being reopened
- def reopened?
- if !new_record? && status_id_changed?
- status_was = IssueStatus.find_by_id(status_id_was)
- status_new = IssueStatus.find_by_id(status_id)
- if status_was && status_new && status_was.is_closed? && !status_new.is_closed?
- return true
- end
+ def reopening?
+ if new_record?
+ false
+ else
+ status_id_changed? && !closed? && was_closed?
end
- false
end
+ alias :reopened? :reopening?
# Return true if the issue is being closed
def closing?
- if !new_record? && status_id_changed?
- if closed? && status_was && !status_was.is_closed?
- return true
- end
+ if new_record?
+ closed?
+ else
+ status_id_changed? && closed? && !was_closed?
end
- false
end
# Returns true if the issue is overdue
def overdue?
- !due_date.nil? && (due_date < Date.today) && !status.is_closed?
+ due_date.present? && (due_date < Date.today) && !closed?
end
# Is the amount of work done less than it should for the due date
# The closed_on attribute stores the time of the last closing
# and is preserved when the issue is reopened.
def update_closed_on
- if closing? || (new_record? && closed?)
+ if closing?
self.closed_on = updated_on
end
end
assert_equal IssueStatus.find(1), issue.status_was
end
+ def test_status_was_should_return_status_before_change_with_status_id
+ issue = Issue.find(1)
+ assert_equal IssueStatus.find(1), issue.status
+ issue.status_id = 2
+ assert_equal IssueStatus.find(1), issue.status_was
+ end
+
def test_status_was_should_be_reset_on_save
issue = Issue.find(1)
issue.status = IssueStatus.find(2)
assert issue.save!
assert_equal IssueStatus.find(2), issue.status_was
end
+
+ def test_closing_should_return_true_when_closing_an_issue
+ issue = Issue.find(1)
+ issue.status = IssueStatus.find(2)
+ assert_equal false, issue.closing?
+ issue.status = IssueStatus.find(5)
+ assert_equal true, issue.closing?
+ end
+
+ def test_closing_should_return_true_when_closing_an_issue_with_status_id
+ issue = Issue.find(1)
+ issue.status_id = 2
+ assert_equal false, issue.closing?
+ issue.status_id = 5
+ assert_equal true, issue.closing?
+ end
+
+ def test_closing_should_return_true_for_new_closed_issue
+ issue = Issue.new
+ assert_equal false, issue.closing?
+ issue.status = IssueStatus.find(5)
+ assert_equal true, issue.closing?
+ end
+
+ def test_closing_should_return_true_for_new_closed_issue_with_status_id
+ issue = Issue.new
+ assert_equal false, issue.closing?
+ issue.status_id = 5
+ assert_equal true, issue.closing?
+ end
+
+ def test_closing_should_be_reset_after_save
+ issue = Issue.find(1)
+ issue.status_id = 5
+ assert_equal true, issue.closing?
+ issue.save!
+ assert_equal false, issue.closing?
+ end
+
+ def test_reopening_should_return_true_when_reopening_an_issue
+ issue = Issue.find(8)
+ issue.status = IssueStatus.find(6)
+ assert_equal false, issue.reopening?
+ issue.status = IssueStatus.find(2)
+ assert_equal true, issue.reopening?
+ end
+
+ def test_reopening_should_return_true_when_reopening_an_issue_with_status_id
+ issue = Issue.find(8)
+ issue.status_id = 6
+ assert_equal false, issue.reopening?
+ issue.status_id = 2
+ assert_equal true, issue.reopening?
+ end
+
+ def test_reopening_should_return_false_for_new_open_issue
+ issue = Issue.new
+ issue.status = IssueStatus.find(1)
+ assert_equal false, issue.reopening?
+ end
+
+ def test_reopening_should_be_reset_after_save
+ issue = Issue.find(8)
+ issue.status_id = 2
+ assert_equal true, issue.reopening?
+ issue.save!
+ assert_equal false, issue.reopening?
+ end
end
# make sure issue 1 is not already closed
fixed_issue = Issue.find(1)
- assert !fixed_issue.status.is_closed?
+ assert !fixed_issue.closed?
old_status = fixed_issue.status
with_settings :notified_events => %w(issue_added issue_updated) do
# fixed issues
fixed_issue.reload
- assert fixed_issue.status.is_closed?
+ assert fixed_issue.closed?
assert_equal 90, fixed_issue.done_ratio
assert_equal [101], fixed_issue.changeset_ids