Redmine Refactor #121: Move Method from NewsController to PreviewsController

Now there is only one non-REST method inside of NewsController left. Today, using move method, I refactored #preview to move it to the dedicated PreviewsController.

Before

1
2
3
4
5
6
7
8
9
10
11
class NewsController  [:new, :create, :index, :preview]
  before_filter :find_project_from_association, :except => [:new, :create, :index, :preview]
  before_filter :find_project, :only => [:new, :create, :preview]
  before_filter :authorize, :except => [:index, :preview]
  before_filter :find_optional_project, :only => :index
 
  def preview
    @text = (params[:news] ? params[:news][:description] : nil)
    render :partial => 'common/preview'
  end
end
1
2
3
class PreviewsController < ApplicationController
  # ...
end

After

1
2
3
4
5
6
7
8
class NewsController  [:new, :create, :index]
  before_filter :find_project_from_association, :except => [:new, :create, :index]
  before_filter :find_project, :only => [:new, :create]
  before_filter :authorize, :except => [:index]
  before_filter :find_optional_project, :only => :index
 
  # No more preview action
end
1
2
3
class PreviewsController  'common/preview'
  end
end

Now that the NewsController actions have been refactored, it’s time to convert the controller into to a full REST resource. This should be easy since I’ve added extra routing tests as I’ve been refactoring.

With refactoring, strong tests are your safety net in case something goes wrong.

Reference commit