]> source.dussan.org Git - redmine.git/commitdiff
Refactor: Extract a new IssueMovesController from IssuesController.
authorEric Davis <edavis@littlestreamsoftware.com>
Wed, 11 Aug 2010 14:42:10 +0000 (14:42 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Wed, 11 Aug 2010 14:42:10 +0000 (14:42 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3936 e93f8b46-1217-0410-a6f0-8f06a7374b81

13 files changed:
app/controllers/issue_moves_controller.rb [new file with mode: 0644]
app/controllers/issues_controller.rb
app/helpers/issue_moves_helper.rb [new file with mode: 0644]
app/views/issue_moves/new.rhtml [new file with mode: 0644]
app/views/issues/_action_menu.rhtml
app/views/issues/context_menu.rhtml
app/views/issues/move.rhtml [deleted file]
config/routes.rb
lib/redmine.rb
test/functional/issue_moves_controller_test.rb [new file with mode: 0644]
test/functional/issues_controller_test.rb
test/integration/routing_test.rb
test/unit/helpers/issue_moves_helper_test.rb [new file with mode: 0644]

diff --git a/app/controllers/issue_moves_controller.rb b/app/controllers/issue_moves_controller.rb
new file mode 100644 (file)
index 0000000..1999930
--- /dev/null
@@ -0,0 +1,94 @@
+class IssueMovesController < ApplicationController
+  default_search_scope :issues
+  before_filter :find_issues
+  before_filter :authorize
+  
+  def new
+    prepare_for_issue_move
+    render :layout => false if request.xhr?
+  end
+
+  def create
+    prepare_for_issue_move
+
+    if request.post?
+      new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
+      unsaved_issue_ids = []
+      moved_issues = []
+      @issues.each do |issue|
+        issue.reload
+        issue.init_journal(User.current)
+        call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
+        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
+          moved_issues << r
+        else
+          unsaved_issue_ids << issue.id
+        end
+      end
+      set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
+
+      if params[:follow]
+        if @issues.size == 1 && moved_issues.size == 1
+          redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
+        else
+          redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
+        end
+      else
+        redirect_to :controller => 'issues', :action => 'index', :project_id => @project
+      end
+      return
+    end
+  end
+
+  private
+
+  def prepare_for_issue_move
+    @issues.sort!
+    @copy = params[:copy_options] && params[:copy_options][:copy]
+    @allowed_projects = Issue.allowed_target_projects_on_move
+    @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
+    @target_project ||= @project    
+    @trackers = @target_project.trackers
+    @available_statuses = Workflow.available_statuses(@project)
+  end
+
+  # Filter for bulk operations
+  # TODO: duplicated in IssuesController
+  def find_issues
+    @issues = Issue.find_all_by_id(params[:id] || params[:ids])
+    raise ActiveRecord::RecordNotFound if @issues.empty?
+    projects = @issues.collect(&:project).compact.uniq
+    if projects.size == 1
+      @project = projects.first
+    else
+      # TODO: let users bulk edit/move/destroy issues from different projects
+      render_error 'Can not bulk edit/move/destroy issues from different projects'
+      return false
+    end
+  rescue ActiveRecord::RecordNotFound
+    render_404
+  end
+
+  # TODO: duplicated in IssuesController
+  def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
+    if unsaved_issue_ids.empty?
+      flash[:notice] = l(:notice_successful_update) unless issues.empty?
+    else
+      flash[:error] = l(:notice_failed_to_save_issues,
+                        :count => unsaved_issue_ids.size,
+                        :total => issues.size,
+                        :ids => '#' + unsaved_issue_ids.join(', #'))
+    end
+  end
+
+  def extract_changed_attributes_for_move(params)
+    changed_attributes = {}
+    [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
+      unless params[valid_attribute].blank?
+        changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
+      end
+    end
+    changed_attributes
+  end
+
+end
index 46c61ea0f87b9a05a1e8c41e622ee8d7b4752e5d..50a6f08e700bb32afabe33e560f3c53c05574674 100644 (file)
@@ -249,44 +249,6 @@ class IssuesController < ApplicationController
     @available_statuses = Workflow.available_statuses(@project)
     @custom_fields = @project.all_issue_custom_fields
   end
-
-  def move
-    prepare_for_issue_move
-    render :layout => false if request.xhr?
-  end
-
-  # TODO: more descriptive name? move to separate controller like IssueMovesController?
-  def perform_move
-    prepare_for_issue_move
-
-    if request.post?
-      new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
-      unsaved_issue_ids = []
-      moved_issues = []
-      @issues.each do |issue|
-        issue.reload
-        issue.init_journal(User.current)
-        call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
-        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
-          moved_issues << r
-        else
-          unsaved_issue_ids << issue.id
-        end
-      end
-      set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
-
-      if params[:follow]
-        if @issues.size == 1 && moved_issues.size == 1
-          redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
-        else
-          redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
-        end
-      else
-        redirect_to :controller => 'issues', :action => 'index', :project_id => @project
-      end
-      return
-    end
-  end
   
   def destroy
     @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
@@ -462,16 +424,6 @@ private
     @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
   end
 
-  def prepare_for_issue_move
-    @issues.sort!
-    @copy = params[:copy_options] && params[:copy_options][:copy]
-    @allowed_projects = Issue.allowed_target_projects_on_move
-    @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
-    @target_project ||= @project    
-    @trackers = @target_project.trackers
-    @available_statuses = Workflow.available_statuses(@project)
-  end
-
   def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
     if unsaved_issue_ids.empty?
       flash[:notice] = l(:notice_successful_update) unless issues.empty?
@@ -489,14 +441,4 @@ private
       return false
     end
   end
-
-  def extract_changed_attributes_for_move(params)
-    changed_attributes = {}
-    [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
-      unless params[valid_attribute].blank?
-        changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
-      end
-    end
-    changed_attributes
-  end
 end
diff --git a/app/helpers/issue_moves_helper.rb b/app/helpers/issue_moves_helper.rb
new file mode 100644 (file)
index 0000000..b58b4ce
--- /dev/null
@@ -0,0 +1,2 @@
+module IssueMovesHelper
+end
diff --git a/app/views/issue_moves/new.rhtml b/app/views/issue_moves/new.rhtml
new file mode 100644 (file)
index 0000000..2dc971d
--- /dev/null
@@ -0,0 +1,57 @@
+<h2><%= @copy ? l(:button_copy) : l(:button_move) %></h2>
+
+<ul>
+<% @issues.each do |issue| -%>
+       <li><%= link_to_issue issue %></li>
+<% end -%>
+</ul>
+
+<% form_tag({:action => 'create'}, :id => 'move_form') do %>
+<%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
+
+<div class="box tabular">
+<p><label for="new_project_id"><%=l(:field_project)%>:</label>
+<%= select_tag "new_project_id",
+               project_tree_options_for_select(@allowed_projects, :selected => @target_project),
+               :onchange => remote_function(:url => { :action => 'new' },
+                                            :method => :get,
+                                            :update => 'content',
+                                            :with => "Form.serialize('move_form')") %></p>
+
+<p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
+<%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
+
+<p>
+  <label><%= l(:field_assigned_to) %></label>
+  <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
+                                   content_tag('option', l(:label_nobody), :value => 'none') +
+                                   options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
+</p>
+
+<p>
+  <label><%= l(:field_status) %></label>
+  <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
+</p>
+
+<p>
+  <label><%= l(:field_start_date) %></label>
+  <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
+</p>
+
+<p>
+  <label><%= l(:field_due_date) %></label>
+  <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
+</p>
+
+<%= call_hook(:view_issues_move_bottom, :issues => @issues, :target_project => @target_project, :copy => !!@copy) %>
+</div>
+
+<% if @copy %>
+       <%= hidden_field_tag("copy_options[copy]", "1") %>
+       <%= submit_tag l(:button_copy) %>
+       <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
+<% else %>
+       <%= submit_tag l(:button_move) %>
+       <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
+<% end %>
+<% end %>
index 693b492379057279168ba16ba35e9c62bf90e28a..c5d17511a424f35dac1aa4b5e3bb8fd986b8b3a9 100644 (file)
@@ -4,7 +4,7 @@
 <% replace_watcher ||= 'watcher' %>
 <%= watcher_tag(@issue, User.current, {:id => replace_watcher, :replace => ['watcher','watcher2']}) %>
 <%= link_to_if_authorized l(:button_duplicate), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-duplicate' %>
-<%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'move', :id => @issue, :copy_options => {:copy => 't'} }, :class => 'icon icon-copy' %>
-<%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %>
+<%= link_to_if_authorized l(:button_copy), new_issue_move_path(:id => @issue, :copy_options => {:copy => 't'}), :class => 'icon icon-copy' %>
+<%= link_to_if_authorized l(:button_move), new_issue_move_path(:id => @issue), :class => 'icon icon-move' %>
 <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
 </div>
index d9e92a4f86c8356942fe28f410703d4a118dfa56..dc11b5fdb46ea6930d491ad765150891c450af48 100644 (file)
   <li><%= context_menu_link l(:button_duplicate), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
                :class => 'icon-duplicate', :disabled => !@can[:copy] %></li>
 <% end %>
-  <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id), :copy_options => {:copy => 't'}},
+  <li><%= context_menu_link l(:button_copy), new_issue_move_path(:ids => @issues.collect(&:id), :copy_options => {:copy => 't'}),
                                :class => 'icon-copy', :disabled => !@can[:move]  %></li>
-  <li><%= context_menu_link l(:button_move), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id)},
+  <li><%= context_menu_link l(:button_move), new_issue_move_path(:ids => @issues.collect(&:id)),
                                :class => 'icon-move', :disabled => !@can[:move]  %></li>
   <li><%= context_menu_link l(:button_delete), {:controller => 'issues', :action => 'destroy', :ids => @issues.collect(&:id)},
                             :method => :post, :confirm => l(:text_issues_destroy_confirmation), :class => 'icon-del', :disabled => !@can[:delete] %></li>
