Redmine Refactor #97: Move method from IssuesController to JournalsController

Starting a fresh week, it’s time to finish up refactoring IssuesController to remove the last of the extra actions. Using move method I was able to move the #changes method to the JournalsController.

Before

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class IssuesController  [:index, :changes]
  before_filter :find_optional_project, :only => [:index, :changes]
 
  def changes
    retrieve_query
    sort_init 'id', 'desc'
    sort_update(@query.sortable_columns)
 
    if @query.valid?
      @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", 
                                  :limit => 25)
    end
    @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
    render :layout => false, :content_type => 'application/atom+xml'
  rescue ActiveRecord::RecordNotFound
    render_404
  end
 
end
1
2
3
class JournalsController < ApplicationController
  # ...
end

After

1
2
3
4
5
class IssuesController  [:index]
  before_filter :find_optional_project, :only => [:index]
 
  # ...
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class JournalsController  [:index]
  accept_key_auth :index
 
  helper :issues
  helper :queries
  include QueriesHelper
  helper :sort
  include SortHelper
 
  def index
    retrieve_query
    sort_init 'id', 'desc'
    sort_update(@query.sortable_columns)
 
    if @query.valid?
      @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", 
                                  :limit => 25)
    end
    @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
    render :layout => false, :content_type => 'application/atom+xml'
  rescue ActiveRecord::RecordNotFound
    render_404
  end
end

Since the only thing #changes did was to render an Atom feed of journal updates, moving it to the JournalsController makes it fit perfectly into the REST design. It will need a few more formats added eventually, instead of the single hardcoded Atom format. The important thing is that IssuesController now only has one final non RESTful action left, #bulk_edit. I’m still trying to think how I want to handle it, keep it on the IssuesController or move it to a new controller.

Reference commit