Redmine Refactor #86: Extract Method to split IssuesController#move into two actions

Now I want to start refactoring IssuesController#move so it’s two separate actions; one to display the form and one to do the actual move. This will make adding more RESTful urls and APIs to Redmine easier.

To start, I create a second method that wraps the existing #move method so I can change the routing and views.

Before

1
2
3
4
5
class IssuesController < ApplicationController
  def move
    # ...
  end
end
1
2
# app/views/issues/move.rhtml
 'move_form') do %>
1
2
3
4
class RoutingTest  'issues', :action => 'move', :id => '1'
    should_route :post, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1'
  end
end

After

1
2
3
4
5
6
7
8
9
class IssuesController < ApplicationController
  def move
    # ...
  end
 
  def perform_move
    move
  end
end
1
2
# app/views/issues/move.rhtml
 'perform_move'}, :id => 'move_form') do %>
1
2
3
4
class RoutingTest  'issues', :action => 'move', :id => '1'
    should_route :post, "/issues/1/perform_move", :controller => 'issues', :action => 'perform_move', :id => '1'
  end
end

There aren’t a lot of code changes because I’m taking these refactorings very slow. Since Rails’ actions are the actual code that runs when a user requests a page, there is a lot of risk changing them. By building up to the main refactoring slowly, I can make sure each one works before I start on the next.

The reference commit shows some more changes to Redmine that were needed but aren’t relevant to the refactoring:

  • functional test changes
  • permission changes
  • before_filter changes
  • route changes

Reference commit