diff --git a/app/views/issues/move.rhtml b/app/views/issues/move.rhtml
deleted file mode 100644 (file)
index c216cba..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<h2><%= @copy ? l(:button_copy) : l(:button_move) %></h2>
-
-<ul>
-<% @issues.each do |issue| -%>
-       <li><%= link_to_issue issue %></li>
-<% end -%>
-</ul>
-
-<% form_tag({:action => 'perform_move'}, :id => 'move_form') do %>
-<%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
-
-<div class="box tabular">
-<p><label for="new_project_id"><%=l(:field_project)%>:</label>
-<%= select_tag "new_project_id",
-               project_tree_options_for_select(@allowed_projects, :selected => @target_project),
-               :onchange => remote_function(:url => { :action => 'move' },
-                                            :method => :get,
-                                            :update => 'content',
-                                            :with => "Form.serialize('move_form')") %></p>
-
-<p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
-<%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
-
-<p>
-  <label><%= l(:field_assigned_to) %></label>
-  <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
-                                   content_tag('option', l(:label_nobody), :value => 'none') +
-                                   options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
-</p>
-
-<p>
-  <label><%= l(:field_status) %></label>
-  <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
-</p>
-
-<p>
-  <label><%= l(:field_start_date) %></label>
-  <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
-</p>
-
-<p>
-  <label><%= l(:field_due_date) %></label>
-  <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
-</p>
-
-<%= call_hook(:view_issues_move_bottom, :issues => @issues, :target_project => @target_project, :copy => !!@copy) %>
-</div>
-
-<% if @copy %>
-       <%= hidden_field_tag("copy_options[copy]", "1") %>
-       <%= submit_tag l(:button_copy) %>
-       <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
-<% else %>
-       <%= submit_tag l(:button_move) %>
-       <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
-<% end %>
-<% end %>
index 2e8a145cbcf6022649650c003c06673bf87ede6f..6f71cb65896b69992d15b33914b66d651944ef2d 100644 (file)
@@ -102,7 +102,9 @@ ActionController::Routing::Routes.draw do |map|
       document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
     end
   end
-  
+
+  map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
+
   map.with_options :controller => 'issues' do |issues_routes|
     issues_routes.with_options :conditions => {:method => :get} do |issues_views|
       issues_views.connect 'issues', :action => 'index'
@@ -116,7 +118,6 @@ ActionController::Routing::Routes.draw do |map|
       issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/
       issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/
       issues_views.connect 'issues/:id/edit', :action => 'edit', :id => /\d+/
-      issues_views.connect 'issues/:id/move', :action => 'move', :id => /\d+/
     end
     issues_routes.with_options :conditions => {:method => :post} do |issues_actions|
       issues_actions.connect 'issues', :action => 'index'
@@ -124,7 +125,7 @@ ActionController::Routing::Routes.draw do |map|
       issues_actions.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
       issues_actions.connect 'projects/:project_id/issues/calendar', :controller => 'calendars', :action => 'show'
       issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/
-      issues_actions.connect 'issues/:id/:action', :action => /edit|perform_move|destroy/, :id => /\d+/
+      issues_actions.connect 'issues/:id/:action', :action => /edit|destroy/, :id => /\d+/
       issues_actions.connect 'issues.:format', :action => 'create', :format => /xml/
     end
     issues_routes.with_options :conditions => {:method => :put} do |issues_actions|
@@ -138,7 +139,7 @@ ActionController::Routing::Routes.draw do |map|
     issues_routes.connect 'issues/calendar', :controller => 'calendars', :action => 'show'
     issues_routes.connect 'issues/:action'
   end
-  
+
   map.with_options  :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
     relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
     relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
