Redmine Refactor #99: Extract method from IssuesController#bulk_update

Now that I refactored Redmine and split the #bulk_edit method, I’m ready to start to refactor the #bulk_update method. Starting with the block of code that’s setting attributes, I used extract method to pull it out into a utility method.

Before

1
2
3
4
5
6
7
class IssuesController  params, :issue => issue })
      unless issue.save
        # Keep unsaved issue ids to display them in flash error
        unsaved_issue_ids < 'issues', :action => 'index', :project_id => @project})
  end
 
end

After

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class IssuesController  params, :issue => issue })
      unless issue.save
        # Keep unsaved issue ids to display them in flash error
        unsaved_issue_ids < 'issues', :action => 'index', :project_id => @project})
  end
 
  private
 
  def parse_params_for_bulk_issue_attributes(params)
    attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
    attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
    attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
    attributes
  end
end

By extracting this dense method into a utility method, the #bulk_update action is now a little easier to read.

There is still a pretty complex block of code in the @issues iterator that I will need to refactor soon. The big problem will be making sure that the call_hook method still works for plugins.

Reference commit