The Refactoring This morning I finished the tedious job of moving all of Redmine’s routing tests into the single RoutingTest integration test. I’m only going to show the post refactoring code, the before code looked just like yesterday. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 …
Tag: ruby
Daily Refactor #59: Move Routing Tests
Next, I’m going to work on refactoring Redmine’s controllers in order to make them match the REST pattern and to take advantage of Rail’s built in REST helpers. In order to do this though, I need to refactor how Redmine’s routes are setup. Since the routes.rb file is over 290 lines long, the first thing …
Daily Refactor #58: Move Method to Query Model
The Refactoring Using move method I was able to move a chunk of duplicated code from the QueriesController into the Query model. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # app/controllers/queries_controller.rb def new # ... params[:fields].each do |field| @query.add_filter(field, params[:operators][field], params[:values][field]) end if …
Daily Refactor #57: Extract Class to CustomFieldFormat
I’m going to take a break from my Kanban plugin today to show a refactoring I did to Redmine last night for a client. Redmine has a model called CustomField. This is shared by several other models to let users add custom data to their issues, projects, users, etc. Each of these custom fields has …
Daily Refactor #56: Replace Accumulator with Inject
The Refactoring Today’s refactoring is a simple one that makes use of Ruby’s #inject. #inject is a great method for building accumulators but I don’t see it that often in Rails code that much (including my own). Before 1 2 3 4 5 6 7 8 9 10 11 12 # app/models/kanban_pane/active_pane.rb class KanbanPane::ActivePane < …