index 4196a5d7a22c5f73c8ffeb2acb04a8a3c26d3cd6..1d8dbea18ab1eeb2c961cad47d396a64736be593 100644 (file)
@@ -69,7 +69,7 @@ Redmine::AccessControl.map do |map|
     map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]}
     map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
     map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
-    map.permission :move_issues, {:issues => [:move, :perform_move]}, :require => :loggedin
+    map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
     map.permission :delete_issues, {:issues => :destroy}, :require => :member
     # Queries
     map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
diff --git a/test/functional/issue_moves_controller_test.rb b/test/functional/issue_moves_controller_test.rb
new file mode 100644 (file)
index 0000000..083959c
--- /dev/null
@@ -0,0 +1,99 @@
+require 'test_helper'
+
+class IssueMovesControllerTest < ActionController::TestCase
+  fixtures :all
+
+  def setup
+    User.current = nil
+  end
+
+  def test_create_one_issue_to_another_project
+    @request.session[:user_id] = 2
+    post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
+    assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
+    assert_equal 2, Issue.find(1).project_id
+  end
+
+  def test_create_one_issue_to_another_project_should_follow_when_needed
+    @request.session[:user_id] = 2
+    post :create, :id => 1, :new_project_id => 2, :follow => '1'
+    assert_redirected_to '/issues/1'
+  end
+
+  def test_bulk_create_to_another_project
+    @request.session[:user_id] = 2
+    post :create, :ids => [1, 2], :new_project_id => 2
+    assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
+    # Issues moved to project 2
+    assert_equal 2, Issue.find(1).project_id
+    assert_equal 2, Issue.find(2).project_id
+    # No tracker change
+    assert_equal 1, Issue.find(1).tracker_id
+    assert_equal 2, Issue.find(2).tracker_id
+  end
+  def test_bulk_create_to_another_tracker
+    @request.session[:user_id] = 2
+    post :create, :ids => [1, 2], :new_tracker_id => 2
+    assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
+    assert_equal 2, Issue.find(1).tracker_id
+    assert_equal 2, Issue.find(2).tracker_id
+  end
+
+  def test_bulk_copy_to_another_project
+    @request.session[:user_id] = 2
+    assert_difference 'Issue.count', 2 do
+      assert_no_difference 'Project.find(1).issues.count' do
+        post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
+      end
+    end
+    assert_redirected_to 'projects/ecookbook/issues'
+  end
+
+  context "#create via bulk copy" do
+    should "allow not changing the issue's attributes" do
+      @request.session[:user_id] = 2
+      issue_before_move = Issue.find(1)
+      assert_difference 'Issue.count', 1 do
+        assert_no_difference 'Project.find(1).issues.count' do
+          post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
+        end
+      end
+      issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
+      assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
+      assert_equal issue_before_move.status_id, issue_after_move.status_id
+      assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
+    end
+    
+    should "allow changing the issue's attributes" do
+      # Fixes random test failure with Mysql
+      # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
+      Issue.delete_all("project_id=2")
+      
+      @request.session[:user_id] = 2
+      assert_difference 'Issue.count', 2 do
+        assert_no_difference 'Project.find(1).issues.count' do
+          post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
+        end
+      end
+
+      copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
+      assert_equal 2, copied_issues.size
+      copied_issues.each do |issue|
+        assert_equal 2, issue.project_id, "Project is incorrect"
+        assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
+        assert_equal 3, issue.status_id, "Status is incorrect"
+        assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
+        assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
+      end
+    end
+  end
+  
+  def test_copy_to_another_project_should_follow_when_needed
+    @request.session[:user_id] = 2
+    post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
+    issue = Issue.first(:order => 'id DESC')
+    assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
+  end
+
+end
index 92e6fd30a18b18041292123ca071cf93f2ffb169..6b23a651137037a24851c5a27c5855fe699c93e9 100644 (file)
@@ -1037,95 +1037,6 @@ class IssuesControllerTest < ActionController::TestCase
     assert_response :redirect
     assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
   end
