Adds Issue#status_was that returns the initial issue status.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11412 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
7a1af68178
commit
7b7427b46e
|
@ -155,6 +155,13 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_or_update
|
||||||
|
super
|
||||||
|
ensure
|
||||||
|
@status_was = nil
|
||||||
|
end
|
||||||
|
private :create_or_update
|
||||||
|
|
||||||
# AR#Persistence#destroy would raise and RecordNotFound exception
|
# AR#Persistence#destroy would raise and RecordNotFound exception
|
||||||
# if the issue was already deleted or updated (non matching lock_version).
|
# if the issue was already deleted or updated (non matching lock_version).
|
||||||
# This is a problem when bulk deleting issues or deleting a project
|
# This is a problem when bulk deleting issues or deleting a project
|
||||||
|
@ -637,6 +644,14 @@ class Issue < ActiveRecord::Base
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the initial status of the issue
|
||||||
|
# Returns nil for a new issue
|
||||||
|
def status_was
|
||||||
|
if status_id_was && status_id_was.to_i > 0
|
||||||
|
@status_was ||= IssueStatus.find_by_id(status_id_was)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return true if the issue is closed, otherwise false
|
# Return true if the issue is closed, otherwise false
|
||||||
def closed?
|
def closed?
|
||||||
self.status.is_closed?
|
self.status.is_closed?
|
||||||
|
@ -657,9 +672,7 @@ class Issue < ActiveRecord::Base
|
||||||
# Return true if the issue is being closed
|
# Return true if the issue is being closed
|
||||||
def closing?
|
def closing?
|
||||||
if !new_record? && status_id_changed?
|
if !new_record? && status_id_changed?
|
||||||
status_was = IssueStatus.find_by_id(status_id_was)
|
if status_was && status && !status_was.is_closed? && status.is_closed?
|
||||||
status_new = IssueStatus.find_by_id(status_id)
|
|
||||||
if status_was && status_new && !status_was.is_closed? && status_new.is_closed?
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1971,4 +1971,23 @@ class IssueTest < ActiveSupport::TestCase
|
||||||
assert !issue.closed?
|
assert !issue.closed?
|
||||||
assert_equal was_closed_on, issue.closed_on
|
assert_equal was_closed_on, issue.closed_on
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_status_was_should_return_nil_for_new_issue
|
||||||
|
issue = Issue.new
|
||||||
|
assert_nil issue.status_was
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_status_was_should_return_status_before_change
|
||||||
|
issue = Issue.find(1)
|
||||||
|
issue.status = IssueStatus.find(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_equal IssueStatus.find(1), issue.status_was
|
||||||
|
assert issue.save!
|
||||||
|
assert_equal IssueStatus.find(2), issue.status_was
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue