Deprecated Issue#move_to_project.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8539 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
065376c160
commit
1653735758
@ -241,7 +241,7 @@ class IssuesController < ApplicationController
|
|||||||
@issues.each do |issue|
|
@issues.each do |issue|
|
||||||
issue.reload
|
issue.reload
|
||||||
if @copy
|
if @copy
|
||||||
issue = Issue.new.copy_from(issue)
|
issue = issue.copy
|
||||||
end
|
end
|
||||||
journal = issue.init_journal(User.current, params[:notes])
|
journal = issue.init_journal(User.current, params[:notes])
|
||||||
issue.safe_attributes = attributes
|
issue.safe_attributes = attributes
|
||||||
|
@ -136,11 +136,20 @@ class Issue < ActiveRecord::Base
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns an unsaved copy of the issue
|
||||||
|
def copy(attributes=nil)
|
||||||
|
copy = self.class.new.copy_from(self)
|
||||||
|
copy.attributes = attributes if attributes
|
||||||
|
copy
|
||||||
|
end
|
||||||
|
|
||||||
# Moves/copies an issue to a new project and tracker
|
# Moves/copies an issue to a new project and tracker
|
||||||
# Returns the moved/copied issue on success, false on failure
|
# Returns the moved/copied issue on success, false on failure
|
||||||
def move_to_project(new_project, new_tracker=nil, options={})
|
def move_to_project(new_project, new_tracker=nil, options={})
|
||||||
|
ActiveSupport::Deprecation.warn "Issue#move_to_project is deprecated, use #project= instead."
|
||||||
|
|
||||||
if options[:copy]
|
if options[:copy]
|
||||||
issue = self.class.new.copy_from(self)
|
issue = self.copy
|
||||||
else
|
else
|
||||||
issue = self
|
issue = self
|
||||||
end
|
end
|
||||||
|
@ -139,7 +139,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
|
|||||||
child = create_issue!(:parent_issue_id => parent1.id)
|
child = create_issue!(:parent_issue_id => parent1.id)
|
||||||
grandchild = create_issue!(:parent_issue_id => child.id)
|
grandchild = create_issue!(:parent_issue_id => child.id)
|
||||||
|
|
||||||
assert child.reload.move_to_project(Project.find(2))
|
child.reload
|
||||||
|
child.project = Project.find(2)
|
||||||
|
assert child.save
|
||||||
child.reload
|
child.reload
|
||||||
grandchild.reload
|
grandchild.reload
|
||||||
parent1.reload
|
parent1.reload
|
||||||
@ -159,7 +161,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
|
|||||||
assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
|
assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
|
||||||
|
|
||||||
# child can not be moved to Project 2 because its child is on a disabled tracker
|
# child can not be moved to Project 2 because its child is on a disabled tracker
|
||||||
assert_equal false, Issue.find(child.id).move_to_project(Project.find(2))
|
child = Issue.find(child.id)
|
||||||
|
child.project = Project.find(2)
|
||||||
|
assert !child.save
|
||||||
child.reload
|
child.reload
|
||||||
grandchild.reload
|
grandchild.reload
|
||||||
parent1.reload
|
parent1.reload
|
||||||
|
@ -522,7 +522,8 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
def test_move_to_another_project_with_same_category
|
def test_move_to_another_project_with_same_category
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
assert issue.move_to_project(Project.find(2))
|
issue.project = Project.find(2)
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 2, issue.project_id
|
assert_equal 2, issue.project_id
|
||||||
# Category changes
|
# Category changes
|
||||||
@ -533,7 +534,8 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
def test_move_to_another_project_without_same_category
|
def test_move_to_another_project_without_same_category
|
||||||
issue = Issue.find(2)
|
issue = Issue.find(2)
|
||||||
assert issue.move_to_project(Project.find(2))
|
issue.project = Project.find(2)
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 2, issue.project_id
|
assert_equal 2, issue.project_id
|
||||||
# Category cleared
|
# Category cleared
|
||||||
@ -543,7 +545,8 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
def test_move_to_another_project_should_clear_fixed_version_when_not_shared
|
def test_move_to_another_project_should_clear_fixed_version_when_not_shared
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
issue.update_attribute(:fixed_version_id, 1)
|
issue.update_attribute(:fixed_version_id, 1)
|
||||||
assert issue.move_to_project(Project.find(2))
|
issue.project = Project.find(2)
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 2, issue.project_id
|
assert_equal 2, issue.project_id
|
||||||
# Cleared fixed_version
|
# Cleared fixed_version
|
||||||
@ -553,7 +556,8 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project
|
def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
issue.update_attribute(:fixed_version_id, 4)
|
issue.update_attribute(:fixed_version_id, 4)
|
||||||
assert issue.move_to_project(Project.find(5))
|
issue.project = Project.find(5)
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 5, issue.project_id
|
assert_equal 5, issue.project_id
|
||||||
# Keep fixed_version
|
# Keep fixed_version
|
||||||
@ -563,7 +567,8 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project
|
def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
issue.update_attribute(:fixed_version_id, 1)
|
issue.update_attribute(:fixed_version_id, 1)
|
||||||
assert issue.move_to_project(Project.find(5))
|
issue.project = Project.find(5)
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 5, issue.project_id
|
assert_equal 5, issue.project_id
|
||||||
# Cleared fixed_version
|
# Cleared fixed_version
|
||||||
@ -573,7 +578,8 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide
|
def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
issue.update_attribute(:fixed_version_id, 7)
|
issue.update_attribute(:fixed_version_id, 7)
|
||||||
assert issue.move_to_project(Project.find(2))
|
issue.project = Project.find(2)
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 2, issue.project_id
|
assert_equal 2, issue.project_id
|
||||||
# Keep fixed_version
|
# Keep fixed_version
|
||||||
@ -585,16 +591,18 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
target = Project.find(2)
|
target = Project.find(2)
|
||||||
target.tracker_ids = [3]
|
target.tracker_ids = [3]
|
||||||
target.save
|
target.save
|
||||||
assert_equal false, issue.move_to_project(target)
|
issue.project = target
|
||||||
|
assert issue.save
|
||||||
issue.reload
|
issue.reload
|
||||||
assert_equal 1, issue.project_id
|
assert_equal 2, issue.project_id
|
||||||
|
assert_equal 3, issue.tracker_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_copy_to_the_same_project
|
def test_copy_to_the_same_project
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
copy = nil
|
copy = issue.copy
|
||||||
assert_difference 'Issue.count' do
|
assert_difference 'Issue.count' do
|
||||||
copy = issue.move_to_project(issue.project, nil, :copy => true)
|
copy.save!
|
||||||
end
|
end
|
||||||
assert_kind_of Issue, copy
|
assert_kind_of Issue, copy
|
||||||
assert_equal issue.project, copy.project
|
assert_equal issue.project, copy.project
|
||||||
@ -603,9 +611,9 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
def test_copy_to_another_project_and_tracker
|
def test_copy_to_another_project_and_tracker
|
||||||
issue = Issue.find(1)
|
issue = Issue.find(1)
|
||||||
copy = nil
|
copy = issue.copy(:project_id => 3, :tracker_id => 2)
|
||||||
assert_difference 'Issue.count' do
|
assert_difference 'Issue.count' do
|
||||||
copy = issue.move_to_project(Project.find(3), Tracker.find(2), :copy => true)
|
copy.save!
|
||||||
end
|
end
|
||||||
copy.reload
|
copy.reload
|
||||||
assert_kind_of Issue, copy
|
assert_kind_of Issue, copy
|
||||||
@ -615,66 +623,64 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
assert_nil copy.custom_value_for(2)
|
assert_nil copy.custom_value_for(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#move_to_project" do
|
context "#copy" do
|
||||||
context "as a copy" do
|
setup do
|
||||||
setup do
|
@issue = Issue.find(1)
|
||||||
@issue = Issue.find(1)
|
end
|
||||||
@copy = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
should "not create a journal" do
|
should "not create a journal" do
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
|
||||||
assert_equal 0, @copy.reload.journals.size
|
copy.save!
|
||||||
end
|
assert_equal 0, copy.reload.journals.size
|
||||||
|
end
|
||||||
|
|
||||||
should "allow assigned_to changes" do
|
should "allow assigned_to changes" do
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
|
||||||
assert_equal 3, @copy.assigned_to_id
|
assert_equal 3, copy.assigned_to_id
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow status changes" do
|
should "allow status changes" do
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}})
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :status_id => 2)
|
||||||
assert_equal 2, @copy.status_id
|
assert_equal 2, copy.status_id
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow start date changes" do
|
should "allow start date changes" do
|
||||||
date = Date.today
|
date = Date.today
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}})
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date)
|
||||||
assert_equal date, @copy.start_date
|
assert_equal date, copy.start_date
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow due date changes" do
|
should "allow due date changes" do
|
||||||
date = Date.today
|
date = Date.today
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}})
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :due_date => date)
|
||||||
|
assert_equal date, copy.due_date
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal date, @copy.due_date
|
should "set current user as author" do
|
||||||
end
|
User.current = User.find(9)
|
||||||
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2)
|
||||||
|
assert_equal User.current, copy.author
|
||||||
|
end
|
||||||
|
|
||||||
should "set current user as author" do
|
should "create a journal with notes" do
|
||||||
User.current = User.find(9)
|
date = Date.today
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {}})
|
notes = "Notes added when copying"
|
||||||
|
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date)
|
||||||
|
copy.init_journal(User.current, notes)
|
||||||
|
copy.save!
|
||||||
|
|
||||||
assert_equal User.current, @copy.author
|
assert_equal 1, copy.journals.size
|
||||||
end
|
journal = copy.journals.first
|
||||||
|
assert_equal 0, journal.details.size
|
||||||
should "create a journal with notes" do
|
assert_equal notes, journal.notes
|
||||||
date = Date.today
|
|
||||||
notes = "Notes added when copying"
|
|
||||||
@copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :notes => notes, :attributes => {:start_date => date}})
|
|
||||||
|
|
||||||
assert_equal 1, @copy.journals.size
|
|
||||||
journal = @copy.journals.first
|
|
||||||
assert_equal 0, journal.details.size
|
|
||||||
assert_equal notes, journal.notes
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_recipients_should_not_include_users_that_cannot_view_the_issue
|
def test_recipients_should_not_include_users_that_cannot_view_the_issue
|
||||||
issue = Issue.find(12)
|
issue = Issue.find(12)
|
||||||
assert issue.recipients.include?(issue.author.mail)
|
assert issue.recipients.include?(issue.author.mail)
|
||||||
# move the issue to a private project
|
# copy the issue to a private project
|
||||||
copy = issue.move_to_project(Project.find(5), Tracker.find(2), :copy => true)
|
copy = issue.copy(:project_id => 5, :tracker_id => 2)
|
||||||
# author is not a member of project anymore
|
# author is not a member of project anymore
|
||||||
assert !copy.recipients.include?(copy.author.mail)
|
assert !copy.recipients.include?(copy.author.mail)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user