-
-  def test_perform_move_one_issue_to_another_project
-    @request.session[:user_id] = 2
-    post :perform_move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
-    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
-    assert_equal 2, Issue.find(1).project_id
-  end
-
-  def test_perform_move_one_issue_to_another_project_should_follow_when_needed
-    @request.session[:user_id] = 2
-    post :perform_move, :id => 1, :new_project_id => 2, :follow => '1'
-    assert_redirected_to '/issues/1'
-  end
-
-  def test_bulk_perform_move_to_another_project
-    @request.session[:user_id] = 2
-    post :perform_move, :ids => [1, 2], :new_project_id => 2
-    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
-    # Issues moved to project 2
-    assert_equal 2, Issue.find(1).project_id
-    assert_equal 2, Issue.find(2).project_id
-    # No tracker change
-    assert_equal 1, Issue.find(1).tracker_id
-    assert_equal 2, Issue.find(2).tracker_id
-  end
-  def test_bulk_perform_move_to_another_tracker
-    @request.session[:user_id] = 2
-    post :perform_move, :ids => [1, 2], :new_tracker_id => 2
-    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
-    assert_equal 2, Issue.find(1).tracker_id
-    assert_equal 2, Issue.find(2).tracker_id
-  end
-
-  def test_bulk_copy_to_another_project
-    @request.session[:user_id] = 2
-    assert_difference 'Issue.count', 2 do
-      assert_no_difference 'Project.find(1).issues.count' do
-        post :perform_move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
-      end
-    end
-    assert_redirected_to 'projects/ecookbook/issues'
-  end
-
-  context "#perform_move via bulk copy" do
-    should "allow not changing the issue's attributes" do
-      @request.session[:user_id] = 2
-      issue_before_move = Issue.find(1)
-      assert_difference 'Issue.count', 1 do
-        assert_no_difference 'Project.find(1).issues.count' do
-          post :perform_move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
-        end
-      end
-      issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
-      assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
-      assert_equal issue_before_move.status_id, issue_after_move.status_id
-      assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
-    end
-    
-    should "allow changing the issue's attributes" do
-      # Fixes random test failure with Mysql
-      # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
-      Issue.delete_all("project_id=2")
-      
-      @request.session[:user_id] = 2
-      assert_difference 'Issue.count', 2 do
-        assert_no_difference 'Project.find(1).issues.count' do
-          post :perform_move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
-        end
-      end
-
-      copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
-      assert_equal 2, copied_issues.size
-      copied_issues.each do |issue|
-        assert_equal 2, issue.project_id, "Project is incorrect"
-        assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
-        assert_equal 3, issue.status_id, "Status is incorrect"
-        assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
-        assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
-      end
-    end
-  end
-  
-  def test_copy_to_another_project_should_follow_when_needed
-    @request.session[:user_id] = 2
-    post :perform_move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
-    issue = Issue.first(:order => 'id DESC')
-    assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
-  end
   
   def test_context_menu_one_issue
     @request.session[:user_id] = 2
@@ -1156,10 +1067,10 @@ class IssuesControllerTest < ActionController::TestCase
                             :attributes => { :href => '/projects/ecookbook/issues/1/copy',
                                              :class => 'icon-duplicate' }
     assert_tag :tag => 'a', :content => 'Copy',
-                            :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1',
+                            :attributes => { :href => '/issues/move/new?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1',
                                              :class => 'icon-copy' }
     assert_tag :tag => 'a', :content => 'Move',
-                            :attributes => { :href => '/issues/move?ids%5B%5D=1',
+                            :attributes => { :href => '/issues/move/new?ids%5B%5D=1',
                                              :class => 'icon-move' }
     assert_tag :tag => 'a', :content => 'Delete',
                             :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
@@ -1190,10 +1101,10 @@ class IssuesControllerTest < ActionController::TestCase
                             :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;issue%5Bassigned_to_id%5D=3',
                                              :class => '' }
     assert_tag :tag => 'a', :content => 'Copy',
-                            :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
+                            :attributes => { :href => '/issues/move/new?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
                                              :class => 'icon-copy' }
     assert_tag :tag => 'a', :content => 'Move',
-                            :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
+                            :attributes => { :href => '/issues/move/new?ids%5B%5D=1&amp;ids%5B%5D=2',
                                              :class => 'icon-move' }
     assert_tag :tag => 'a', :content => 'Delete',
                             :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
index 51f8e71f6e822aa2882b85292a73edc2b51eb17a..af66f7417d3309fe462b401e39930ae1c303b6ab 100644 (file)
@@ -85,8 +85,8 @@ class RoutingTest < ActionController::IntegrationTest
     # Extra actions
     should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64'
 
-    should_route :get, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1'
-    should_route :post, "/issues/1/perform_move", :controller => 'issues', :action => 'perform_move', :id => '1'
+    should_route :get, "/issues/move/new", :controller => 'issue_moves', :action => 'new'
+    should_route :post, "/issues/move", :controller => 'issue_moves', :action => 'create'
     
     should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1'
 
diff --git a/test/unit/helpers/issue_moves_helper_test.rb b/test/unit/helpers/issue_moves_helper_test.rb
new file mode 100644 (file)
index 0000000..b2ffb60
--- /dev/null
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class IssueMovesHelperTest < ActionView::TestCase
+end