mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-23 20:11:45 +00:00
Code cleanup.
git-svn-id: http://svn.redmine.org/redmine/trunk@13508 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
caccb57b55
commit
c0f082ad02
@ -227,7 +227,7 @@ class Changeset < ActiveRecord::Base
|
||||
# the issue may have been updated by the closure of another one (eg. duplicate)
|
||||
issue.reload
|
||||
# don't change the status is the issue is closed
|
||||
return if issue.status && issue.status.is_closed?
|
||||
return if issue.closed?
|
||||
|
||||
journal = issue.init_journal(user || User.anonymous,
|
||||
ll(Setting.default_language,
|
||||
|
||||
@ -588,7 +588,7 @@ class Issue < ActiveRecord::Base
|
||||
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
|
||||
@ -691,31 +691,33 @@ class Issue < ActiveRecord::Base
|
||||
status.present? && status.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
|
||||
end
|
||||
false
|
||||
# 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 reopening?
|
||||
if new_record?
|
||||
false
|
||||
else
|
||||
status_id_changed? && !closed? && was_closed?
|
||||
end
|
||||
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
|
||||
@ -1511,7 +1513,7 @@ class Issue < ActiveRecord::Base
|
||||
# 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
|
||||
|
||||
@ -2398,6 +2398,13 @@ class IssueTest < ActiveSupport::TestCase
|
||||
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)
|
||||
@ -2405,4 +2412,72 @@ class IssueTest < ActiveSupport::TestCase
|
||||
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
|
||||
|
||||
@ -212,7 +212,7 @@ class RepositoryTest < ActiveSupport::TestCase
|
||||
|
||||
# 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
|
||||
@ -222,7 +222,7 @@ class RepositoryTest < ActiveSupport::TestCase
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user